TreeTransform.h revision 01e19be69a37bc4ab7746c454cfaa6aec7bb7c6a
157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===// 2577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// 3577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// The LLVM Compiler Infrastructure 4577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// 5577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// This file is distributed under the University of Illinois Open Source 6577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// License. See LICENSE.TXT for details. 757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner//===----------------------------------------------------------------------===// 8577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// 9577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// This file implements a semantic tree transformation that takes a given 10577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// AST and rebuilds it, possibly transforming some nodes in the process. 11577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// 1257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner//===----------------------------------------------------------------------===// 1357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 14577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H 15577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#define LLVM_CLANG_SEMA_TREETRANSFORM_H 16577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 172d88708cbe4e4ec5e04e4acb6bd7f5be68557379John McCall#include "clang/Sema/SemaInternal.h" 18e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#include "clang/Sema/Lookup.h" 198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor#include "clang/Sema/ParsedTemplate.h" 20dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor#include "clang/Sema/SemaDiagnostic.h" 21781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#include "clang/Sema/ScopeInfo.h" 22c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor#include "clang/AST/Decl.h" 237cd088e519d7e6caa4c4c12db52e0e4ae35d25c2John McCall#include "clang/AST/DeclObjC.h" 243e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith#include "clang/AST/DeclTemplate.h" 25657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor#include "clang/AST/Expr.h" 26b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/AST/ExprCXX.h" 27b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/AST/ExprObjC.h" 2843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/Stmt.h" 2943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/StmtCXX.h" 3043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/StmtObjC.h" 3119510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Ownership.h" 3219510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Designator.h" 33b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/Lex/Preprocessor.h" 34a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie#include "llvm/ADT/ArrayRef.h" 35a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "llvm/Support/ErrorHandling.h" 367e44e3fcd75147f229f42e6912898ce62d6b4d08Douglas Gregor#include "TypeLocBuilder.h" 37577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#include <algorithm> 38577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 39577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregornamespace clang { 40781472fe99a120098c631b0cbe33c89f8cef5e70John McCallusing namespace sema; 411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \brief A semantic tree transformation that allows one to transform one 43577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// abstract syntax tree into another. 44577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// A new tree transformation is defined by creating a new subclass \c X of 461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// \c TreeTransform<X> and then overriding certain operations to provide 471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// behavior specific to that transformation. For example, template 48577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// instantiation is implemented as a tree transformation where the 49577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation of TemplateTypeParmType nodes involves substituting the 50577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template arguments for their corresponding template parameters; a similar 51577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation is performed for non-type template parameters and 52577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template template parameters. 53577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 54577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// This tree-transformation template uses static polymorphism to allow 551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// subclasses to customize any of its operations. Thus, a subclass can 56577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// override any of the transformation or rebuild operators by providing an 57577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operation with the same signature as the default implementation. The 58577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// overridding function should not be virtual. 59577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 60577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// Semantic tree transformations are split into two stages, either of which 61577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// can be replaced by a subclass. The "transform" step transforms an AST node 62577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// or the parts of an AST node using the various transformation functions, 63577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// then passes the pieces on to the "rebuild" step, which constructs a new AST 64577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// node of the appropriate kind from the pieces. The default transformation 65577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// routines recursively transform the operands to composite AST nodes (e.g., 66577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// the pointee type of a PointerType node) and, if any of those operand nodes 67577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// were changed by the transformation, invokes the rebuild operation to create 68577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// a new AST node. 69577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Subclasses can customize the transformation at various levels. The 71670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor/// most coarse-grained transformations involve replacing TransformType(), 729151c11836f5fbb36cedfe4d22df7e00e77a1d42Douglas Gregor/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(), 73577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// TransformTemplateName(), or TransformTemplateArgument() with entirely 74577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// new implementations. 75577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 76577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// For more fine-grained transformations, subclasses can replace any of the 77577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \c TransformXXX functions (where XXX is the name of an AST node, e.g., 7843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor/// PointerType, StmtExpr) to alter the transformation. As mentioned previously, 79577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// replacing TransformTemplateTypeParmType() allows template instantiation 801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to substitute template arguments for their corresponding template 81577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// parameters. Additionally, subclasses can override the \c RebuildXXX 82577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// functions to control how AST nodes are rebuilt when their operands change. 83577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// By default, \c TreeTransform will invoke semantic analysis to rebuild 84577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// AST nodes. However, certain other tree transformations (e.g, cloning) may 85577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// be able to use more efficient rebuild steps. 86577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 87577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// There are a handful of other functions that can be overridden, allowing one 881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to avoid traversing nodes that don't need any transformation 89577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their 90577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operands have not changed (\c AlwaysRebuild()), and customize the 91577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// default locations and entity names used for type-checking 92577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c getBaseLocation(), \c getBaseEntity()). 93577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 94577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorclass TreeTransform { 95d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// \brief Private RAII object that helps us forget and then re-remember 96d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// the template argument corresponding to a partially-substituted parameter 97d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// pack. 98d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor class ForgetPartiallySubstitutedPackRAII { 99d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Derived &Self; 100d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor TemplateArgument Old; 101d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 102d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor public: 103d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { 104d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Old = Self.ForgetPartiallySubstitutedPack(); 105d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor } 106d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 107d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ~ForgetPartiallySubstitutedPackRAII() { 108d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Self.RememberPartiallySubstitutedPack(Old); 109d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor } 110d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor }; 111d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 112577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorprotected: 113577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Sema &SemaRef; 1148491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 1151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 116577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Initializes a new tree transformer. 117b99268b3083c882103bd1bd08bdcc9a76a2b4795Douglas Gregor TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } 1181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 119577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Retrieves a reference to the derived class. 120577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Derived &getDerived() { return static_cast<Derived&>(*this); } 121577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 122577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Retrieves a reference to the derived class. 1231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Derived &getDerived() const { 1241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return static_cast<const Derived&>(*this); 125577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 126577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 12760d7b3a319d84d688752be3870615ac0f111fb16John McCall static inline ExprResult Owned(Expr *E) { return E; } 12860d7b3a319d84d688752be3870615ac0f111fb16John McCall static inline StmtResult Owned(Stmt *S) { return S; } 1299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall 130577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Retrieves a reference to the semantic analysis object used for 131577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// this tree transform. 132577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Sema &getSema() const { return SemaRef; } 1331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 134577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Whether the transformation should always rebuild AST nodes, even 135577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// if none of the children have changed. 136577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 137577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this function to specify when the transformation 138577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// should rebuild all AST nodes. 139577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor bool AlwaysRebuild() { return false; } 1401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 141577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Returns the location of the entity being transformed, if that 142577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// information was not available elsewhere in the AST. 143577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 1441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, returns no source-location information. Subclasses can 145577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// provide an alternative implementation that provides better location 146577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// information. 147577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation getBaseLocation() { return SourceLocation(); } 1481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 149577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Returns the name of the entity being transformed, if that 150577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// information was not available elsewhere in the AST. 151577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 152577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, returns an empty name. Subclasses can provide an alternative 153577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// implementation with a more precise name. 154577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor DeclarationName getBaseEntity() { return DeclarationName(); } 155577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 156b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Sets the "base" location and entity when that 157b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// information is known based on another transformation. 158b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 159b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, the source location and entity are ignored. Subclasses can 160b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// override this function to provide a customized implementation. 161b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor void setBase(SourceLocation Loc, DeclarationName Entity) { } 1621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 163b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief RAII object that temporarily sets the base location and entity 164b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// used for reporting diagnostics in types. 165b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor class TemporaryBase { 166b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TreeTransform &Self; 167b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OldLocation; 168b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor DeclarationName OldEntity; 1691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 170b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor public: 171b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TemporaryBase(TreeTransform &Self, SourceLocation Location, 1721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclarationName Entity) : Self(Self) { 173b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor OldLocation = Self.getDerived().getBaseLocation(); 174b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor OldEntity = Self.getDerived().getBaseEntity(); 175ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor 176ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor if (Location.isValid()) 177ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor Self.getDerived().setBase(Location, Entity); 178b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 180b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ~TemporaryBase() { 181b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Self.getDerived().setBase(OldLocation, OldEntity); 182b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 183b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor }; 1841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determine whether the given type \p T has already been 186577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// transformed. 187577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 188577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses can provide an alternative implementation of this routine 1891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// to short-circuit evaluation when it is known that a given type will 190577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// not change. For example, template instantiation need not traverse 191577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// non-dependent types. 192577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor bool AlreadyTransformed(QualType T) { 193577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return T.isNull(); 194577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 195577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 1966eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Determine whether the given call argument should be dropped, e.g., 1976eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// because it is a default argument. 1986eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// 1996eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// Subclasses can provide an alternative implementation of this routine to 2006eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// determine which kinds of call arguments get dropped. By default, 2016eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// CXXDefaultArgument nodes are dropped (prior to transformation). 2026eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor bool DropCallArgument(Expr *E) { 2036eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return E->isDefaultArgument(); 2046eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor } 205c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2068491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \brief Determine whether we should expand a pack expansion with the 2078491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// given set of parameter packs into separate arguments by repeatedly 2088491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// transforming the pattern. 2098491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 210b99268b3083c882103bd1bd08bdcc9a76a2b4795Douglas Gregor /// By default, the transformer never tries to expand pack expansions. 2118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// Subclasses can override this routine to provide different behavior. 2128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param EllipsisLoc The location of the ellipsis that identifies the 2148491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// pack expansion. 2158491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2168491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param PatternRange The source range that covers the entire pattern of 2178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// the pack expansion. 2188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param Unexpanded The set of unexpanded parameter packs within the 2208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// pattern. 2218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param NumUnexpanded The number of unexpanded parameter packs in 2238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \p Unexpanded. 2248491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2258491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param ShouldExpand Will be set to \c true if the transformer should 2268491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// expand the corresponding pack expansions into separate arguments. When 2278491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// set, \c NumExpansions must also be set. 2288491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 229d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// \param RetainExpansion Whether the caller should add an unexpanded 230d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// pack expansion after all of the expanded arguments. This is used 231d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// when extending explicitly-specified template argument packs per 232d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// C++0x [temp.arg.explicit]p9. 233d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// 2348491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param NumExpansions The number of separate arguments that will be in 235cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// the expanded form of the corresponding pack expansion. This is both an 236cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// input and an output parameter, which can be set by the caller if the 237cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// number of expansions is known a priori (e.g., due to a prior substitution) 238cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// and will be set by the callee when the number of expansions is known. 239cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// The callee must set this value when \c ShouldExpand is \c true; it may 240cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// set this value in other cases. 2418491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2428491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \returns true if an error occurred (e.g., because the parameter packs 2438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// are to be instantiated with arguments of different lengths), false 2448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) 2458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// must be set. 2468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor bool TryExpandParameterPacks(SourceLocation EllipsisLoc, 2478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor SourceRange PatternRange, 248a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie llvm::ArrayRef<UnexpandedParameterPack> Unexpanded, 2498491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor bool &ShouldExpand, 250d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool &RetainExpansion, 251cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> &NumExpansions) { 2528491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ShouldExpand = false; 2538491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return false; 2548491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 2558491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 256d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// \brief "Forget" about the partially-substituted pack template argument, 257d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// when performing an instantiation that must preserve the parameter pack 258d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// use. 259d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// 260d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// This routine is meant to be overridden by the template instantiator. 261d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor TemplateArgument ForgetPartiallySubstitutedPack() { 262d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor return TemplateArgument(); 263d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor } 264d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 265d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// \brief "Remember" the partially-substituted pack template argument 266d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// after performing an instantiation that must preserve the parameter pack 267d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// use. 268d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// 269d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// This routine is meant to be overridden by the template instantiator. 270d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } 271d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 27212c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor /// \brief Note to the derived class when a function parameter pack is 27312c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor /// being expanded. 27412c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } 27512c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor 276577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transforms the given type into another type. 277577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 278a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// By default, this routine transforms a type by creating a 279a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall /// TypeSourceInfo for it and delegating to the appropriate 280a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// function. This is expensive, but we don't mind, because 281a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// this method is deprecated anyway; all users should be 282a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall /// switched to storing TypeSourceInfos. 283577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 284577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \returns the transformed type. 28543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType TransformType(QualType T); 2861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 287a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// \brief Transforms the given type-with-location into a new 288a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// type-with-location. 289a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// 290a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// By default, this routine transforms a type by delegating to the 291a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// appropriate TransformXXXType to build a new type. Subclasses 292a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// may override this function (to take over all type 293a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// transformations) or some set of the TransformXXXType functions 294a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// to alter the transformation. 29543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeSourceInfo *TransformType(TypeSourceInfo *DI); 296a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 297a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// \brief Transform the given type-with-location into a new 298a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// type, collecting location information in the given builder 299a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// as necessary. 300577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 30143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); 3021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 303657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor /// \brief Transform the given statement. 304577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 3051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, this routine transforms a statement by delegating to the 30643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// appropriate TransformXXXStmt function to transform a specific kind of 30743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// statement or the TransformExpr() function to transform an expression. 30843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this function to transform statements using some 30943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// other mechanism. 31043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 31143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \returns the transformed statement. 31260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TransformStmt(Stmt *S); 3131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 314657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor /// \brief Transform the given expression. 315657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor /// 316b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, this routine transforms an expression by delegating to the 317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// appropriate TransformXXXExpr function to build a new expression. 318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this function to transform expressions using some 319b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// other mechanism. 320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 321b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \returns the transformed expression. 32260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult TransformExpr(Expr *E); 3231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 324aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Transform the given list of expressions. 325aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 326aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// This routine transforms a list of expressions by invoking 327aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \c TransformExpr() for each subexpression. However, it also provides 328aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// support for variadic templates by expanding any pack expansions (if the 329aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// derived class permits such expansion) along the way. When pack expansions 330aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// are present, the number of outputs may not equal the number of inputs. 331aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 332aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param Inputs The set of expressions to be transformed. 333aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 334aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param NumInputs The number of expressions in \c Inputs. 335aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 336aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param IsCall If \c true, then this transform is being performed on 337aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// function-call arguments, and any arguments that should be dropped, will 338aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// be. 339aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 340aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param Outputs The transformed input expressions will be added to this 341aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// vector. 342aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 343aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param ArgChanged If non-NULL, will be set \c true if any argument changed 344aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// due to transformation. 345aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 346aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \returns true if an error occurred, false otherwise. 347aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, 348686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<Expr *> &Outputs, 349aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool *ArgChanged = 0); 350aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 351577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transform the given declaration, which is referenced from a type 352577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// or expression. 353577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 354dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// By default, acts as the identity function on declarations. Subclasses 355dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// may override this function to provide alternate behavior. 3567c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; } 35743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 35843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Transform the definition of the given declaration. 35943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 3601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, invokes TransformDecl() to transform the declaration. 36143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this function to provide alternate behavior. 362c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Decl *TransformDefinition(SourceLocation Loc, Decl *D) { 363c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getDerived().TransformDecl(Loc, D); 3647c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor } 3651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3666cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// \brief Transform the given declaration, which was the first part of a 3676cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// nested-name-specifier in a member access expression. 3686cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// 369c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// This specific declaration transformation only applies to the first 3706cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// identifier in a nested-name-specifier of a member access expression, e.g., 3716cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// the \c T in \c x->T::member 3726cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// 3736cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// By default, invokes TransformDecl() to transform the declaration. 3746cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// Subclasses may override this function to provide alternate behavior. 375c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { 376c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); 3776cd219879ffce00920189ec1dcea927a42602961Douglas Gregor } 378c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 379c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// \brief Transform the given nested-name-specifier with source-location 380c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// information. 381c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// 382c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// By default, transforms all of the types and declarations within the 383c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// nested-name-specifier. Subclasses may override this function to provide 384c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// alternate behavior. 385c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc TransformNestedNameSpecifierLoc( 386c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc NNS, 387c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType = QualType(), 388c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *FirstQualifierInScope = 0); 389c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 39081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// \brief Transform the given declaration name. 39181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// 39281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// By default, transforms the types of conversion function, constructor, 39381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// and destructor names and then (if needed) rebuilds the declaration name. 39481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// Identifiers and selectors are returned unmodified. Sublcasses may 39581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// override this function to provide alternate behavior. 3962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo 39743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); 3981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 399577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transform the given template name. 4001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 401fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// \param SS The nested-name-specifier that qualifies the template 402fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// name. This nested-name-specifier must already have been transformed. 403fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// 404fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// \param Name The template name to transform. 405fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// 406fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// \param NameLoc The source location of the template name. 407fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// 408fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// \param ObjectType If we're translating a template name within a member 409fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// access expression, this is the type of the object whose member template 410fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// is being referenced. 411fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// 412fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// \param FirstQualifierInScope If the first part of a nested-name-specifier 413fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// also refers to a name within the current (lexical) scope, this is the 414fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// declaration it refers to. 415fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// 416fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// By default, transforms the template name by transforming the declarations 417fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// and nested-name-specifiers that occur within the template name. 418fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// Subclasses may override this function to provide alternate behavior. 419fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName TransformTemplateName(CXXScopeSpec &SS, 420fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName Name, 421fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 422fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor QualType ObjectType = QualType(), 423fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor NamedDecl *FirstQualifierInScope = 0); 424fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 425577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transform the given template argument. 426577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 4271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, this operation transforms the type, expression, or 4281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// declaration stored within the template argument and constructs a 429670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor /// new template argument from the transformed result. Subclasses may 430670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor /// override this function to provide alternate behavior. 431833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// 432833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// Returns true if there was an error. 433833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall bool TransformTemplateArgument(const TemplateArgumentLoc &Input, 434833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &Output); 435833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 436fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// \brief Transform the given set of template arguments. 437fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 438fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// By default, this operation transforms all of the template arguments 439fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// in the input set using \c TransformTemplateArgument(), and appends 440fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// the transformed arguments to the output list. 441fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 4427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// Note that this overload of \c TransformTemplateArguments() is merely 4437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// a convenience function. Subclasses that wish to override this behavior 4447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// should override the iterator-based member template version. 4457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// 446fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// \param Inputs The set of template arguments to be transformed. 447fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 448fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// \param NumInputs The number of template arguments in \p Inputs. 449fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 450fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// \param Outputs The set of transformed template arguments output by this 451fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// routine. 452fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 453fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// Returns true if an error occurred. 454fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, 455fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor unsigned NumInputs, 4567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentListInfo &Outputs) { 4577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); 4587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 4597f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 4607f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// \brief Transform the given set of template arguments. 4617f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// 4627f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// By default, this operation transforms all of the template arguments 4637f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// in the input set using \c TransformTemplateArgument(), and appends 4647f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// the transformed arguments to the output list. 4657f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// 4667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \param First An iterator to the first template argument. 4677ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// 4687ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \param Last An iterator one step past the last template argument. 4697f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// 4707f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// \param Outputs The set of transformed template arguments output by this 4717f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// routine. 4727f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// 4737f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// Returns true if an error occurred. 4747ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor template<typename InputIterator> 4757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor bool TransformTemplateArguments(InputIterator First, 4767ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Last, 4777ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentListInfo &Outputs); 4787f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 479833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. 480833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall void InventTemplateArgumentLoc(const TemplateArgument &Arg, 481833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &ArgLoc); 482833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 483a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall /// \brief Fakes up a TypeSourceInfo for a type. 484a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *InventTypeSourceInfo(QualType T) { 485a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall return SemaRef.Context.getTrivialTypeSourceInfo(T, 486833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall getDerived().getBaseLocation()); 487833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 4881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 489a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT) 490a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT) \ 49143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); 492a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def" 493577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 49428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult 49528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley TransformSEHHandler(Stmt *Handler); 49628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 49743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType 49843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TransformTemplateSpecializationType(TypeLocBuilder &TLB, 49943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateSpecializationTypeLoc TL, 50043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template); 50143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 50243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType 50343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 50443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentTemplateSpecializationTypeLoc TL, 505087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor TemplateName Template, 506087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor CXXScopeSpec &SS); 507a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 508a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor QualType 509a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 51094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor DependentTemplateSpecializationTypeLoc TL, 51194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NestedNameSpecifierLoc QualifierLoc); 51294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 51321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// \brief Transforms the parameters of a function type into the 51421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// given vectors. 51521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// 51621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// The result vectors should be kept in sync; null entries in the 51721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// variables vector are acceptable. 51821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// 51921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// Return true on error. 520a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor bool TransformFunctionTypeParams(SourceLocation Loc, 521a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParmVarDecl **Params, unsigned NumParams, 522a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor const QualType *ParamTypes, 523686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<QualType> &PTypes, 524686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<ParmVarDecl*> *PVars); 52521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 52621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// \brief Transforms a single function-type parameter. Return null 52721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// on error. 528fb44de956f27875def889482b5393475060392afJohn McCall /// 529fb44de956f27875def889482b5393475060392afJohn McCall /// \param indexAdjustment - A number to add to the parameter's 530fb44de956f27875def889482b5393475060392afJohn McCall /// scope index; can be negative 5316a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, 532fb44de956f27875def889482b5393475060392afJohn McCall int indexAdjustment, 5336a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor llvm::Optional<unsigned> NumExpansions); 53421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 53543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); 536833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 53760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); 53860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); 5391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 54043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) \ 54160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Transform##Node(Node *S); 542b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent) \ 54360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Transform##Node(Node *E); 5447381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 5454bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 5461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 547577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new pointer type given its pointee type. 548577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 549577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the pointer type. 550577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 55185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); 552577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 553577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new block pointer type given its pointee type. 554577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 5551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, performs semantic analysis when building the block pointer 556577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// type. Subclasses may override this routine to provide different behavior. 55785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); 558577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 55985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// \brief Build a new reference type given the type it references. 560577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 56185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// By default, performs semantic analysis when building the 56285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// reference type. Subclasses may override this routine to provide 56385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// different behavior. 564577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 56585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// \param LValue whether the type was written with an lvalue sigil 56685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// or an rvalue sigil. 56785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildReferenceType(QualType ReferentType, 56885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall bool LValue, 56985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil); 5701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 571577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new member pointer type given the pointee type and the 572577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// class type it refers into. 573577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 574577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the member pointer 575577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// type. Subclasses may override this routine to provide different behavior. 57685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, 57785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil); 5781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 579577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new array type given the element type, size 580577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// modifier, size of the array (if known), size expression, and index type 581577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// qualifiers. 582577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 583577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 584577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 5851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Also by default, all of the other Rebuild*Array 586577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildArrayType(QualType ElementType, 587577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 588577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt *Size, 589577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Expr *SizeExpr, 590577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 591577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange); 5921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 593577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new constant array type given the element type, size 594577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// modifier, (known) size of the array, and index type qualifiers. 595577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 596577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 597577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 5981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildConstantArrayType(QualType ElementType, 599577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 600577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt &Size, 60185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 60285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange); 603577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 604577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new incomplete array type given the element type, size 605577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// modifier, and index type qualifiers. 606577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 607577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 608577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildIncompleteArrayType(QualType ElementType, 610577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 61185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 61285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange); 613577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 6141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new variable-length array type given the element type, 615577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// size modifier, size expression, and index type qualifiers. 616577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 617577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 618577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildVariableArrayType(QualType ElementType, 620577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 6219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 622577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 623577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange); 624577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 6251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new dependent-sized array type given the element type, 626577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// size modifier, size expression, and index type qualifiers. 627577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 628577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 629577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildDependentSizedArrayType(QualType ElementType, 631577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 6329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 633577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 634577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange); 635577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 636577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new vector type given the element type and 637577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// number of elements. 638577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 639577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the vector type. 640577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 64182287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson QualType RebuildVectorType(QualType ElementType, unsigned NumElements, 642e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::VectorKind VecKind); 6431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 644577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new extended vector type given the element type and 645577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// number of elements. 646577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 647577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the vector type. 648577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 649577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, 650577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc); 6511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new potentially dependently-sized extended vector type 653577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// given the element type and number of elements. 654577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 655577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the vector type. 656577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildDependentSizedExtVectorType(QualType ElementType, 6589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 659577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc); 6601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 661577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new function type. 662577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 663577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the function type. 664577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 665577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildFunctionProtoType(QualType T, 6661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType *ParamTypes, 667577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumParamTypes, 668fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman bool Variadic, unsigned Quals, 669c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind RefQualifier, 670fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman const FunctionType::ExtInfo &Info); 6711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 672a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// \brief Build a new unprototyped function type. 673a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType RebuildFunctionNoProtoType(QualType ResultType); 674a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 675ed97649e9574b9d854fa4d6109c9333ae0993554John McCall /// \brief Rebuild an unresolved typename type, given the decl that 676ed97649e9574b9d854fa4d6109c9333ae0993554John McCall /// the UnresolvedUsingTypenameDecl was transformed to. 677ed97649e9574b9d854fa4d6109c9333ae0993554John McCall QualType RebuildUnresolvedUsingType(Decl *D); 678ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 679577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new typedef type. 680162e1c1b487352434552147967c3dd296ebee2f7Richard Smith QualType RebuildTypedefType(TypedefNameDecl *Typedef) { 681577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeDeclType(Typedef); 682577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 683577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 684577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new class/struct/union type. 685577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildRecordType(RecordDecl *Record) { 686577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeDeclType(Record); 687577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 688577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 689577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new Enum type. 690577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildEnumType(EnumDecl *Enum) { 691577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeDeclType(Enum); 692577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 6937da2431c23ef1ee8acb114e39692246e1801afc2John McCall 6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new typeof(expr) type. 695577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 696577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the typeof type. 697577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6982a984cad5ac3fdceeff2bd99daa7b90979313475John McCall QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); 699577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 7001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new typeof(type) type. 701577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 702577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, builds a new TypeOfType with the given underlying type. 703577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildTypeOfType(QualType Underlying); 704577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 705ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt /// \brief Build a new unary transform type. 706ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType RebuildUnaryTransformType(QualType BaseType, 707ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType::UTTKind UKind, 708ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt SourceLocation Loc); 709ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 7101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new C++0x decltype type. 711577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 712577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the decltype type. 713577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 7142a984cad5ac3fdceeff2bd99daa7b90979313475John McCall QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); 7151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71634b41d939a1328f484511c6002ba2456db879a29Richard Smith /// \brief Build a new C++0x auto type. 71734b41d939a1328f484511c6002ba2456db879a29Richard Smith /// 71834b41d939a1328f484511c6002ba2456db879a29Richard Smith /// By default, builds a new AutoType with the given deduced type. 71934b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType RebuildAutoType(QualType Deduced) { 72034b41d939a1328f484511c6002ba2456db879a29Richard Smith return SemaRef.Context.getAutoType(Deduced); 72134b41d939a1328f484511c6002ba2456db879a29Richard Smith } 72234b41d939a1328f484511c6002ba2456db879a29Richard Smith 723577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new template specialization type. 724577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 725577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the template 726577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// specialization type. Subclasses may override this routine to provide 727577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// different behavior. 728577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildTemplateSpecializationType(TemplateName Template, 729833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation TemplateLoc, 73067714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor TemplateArgumentListInfo &Args); 7311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 732075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// \brief Build a new parenthesized type. 733075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// 734075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// By default, builds a new ParenType type from the inner type. 735075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// Subclasses may override this routine to provide different behavior. 736075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType RebuildParenType(QualType InnerType) { 737075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return SemaRef.Context.getParenType(InnerType); 738075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 739075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 740577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new qualified name type. 741577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 742465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// By default, builds a new ElaboratedType type from the keyword, 743465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// the nested-name-specifier and the named type. 744465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// Subclasses may override this routine to provide different behavior. 74521e413fe6305a198564d436ac515497716c47844John McCall QualType RebuildElaboratedType(SourceLocation KeywordLoc, 74621e413fe6305a198564d436ac515497716c47844John McCall ElaboratedTypeKeyword Keyword, 7479e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 7489e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualType Named) { 7499e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor return SemaRef.Context.getElaboratedType(Keyword, 7509e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 7519e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor Named); 7521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 753577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 754577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new typename type that refers to a template-id. 755577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 756e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// By default, builds a new DependentNameType type from the 757e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// nested-name-specifier and the given type. Subclasses may override 758e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// this routine to provide different behavior. 75933500955d731c73717af52088b7fc0e7a85681e7John McCall QualType RebuildDependentTemplateSpecializationType( 76094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor ElaboratedTypeKeyword Keyword, 76194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 76294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor const IdentifierInfo *Name, 76394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor SourceLocation NameLoc, 76467714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor TemplateArgumentListInfo &Args) { 76594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Rebuild the template name. 76694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // TODO: avoid TemplateName abstraction 767fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor CXXScopeSpec SS; 768fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SS.Adopt(QualifierLoc); 76994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor TemplateName InstName 770fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0); 77194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 77294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (InstName.isNull()) 77394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return QualType(); 77494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 77594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // If it's still dependent, make a dependent specialization. 77694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (InstName.getAsDependentTemplateName()) 77794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, 77894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 77994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor Name, 78094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor Args); 78194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 78294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Otherwise, make an elaborated type wrapping a non-dependent 78394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // specialization. 78494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualType T = 78594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); 78694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (T.isNull()) return QualType(); 78794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 78894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0) 78994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return T; 79094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 79194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return SemaRef.Context.getElaboratedType(Keyword, 79294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 79394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor T); 79494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor } 79594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 796577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new typename type that refers to an identifier. 797577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 798577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the typename type 799e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// (or elaborated type). Subclasses may override this routine to provide 800577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// different behavior. 801e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, 802e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SourceLocation KeywordLoc, 8032494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 8042494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor const IdentifierInfo *Id, 805e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SourceLocation IdLoc) { 8064033642464e8ba0982f88f34cffad808d247b393Douglas Gregor CXXScopeSpec SS; 8072494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor SS.Adopt(QualifierLoc); 808e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara 8092494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { 8104033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // If the name is still dependent, just build a new dependent name type. 8114033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (!SemaRef.computeDeclContext(SS)) 8122494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor return SemaRef.Context.getDependentNameType(Keyword, 8132494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 8142494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor Id); 8154033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 8164033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 817465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara if (Keyword == ETK_None || Keyword == ETK_Typename) 8182494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, 819e29425bd22fbb9200bbec7b743197b9c6dad3e40Douglas Gregor *Id, IdLoc); 820465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 821465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); 822465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 823e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara // We had a dependent elaborated-type-specifier that has been transformed 8244033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // into a non-dependent elaborated-type-specifier. Find the tag we're 8254033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // referring to. 826e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); 8274033642464e8ba0982f88f34cffad808d247b393Douglas Gregor DeclContext *DC = SemaRef.computeDeclContext(SS, false); 8284033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (!DC) 8294033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 8304033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 8315613876991c80a684595fe8de1f039296a0657ffJohn McCall if (SemaRef.RequireCompleteDeclContext(SS, DC)) 8325613876991c80a684595fe8de1f039296a0657ffJohn McCall return QualType(); 8335613876991c80a684595fe8de1f039296a0657ffJohn McCall 8344033642464e8ba0982f88f34cffad808d247b393Douglas Gregor TagDecl *Tag = 0; 8354033642464e8ba0982f88f34cffad808d247b393Douglas Gregor SemaRef.LookupQualifiedName(Result, DC); 8364033642464e8ba0982f88f34cffad808d247b393Douglas Gregor switch (Result.getResultKind()) { 8374033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::NotFound: 8384033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::NotFoundInCurrentInstantiation: 8394033642464e8ba0982f88f34cffad808d247b393Douglas Gregor break; 840c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8414033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::Found: 8424033642464e8ba0982f88f34cffad808d247b393Douglas Gregor Tag = Result.getAsSingle<TagDecl>(); 8434033642464e8ba0982f88f34cffad808d247b393Douglas Gregor break; 844c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8454033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::FoundOverloaded: 8464033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::FoundUnresolvedValue: 8474033642464e8ba0982f88f34cffad808d247b393Douglas Gregor llvm_unreachable("Tag lookup cannot find non-tags"); 8484033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 849c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8504033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::Ambiguous: 8514033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // Let the LookupResult structure handle ambiguities. 8524033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 8534033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 8544033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 8554033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (!Tag) { 856446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky // Check where the name exists but isn't a tag type and use that to emit 857446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky // better diagnostics. 858446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); 859446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.LookupQualifiedName(Result, DC); 860446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky switch (Result.getResultKind()) { 861446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky case LookupResult::Found: 862446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky case LookupResult::FoundOverloaded: 863446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky case LookupResult::FoundUnresolvedValue: { 8643e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NamedDecl *SomeDecl = Result.getRepresentativeDecl(); 865446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky unsigned Kind = 0; 866446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky if (isa<TypedefDecl>(SomeDecl)) Kind = 1; 867162e1c1b487352434552147967c3dd296ebee2f7Richard Smith else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2; 868162e1c1b487352434552147967c3dd296ebee2f7Richard Smith else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3; 869446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; 870446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); 871446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky break; 8723e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 873446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky default: 874446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky // FIXME: Would be nice to highlight just the source range. 875446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) 876446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky << Kind << Id << DC; 877446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky break; 878446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky } 8794033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 8804033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 881465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 882bbf34c024398e7bae825686dcff4c3b901ec9f89Richard Trieu if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, 883bbf34c024398e7bae825686dcff4c3b901ec9f89Richard Trieu IdLoc, *Id)) { 884e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; 8854033642464e8ba0982f88f34cffad808d247b393Douglas Gregor SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); 8864033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 8874033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 8884033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 8894033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // Build the elaborated-type-specifier type. 8904033642464e8ba0982f88f34cffad808d247b393Douglas Gregor QualType T = SemaRef.Context.getTypeDeclType(Tag); 8912494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor return SemaRef.Context.getElaboratedType(Keyword, 8922494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 8932494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor T); 894dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor } 8951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8962fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// \brief Build a new pack expansion type. 8972fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// 8982fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// By default, builds a new PackExpansionType type from the given pattern. 8992fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// Subclasses may override this routine to provide different behavior. 9002fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor QualType RebuildPackExpansionType(QualType Pattern, 9012fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor SourceRange PatternRange, 902cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor SourceLocation EllipsisLoc, 903cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 904cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, 905cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions); 9062fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor } 9072fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor 908b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman /// \brief Build a new atomic type given its value type. 909b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman /// 910b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman /// By default, performs semantic analysis when building the atomic type. 911b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman /// Subclasses may override this routine to provide different behavior. 912b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); 913b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 914d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// \brief Build a new template name given a nested name specifier, a flag 915d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// indicating whether the "template" keyword was provided, and the template 916d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// that the template name refers to. 917d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// 918d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// By default, builds the new template name directly. Subclasses may override 919d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// this routine to provide different behavior. 920fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName RebuildTemplateName(CXXScopeSpec &SS, 921d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor bool TemplateKW, 922d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TemplateDecl *Template); 923d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor 924d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// \brief Build a new template name given a nested name specifier and the 925d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// name that is referred to as a template. 926d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// 927d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// By default, performs semantic analysis to determine whether the name can 928d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// be resolved to a specific template, then builds the appropriate kind of 929d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// template name. Subclasses may override this routine to provide different 930d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// behavior. 931fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName RebuildTemplateName(CXXScopeSpec &SS, 932fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor const IdentifierInfo &Name, 933fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 93443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 93543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope); 9361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 937ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// \brief Build a new template name given a nested name specifier and the 938ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// overloaded operator name that is referred to as a template. 939ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// 940ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// By default, performs semantic analysis to determine whether the name can 941ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// be resolved to a specific template, then builds the appropriate kind of 942ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// template name. Subclasses may override this routine to provide different 943ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// behavior. 944fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName RebuildTemplateName(CXXScopeSpec &SS, 945ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor OverloadedOperatorKind Operator, 946fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 947ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor QualType ObjectType); 9481aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 9491aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// \brief Build a new template name given a template template parameter pack 9501aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// and the 9511aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// 9521aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// By default, performs semantic analysis to determine whether the name can 9531aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// be resolved to a specific template, then builds the appropriate kind of 9541aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// template name. Subclasses may override this routine to provide different 9551aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// behavior. 9561aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, 9571aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor const TemplateArgument &ArgPack) { 9581aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); 9591aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor } 9601aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 96143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new compound statement. 96243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 96343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 96443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 96560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, 96643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor MultiStmtArg Statements, 96743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation RBraceLoc, 96843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool IsStmtExpr) { 9699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, 97043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor IsStmtExpr); 97143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 97243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 97343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new case statement. 97443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 97543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 97643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 97760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCaseStmt(SourceLocation CaseLoc, 9789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *LHS, 97943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation EllipsisLoc, 9809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *RHS, 98143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation ColonLoc) { 9829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, 98343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor ColonLoc); 98443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 9851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 98643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Attach the body to a new case statement. 98743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 98843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 98943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 99060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { 9919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall getSema().ActOnCaseStmtBody(S, Body); 9929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return S; 99343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 9941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 99543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new default 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 RebuildDefaultStmt(SourceLocation DefaultLoc, 100043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation ColonLoc, 10019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *SubStmt) { 10029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, 100343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /*CurScope=*/0); 100443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 100643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new label statement. 100743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 100843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 100943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 101057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, 101157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner SourceLocation ColonLoc, Stmt *SubStmt) { 101257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); 101343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 101543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new "if" 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. 101960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, 102057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner VarDecl *CondVar, Stmt *Then, 102157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner SourceLocation ElseLoc, Stmt *Else) { 102244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); 102343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 102543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Start building a new switch statement. 102643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 102743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 102843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 102960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, 103057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Expr *Cond, VarDecl *CondVar) { 10319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, 1032d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall CondVar); 103343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 103543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Attach the body to the switch statement. 103643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 103743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 103843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 103960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, 104057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Stmt *Switch, Stmt *Body) { 10419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); 104243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 104343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 104443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new while 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. 104857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, 104957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner VarDecl *CondVar, Stmt *Body) { 10509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); 105143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 105343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new do-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. 105760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, 1058ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation WhileLoc, SourceLocation LParenLoc, 1059ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner Expr *Cond, SourceLocation RParenLoc) { 10609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, 10619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond, RParenLoc); 106243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 106343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 106443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new for statement. 106543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 106643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 106743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1068ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, 1069ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner Stmt *Init, Sema::FullExprArg Cond, 1070ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner VarDecl *CondVar, Sema::FullExprArg Inc, 1071ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation RParenLoc, Stmt *Body) { 10729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, 1073ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner CondVar, Inc, RParenLoc, Body); 107443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 107643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new goto statement. 107743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 107843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 107943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1080ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, 1081ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *Label) { 108257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); 108343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 108443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 108543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new indirect 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. 108960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, 1090ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation StarLoc, 1091ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner Expr *Target) { 10929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); 109343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 109543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new return statement. 109643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 109743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 109843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1099ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { 11009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnReturnStmt(ReturnLoc, Result); 110143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 11021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 110343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new declaration statement. 110443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 110543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 110643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 110760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, 11081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation StartLoc, 110943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation EndLoc) { 1110406c38e8c1f105acfd438f94dfbc17af817aa4a5Richard Smith Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls); 1111406c38e8c1f105acfd438f94dfbc17af817aa4a5Richard Smith return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); 111243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 11131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1114703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// \brief Build a new inline asm statement. 1115703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// 1116703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// By default, performs semantic analysis to build the new statement. 1117703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// Subclasses may override this routine to provide different behavior. 111860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildAsmStmt(SourceLocation AsmLoc, 1119703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool IsSimple, 1120703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool IsVolatile, 1121703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson unsigned NumOutputs, 1122703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson unsigned NumInputs, 1123ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo **Names, 1124703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson MultiExprArg Constraints, 1125703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson MultiExprArg Exprs, 11269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *AsmString, 1127703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson MultiExprArg Clobbers, 1128703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson SourceLocation RParenLoc, 1129703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool MSAsm) { 1130c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, 1131703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson NumInputs, Names, move(Constraints), 11329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs, AsmString, Clobbers, 1133703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson RParenLoc, MSAsm); 1134703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 11354dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 11364dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// \brief Build a new Objective-C @try statement. 11374dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// 11384dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// By default, performs semantic analysis to build the new statement. 11394dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 114060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, 11419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *TryBody, 11428f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor MultiStmtArg CatchStmts, 11439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Finally) { 11449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts), 11459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Finally); 11464dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 11474dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 1148be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// \brief Rebuild an Objective-C exception declaration. 1149be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// 1150be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// By default, performs semantic analysis to build the new declaration. 1151be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1152be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, 1153be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TypeSourceInfo *TInfo, QualType T) { 1154ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara return getSema().BuildObjCExceptionDecl(TInfo, T, 1155ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getInnerLocStart(), 1156ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getLocation(), 1157ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getIdentifier()); 1158be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 1159c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1160be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// \brief Build a new Objective-C @catch statement. 1161be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// 1162be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// By default, performs semantic analysis to build the new statement. 1163be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// Subclasses may override this routine to provide different behavior. 116460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, 1165be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor SourceLocation RParenLoc, 1166be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *Var, 11679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Body) { 1168be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, 11699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Var, Body); 1170be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 1171c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 11724dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// \brief Build a new Objective-C @finally statement. 11734dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// 11744dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// By default, performs semantic analysis to build the new statement. 11754dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 117660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, 11779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Body) { 11789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); 11794dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 1180c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 11818fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// \brief Build a new Objective-C @throw statement. 1182d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor /// 1183d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor /// By default, performs semantic analysis to build the new statement. 1184d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor /// Subclasses may override this routine to provide different behavior. 118560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, 11869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand) { 11879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); 1188d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor } 1189c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 119007524039dce5c820f111a1b3f772b4261f004b4aJohn McCall /// \brief Rebuild the operand to an Objective-C @synchronized statement. 119107524039dce5c820f111a1b3f772b4261f004b4aJohn McCall /// 119207524039dce5c820f111a1b3f772b4261f004b4aJohn McCall /// By default, performs semantic analysis to build the new statement. 119307524039dce5c820f111a1b3f772b4261f004b4aJohn McCall /// Subclasses may override this routine to provide different behavior. 119407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, 119507524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Expr *object) { 119607524039dce5c820f111a1b3f772b4261f004b4aJohn McCall return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); 119707524039dce5c820f111a1b3f772b4261f004b4aJohn McCall } 119807524039dce5c820f111a1b3f772b4261f004b4aJohn McCall 11998fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// \brief Build a new Objective-C @synchronized statement. 12008fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// 12018fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// By default, performs semantic analysis to build the new statement. 12028fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// Subclasses may override this routine to provide different behavior. 120360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, 120407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Expr *Object, Stmt *Body) { 120507524039dce5c820f111a1b3f772b4261f004b4aJohn McCall return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); 12068fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor } 1207c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor 1208f85e193739c953358c865005855253af4f68a497John McCall /// \brief Build a new Objective-C @autoreleasepool statement. 1209f85e193739c953358c865005855253af4f68a497John McCall /// 1210f85e193739c953358c865005855253af4f68a497John McCall /// By default, performs semantic analysis to build the new statement. 1211f85e193739c953358c865005855253af4f68a497John McCall /// Subclasses may override this routine to provide different behavior. 1212f85e193739c953358c865005855253af4f68a497John McCall StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, 1213f85e193739c953358c865005855253af4f68a497John McCall Stmt *Body) { 1214f85e193739c953358c865005855253af4f68a497John McCall return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); 1215f85e193739c953358c865005855253af4f68a497John McCall } 1216990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall 1217990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall /// \brief Build the collection operand to a new Objective-C fast 1218990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall /// enumeration statement. 1219990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall /// 1220990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall /// By default, performs semantic analysis to build the new statement. 1221990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall /// Subclasses may override this routine to provide different behavior. 1222990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc, 1223990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall Expr *collection) { 1224990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall return getSema().ActOnObjCForCollectionOperand(forLoc, collection); 1225990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall } 1226f85e193739c953358c865005855253af4f68a497John McCall 1227c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// \brief Build a new Objective-C fast enumeration statement. 1228c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// 1229c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// By default, performs semantic analysis to build the new statement. 1230c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// Subclasses may override this routine to provide different behavior. 123160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, 1232f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall SourceLocation LParenLoc, 1233f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *Element, 1234f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Expr *Collection, 1235f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall SourceLocation RParenLoc, 1236f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *Body) { 1237c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, 12389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Element, 12399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Collection, 1240c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor RParenLoc, 12419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body); 1242c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor } 1243c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 124443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new C++ exception declaration. 124543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 124643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new decaration. 124743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1248ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, 1249a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Declarator, 1250ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation StartLoc, 1251ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation IdLoc, 1252ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara IdentifierInfo *Id) { 1253efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator, 1254efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor StartLoc, IdLoc, Id); 1255efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor if (Var) 1256efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor getSema().CurContext->addDecl(Var); 1257efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor return Var; 125843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 125943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 126043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new C++ catch statement. 126143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 126243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 126343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 126460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, 1265f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall VarDecl *ExceptionDecl, 1266f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *Handler) { 12679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, 12689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Handler)); 126943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 12701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 127143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new C++ try statement. 127243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 127343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 127443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 127560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, 1276f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *TryBlock, 1277f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiStmtArg Handlers) { 12789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers)); 127943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 12801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1281ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// \brief Build a new C++0x range-based for statement. 1282ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// 1283ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// By default, performs semantic analysis to build the new statement. 1284ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// Subclasses may override this routine to provide different behavior. 1285ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, 1286ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith SourceLocation ColonLoc, 1287ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Stmt *Range, Stmt *BeginEnd, 1288ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Expr *Cond, Expr *Inc, 1289ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Stmt *LoopVar, 1290ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith SourceLocation RParenLoc) { 1291ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd, 1292ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Cond, Inc, LoopVar, RParenLoc); 1293ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 1294ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 1295ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor /// \brief Build a new C++0x range-based for statement. 1296ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor /// 1297ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor /// By default, performs semantic analysis to build the new statement. 1298ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1299ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, 1300ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor bool IsIfExists, 1301ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 1302ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor DeclarationNameInfo NameInfo, 1303ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor Stmt *Nested) { 1304ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, 1305ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor QualifierLoc, NameInfo, Nested); 1306ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor } 1307ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 1308ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// \brief Attach body to a C++0x range-based for statement. 1309ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// 1310ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// By default, performs semantic analysis to finish the new statement. 1311ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// Subclasses may override this routine to provide different behavior. 1312ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { 1313ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return getSema().FinishCXXForRangeStmt(ForRange, Body); 1314ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 1315ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 131628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult RebuildSEHTryStmt(bool IsCXXTry, 131728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation TryLoc, 131828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *TryBlock, 131928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Handler) { 132028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler); 132128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 132228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 132328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult RebuildSEHExceptStmt(SourceLocation Loc, 132428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Expr *FilterExpr, 132528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block) { 132628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block); 132728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 132828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 132928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, 133028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block) { 133128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getSema().ActOnSEHFinallyBlock(Loc,Block); 133228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 133328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 1334b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression that references a declaration. 1335b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1336b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1337b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 133860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, 1339f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall LookupResult &R, 1340f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall bool RequiresADL) { 1341f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); 1342f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 1343f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 1344f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 1345f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// \brief Build a new expression that references a declaration. 1346f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// 1347f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// By default, performs semantic analysis to build the new expression. 1348f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// Subclasses may override this routine to provide different behavior. 134940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, 1350f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall ValueDecl *VD, 1351f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall const DeclarationNameInfo &NameInfo, 1352f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TemplateArgumentListInfo *TemplateArgs) { 1353a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor CXXScopeSpec SS; 135440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor SS.Adopt(QualifierLoc); 1355dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 1356dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // FIXME: loses template args. 13572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 13582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); 1359b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 13601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1361b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression in parentheses. 13621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1363b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1364b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 136560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, 1366b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParen) { 13679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnParenExpr(LParen, RParen, SubExpr); 1368b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1369b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1370a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief Build a new pseudo-destructor expression. 13711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1372a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1373a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// Subclasses may override this routine to provide different behavior. 137460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, 1375f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SourceLocation OperatorLoc, 1376f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor bool isArrow, 1377f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor CXXScopeSpec &SS, 1378f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor TypeSourceInfo *ScopeType, 1379f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SourceLocation CCLoc, 1380f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SourceLocation TildeLoc, 1381a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed); 13821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1383b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new unary operator expression. 13841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1385b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1386b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 138760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildUnaryOperator(SourceLocation OpLoc, 13882de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc, 13899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr) { 13909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); 1391b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 13921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Build a new builtin offsetof expression. 13948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// 13958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// By default, performs semantic analysis to build the new expression. 13968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// Subclasses may override this routine to provide different behavior. 139760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, 13988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *Type, 1399f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::OffsetOfComponent *Components, 14008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComponents, 14018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) { 14028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, 14038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor NumComponents, RParenLoc); 14048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1405c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1406f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne /// \brief Build a new sizeof, alignof or vec_step expression with a 1407f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne /// type argument. 14081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1409b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1410b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1411f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, 1412f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation OpLoc, 1413f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTrait ExprKind, 1414f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceRange R) { 1415f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); 1416b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1417b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1418f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne /// \brief Build a new sizeof, alignof or vec step expression with an 1419f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne /// expression argument. 14201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1421b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1422b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1423f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, 1424f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTrait ExprKind, 1425f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceRange R) { 142660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 1427e72c55b9a11be9f00fa3f66f7ad6b73b2814e963Chandler Carruth = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); 1428b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 1429f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 14301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1431b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return move(Result); 1432b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 14331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1434b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new array subscript expression. 14351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1436b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1437b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 143860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildArraySubscriptExpr(Expr *LHS, 1439b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LBracketLoc, 14409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *RHS, 1441b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RBracketLoc) { 14429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, 14439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LBracketLoc, RHS, 1444b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RBracketLoc); 1445b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1446b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1447b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new call expression. 14481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1449b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1450b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 145160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, 1452b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg Args, 1453e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne SourceLocation RParenLoc, 1454e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne Expr *ExecConfig = 0) { 14559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, 1456e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne move(Args), RParenLoc, ExecConfig); 1457b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1458b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1459b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new member access expression. 14601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1461b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1462b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 146360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, 1464f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall bool isArrow, 146540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 1466f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const DeclarationNameInfo &MemberNameInfo, 1467f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ValueDecl *Member, 1468f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall NamedDecl *FoundDecl, 1469d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *ExplicitTemplateArgs, 1470f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall NamedDecl *FirstQualifierInScope) { 14719138b4e96429cbaae00c52c15c960f72b6645088Richard Smith ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, 14729138b4e96429cbaae00c52c15c960f72b6645088Richard Smith isArrow); 1473d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson if (!Member->getDeclName()) { 1474f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // We have a reference to an unnamed field. This is always the 1475f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // base of an anonymous struct/union member access, i.e. the 1476f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // field is always of record type. 147740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); 1478f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall assert(Member->getType()->isRecordType() && 1479f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall "unnamed member not of record type?"); 14801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14819138b4e96429cbaae00c52c15c960f72b6645088Richard Smith BaseResult = 14829138b4e96429cbaae00c52c15c960f72b6645088Richard Smith getSema().PerformObjectMemberConversion(BaseResult.take(), 1483429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley QualifierLoc.getNestedNameSpecifier(), 1484429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley FoundDecl, Member); 1485429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (BaseResult.isInvalid()) 1486f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 1487429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley Base = BaseResult.take(); 1488f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); 14891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump MemberExpr *ME = 14909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall new (getSema().Context) MemberExpr(Base, isArrow, 14912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Member, MemberNameInfo, 1492f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall cast<FieldDecl>(Member)->getType(), 1493f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall VK, OK_Ordinary); 1494d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson return getSema().Owned(ME); 1495d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson } 14961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 149783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor CXXScopeSpec SS; 149840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor SS.Adopt(QualifierLoc); 149983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 1500429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley Base = BaseResult.take(); 15019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall QualType BaseType = Base->getType(); 1502aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 15036bb8017bb9e828d118e15e59d71c66bba323c364John McCall // FIXME: this involves duplicating earlier analysis in a lot of 15046bb8017bb9e828d118e15e59d71c66bba323c364John McCall // cases; we should avoid this when possible. 15052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); 15066bb8017bb9e828d118e15e59d71c66bba323c364John McCall R.addDecl(FoundDecl); 1507c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R.resolveKind(); 1508c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 15099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, 1510129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SS, FirstQualifierInScope, 1511c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R, ExplicitTemplateArgs); 1512b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1514b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new binary operator expression. 15151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1516b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1517b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 151860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildBinaryOperator(SourceLocation OpLoc, 15192de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc, 15209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *LHS, Expr *RHS) { 15219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); 1522b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1523b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1524b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new conditional operator expression. 15251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1526b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1527b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 152860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildConditionalOperator(Expr *Cond, 152956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation QuestionLoc, 153056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *LHS, 153156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation ColonLoc, 153256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *RHS) { 15339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, 15349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS, RHS); 1535b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1536b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1537b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C-style cast expression. 15381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1539b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1540b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 154160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, 15429d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1543b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc, 15449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr) { 1545b042fdfc9460e0018276412257e3c3226f9ea96eJohn McCall return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, 15469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr); 1547b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1549b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new compound literal expression. 15501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1551b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1552b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 155360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, 155442f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *TInfo, 1555b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc, 15569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Init) { 155742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, 15589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init); 1559b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1561b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new extended vector element access expression. 15621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1563b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1564b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 156560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildExtVectorElementExpr(Expr *Base, 1566b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 1567b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation AccessorLoc, 1568b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor IdentifierInfo &Accessor) { 1569aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 1570129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall CXXScopeSpec SS; 15712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); 15729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, Base->getType(), 1573129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall OpLoc, /*IsArrow*/ false, 1574129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SS, /*FirstQualifierInScope*/ 0, 15752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 1576129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /* TemplateArgs */ 0); 1577b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1579b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new initializer list expression. 15801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1581b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1582b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 158360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildInitList(SourceLocation LBraceLoc, 1584c8fc90a854b4ccba21c85884676a80334159dd94John McCall MultiExprArg Inits, 1585c8fc90a854b4ccba21c85884676a80334159dd94John McCall SourceLocation RBraceLoc, 1586c8fc90a854b4ccba21c85884676a80334159dd94John McCall QualType ResultTy) { 158760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 1588e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); 1589e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor if (Result.isInvalid() || ResultTy->isDependentType()) 1590e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor return move(Result); 1591c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1592e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor // Patch in the result type we were given, which may have been computed 1593e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor // when the initial InitListExpr was built. 1594e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); 1595e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor ILE->setType(ResultTy); 1596e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor return move(Result); 1597b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1599b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new designated initializer expression. 16001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1601b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1602b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 160360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildDesignatedInitExpr(Designation &Desig, 1604b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg ArrayExprs, 1605b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation EqualOrColonLoc, 1606b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool GNUSyntax, 16079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Init) { 160860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 1609b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, 16109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init); 1611b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 1612f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 16131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1614b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.release(); 1615b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return move(Result); 1616b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1618b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new value-initialized expression. 16191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1620b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds the implicit value initialization without performing 1621b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// any semantic analysis. Subclasses may override this routine to provide 1622b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// different behavior. 162360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildImplicitValueInitExpr(QualType T) { 1624b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); 1625b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1627b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new \c va_arg expression. 16281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1629b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1630b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 163160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, 16329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, TypeSourceInfo *TInfo, 16332cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara SourceLocation RParenLoc) { 16342cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara return getSema().BuildVAArgExpr(BuiltinLoc, 16359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, TInfo, 16362cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara RParenLoc); 1637b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1638b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1639b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression list in parentheses. 16401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1641b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1642b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 164360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildParenListExpr(SourceLocation LParenLoc, 1644b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg SubExprs, 1645b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1646c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, 1647f88f7ab5adaa11d050270ffee6aa871e855f83b8Fariborz Jahanian move(SubExprs)); 1648b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1650b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new address-of-label expression. 16511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 16521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, performs semantic analysis, using the name of the label 1653b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// rather than attempting to map the label statement itself. 1654b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 165560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, 1656ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation LabelLoc, LabelDecl *Label) { 165757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); 1658b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1660b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new GNU statement expression. 16611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1662b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1663b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 166460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildStmtExpr(SourceLocation LParenLoc, 16659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *SubStmt, 1666b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 16679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); 1668b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1670b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new __builtin_choose_expr expression. 1671b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1672b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 167460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, 16759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Cond, Expr *LHS, Expr *RHS, 1676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1677b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.ActOnChooseExpr(BuiltinLoc, 16789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond, LHS, RHS, 1679b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 1680b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1682f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// \brief Build a new generic selection expression. 1683f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// 1684f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// By default, performs semantic analysis to build the new expression. 1685f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// Subclasses may override this routine to provide different behavior. 1686f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, 1687f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation DefaultLoc, 1688f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 1689f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *ControllingExpr, 1690f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **Types, 1691f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr **Exprs, 1692f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs) { 1693f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, 1694f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ControllingExpr, Types, Exprs, 1695f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne NumAssocs); 1696f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 1697f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 1698b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new overloaded operator call expression. 1699b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1700b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1701b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// The semantic analysis provides the behavior of template instantiation, 1702b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// copying with transformations that turn what looks like an overloaded 17031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// operator call into a use of a builtin operator, performing 1704b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// argument-dependent lookup, etc. Subclasses may override this routine to 1705b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// provide different behavior. 170660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, 1707b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 17089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Callee, 17099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *First, 17109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Second); 17111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new C++ "named" cast expression, such as static_cast or 1713b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// reinterpret_cast. 1714b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1715b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, this routine dispatches to one of the more-specific routines 17161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). 1717b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 171860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, 1719b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Stmt::StmtClass Class, 1720b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 17219d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1722b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1723b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 17249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1725b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1726b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor switch (Class) { 1727b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXStaticCastExprClass: 17289d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, 17291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 1731b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1732b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXDynamicCastExprClass: 17339d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, 17341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 17361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1737b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXReinterpretCastExprClass: 17389d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, 17391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, 1741b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 17421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1743b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXConstCastExprClass: 17449d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, 17451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 17471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1748b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor default: 1749b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Invalid C++ named cast"); 1750b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1752f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 1753b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1755b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ static_cast expression. 1756b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1757b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1758b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 175960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, 1760b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 17619d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1762b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1763b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 17649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1765b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1766c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, 17679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1768c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1769c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1770b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1771b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1772b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ dynamic_cast expression. 1773b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1774b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1775b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 177660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, 1777b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 17789d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1779b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1780b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 17819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1782b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1783c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, 17849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1785c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1786c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1787b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1788b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1789b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ reinterpret_cast expression. 1790b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1791b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1792b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 179360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, 1794b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 17959d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1796b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1797b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 17989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1799b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1800c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, 18019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1802c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1803c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1804b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1805b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1806b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ const_cast expression. 1807b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1808b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1809b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 181060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, 1811b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 18129d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1813b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1814b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 18159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1816b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1817c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, 18189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1819c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1820c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1821b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1823b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ functional-style cast expression. 1824b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1825b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1826b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1827ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, 1828ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 1829ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor Expr *Sub, 1830ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 1831ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, 1832f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiExprArg(&Sub, 1), 1833b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 1834b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1836b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ typeid(type) expression. 1837b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1838b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1839b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 184060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, 184157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor SourceLocation TypeidLoc, 184257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TypeSourceInfo *Operand, 1843b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1844c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, 184557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor RParenLoc); 1846b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 184801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 1849b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ typeid(expr) expression. 1850b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1851b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1852b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 185360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, 185457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor SourceLocation TypeidLoc, 18559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand, 1856b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 18579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, 185857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor RParenLoc); 18591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 18601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 186101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Build a new C++ __uuidof(type) expression. 186201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// 186301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// By default, performs semantic analysis to build the new expression. 186401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// Subclasses may override this routine to provide different behavior. 186501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, 186601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation TypeidLoc, 186701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TypeSourceInfo *Operand, 186801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation RParenLoc) { 186901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, 187001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet RParenLoc); 187101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 187201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 187301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Build a new C++ __uuidof(expr) expression. 187401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// 187501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// By default, performs semantic analysis to build the new expression. 187601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// Subclasses may override this routine to provide different behavior. 187701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, 187801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation TypeidLoc, 187901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Expr *Operand, 188001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation RParenLoc) { 188101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, 188201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet RParenLoc); 188301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 188401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 1885b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "this" expression. 1886b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1887b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds a new "this" expression without performing any 18881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// semantic analysis. Subclasses may override this routine to provide 1889b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// different behavior. 189060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, 1891ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor QualType ThisType, 1892ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor bool isImplicit) { 1893b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getSema().Owned( 1894828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, 1895828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor isImplicit)); 1896b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1897b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1898b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ throw expression. 1899b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1900b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1901b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1902bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, 1903bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor bool IsThrownVariableInScope) { 1904bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); 1905b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1906b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1907b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ default-argument expression. 1908b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1909b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds a new default-argument expression, which does not 1910b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// require any semantic analysis. Subclasses may override this routine to 1911b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// provide different behavior. 191260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, 1913036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor ParmVarDecl *Param) { 1914036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, 1915036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor Param)); 1916b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1917b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1918b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ zero-initialization expression. 1919b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1920b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1921b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1922ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, 1923ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 1924ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 1925ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, 19261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump MultiExprArg(getSema(), 0, 0), 1927ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor RParenLoc); 1928b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 19291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1930b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "new" expression. 1931b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1932b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1933b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 193460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, 19351bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor bool UseGlobal, 19361bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation PlacementLParen, 19371bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor MultiExprArg PlacementArgs, 19381bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation PlacementRParen, 19391bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceRange TypeIdParens, 19401bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor QualType AllocatedType, 19411bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *AllocatedTypeInfo, 19421bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor Expr *ArraySize, 19431bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation ConstructorLParen, 19441bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor MultiExprArg ConstructorArgs, 19451bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation ConstructorRParen) { 19461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getSema().BuildCXXNew(StartLoc, UseGlobal, 1947b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor PlacementLParen, 1948b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(PlacementArgs), 1949b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor PlacementRParen, 19504bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor TypeIdParens, 19511bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocatedType, 19521bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocatedTypeInfo, 19539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ArraySize, 1954b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ConstructorLParen, 1955b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(ConstructorArgs), 1956b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ConstructorRParen); 1957b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 19581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1959b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "delete" expression. 1960b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1961b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1962b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 196360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, 1964b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool IsGlobalDelete, 1965b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool IsArrayForm, 19669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand) { 1967b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, 19689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Operand); 1969b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 19701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1971b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new unary type trait expression. 1972b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1973b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1974b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 197560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, 19763d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor SourceLocation StartLoc, 19773d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *T, 19783d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor SourceLocation RParenLoc) { 19793d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); 1980b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1981b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 19826ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// \brief Build a new binary type trait expression. 19836ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// 19846ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// By default, performs semantic analysis to build the new expression. 19856ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// Subclasses may override this routine to provide different behavior. 19866ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, 19876ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation StartLoc, 19886ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *LhsT, 19896ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *RhsT, 19906ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation RParenLoc) { 19916ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); 19926ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 19936ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 199421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// \brief Build a new array type trait expression. 199521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// 199621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// By default, performs semantic analysis to build the new expression. 199721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// Subclasses may override this routine to provide different behavior. 199821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, 199921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SourceLocation StartLoc, 200021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *TSInfo, 200121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Expr *DimExpr, 200221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SourceLocation RParenLoc) { 200321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); 200421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 200521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 2006552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// \brief Build a new expression trait expression. 2007552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// 2008552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// By default, performs semantic analysis to build the new expression. 2009552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// Subclasses may override this routine to provide different behavior. 2010552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExprResult RebuildExpressionTrait(ExpressionTrait Trait, 2011552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation StartLoc, 2012552622067dc45013d240f73952fece703f5e63bdJohn Wiegley Expr *Queried, 2013552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation RParenLoc) { 2014552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); 2015552622067dc45013d240f73952fece703f5e63bdJohn Wiegley } 2016552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 20171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new (previously unresolved) declaration reference 2018b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// expression. 2019b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2020b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2021b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 202200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor ExprResult RebuildDependentScopeDeclRefExpr( 202300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 20242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2025f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall const TemplateArgumentListInfo *TemplateArgs) { 2026b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXScopeSpec SS; 202700cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor SS.Adopt(QualifierLoc); 2028f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 2029f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (TemplateArgs) 20302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo, 2031f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall *TemplateArgs); 2032f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 20332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo); 2034b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2035b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2036b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new template-id expression. 2037b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2038b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2039b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 204060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, 2041f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall LookupResult &R, 2042f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall bool RequiresADL, 2043d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo &TemplateArgs) { 2044f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); 2045b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2046b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2047b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 2048b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2049b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2050b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 205160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXConstructExpr(QualType T, 20527cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara SourceLocation Loc, 20537cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara CXXConstructorDecl *Constructor, 20547cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool IsElidable, 20557cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara MultiExprArg Args, 20567cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates, 20577cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool RequiresZeroInit, 2058428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth CXXConstructExpr::ConstructionKind ConstructKind, 20597cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara SourceRange ParenRange) { 2060ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> ConvertedArgs(SemaRef); 2061c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, 20624411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor ConvertedArgs)) 2063f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2064c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 20654411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, 20668c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor move_arg(ConvertedArgs), 20677cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HadMultipleCandidates, 2068428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth RequiresZeroInit, ConstructKind, 2069428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth ParenRange); 2070b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2071b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2072b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 2073b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2074b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2075b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 2076ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, 2077ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 2078ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor MultiExprArg Args, 2079ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 2080ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, 2081b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LParenLoc, 2082b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(Args), 2083b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 2084b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2085b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2086b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 2087b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2088b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2089b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 2090ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, 2091ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 2092ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor MultiExprArg Args, 2093ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 2094ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, 2095b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LParenLoc, 2096b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(Args), 2097b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 2098b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 20991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2100b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new member reference expression. 2101b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2102b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2103b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 210460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, 21057c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualType BaseType, 21067c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor bool IsArrow, 21077c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor SourceLocation OperatorLoc, 21087c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2109129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall NamedDecl *FirstQualifierInScope, 21102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &MemberNameInfo, 2111129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall const TemplateArgumentListInfo *TemplateArgs) { 2112b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXScopeSpec SS; 21137c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor SS.Adopt(QualifierLoc); 21141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, 2116aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OperatorLoc, IsArrow, 2117129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SS, FirstQualifierInScope, 21182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberNameInfo, 21192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TemplateArgs); 2120b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2121b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2122129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Build a new member reference expression. 21233b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// 21243b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// By default, performs semantic analysis to build the new expression. 21253b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// Subclasses may override this routine to provide different behavior. 21269138b4e96429cbaae00c52c15c960f72b6645088Richard Smith ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, 21279138b4e96429cbaae00c52c15c960f72b6645088Richard Smith SourceLocation OperatorLoc, 21289138b4e96429cbaae00c52c15c960f72b6645088Richard Smith bool IsArrow, 21299138b4e96429cbaae00c52c15c960f72b6645088Richard Smith NestedNameSpecifierLoc QualifierLoc, 21309138b4e96429cbaae00c52c15c960f72b6645088Richard Smith NamedDecl *FirstQualifierInScope, 21319138b4e96429cbaae00c52c15c960f72b6645088Richard Smith LookupResult &R, 2132129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall const TemplateArgumentListInfo *TemplateArgs) { 21333b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor CXXScopeSpec SS; 21344c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor SS.Adopt(QualifierLoc); 21351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, 2137aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OperatorLoc, IsArrow, 2138c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall SS, FirstQualifierInScope, 2139c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R, TemplateArgs); 21403b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 21411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21422e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// \brief Build a new noexcept expression. 21432e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// 21442e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// By default, performs semantic analysis to build the new expression. 21452e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// Subclasses may override this routine to provide different behavior. 21462e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { 21472e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); 21482e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl } 21492e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 2150ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Build a new expression to compute the length of a parameter pack. 2151ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, 2152ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation PackLoc, 2153ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation RParenLoc, 2154089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor llvm::Optional<unsigned> Length) { 2155089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor if (Length) 2156089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), 2157089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor OperatorLoc, Pack, PackLoc, 2158089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor RParenLoc, *Length); 2159089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor 2160ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), 2161ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor OperatorLoc, Pack, PackLoc, 2162089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor RParenLoc); 2163ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor } 2164ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 2165b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new Objective-C @encode expression. 2166b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2167b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2168b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 216960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, 217081d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *EncodeTypeInfo, 2171b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 217281d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, 2173b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc)); 21741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 2175b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 217692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /// \brief Build a new Objective-C class message. 217760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, 217892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Selector Sel, 2179207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelectorLocs, 218092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ObjCMethodDecl *Method, 2181c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation LBracLoc, 218292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor MultiExprArg Args, 218392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor SourceLocation RBracLoc) { 218492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return SemaRef.BuildClassMessage(ReceiverTypeInfo, 218592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ReceiverTypeInfo->getType(), 218692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /*SuperLoc=*/SourceLocation(), 2187207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Sel, Method, LBracLoc, SelectorLocs, 2188f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis RBracLoc, move(Args)); 218992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 219092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 219192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /// \brief Build a new Objective-C instance message. 219260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCMessageExpr(Expr *Receiver, 219392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Selector Sel, 2194207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelectorLocs, 219592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ObjCMethodDecl *Method, 2196c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation LBracLoc, 219792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor MultiExprArg Args, 219892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor SourceLocation RBracLoc) { 21999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildInstanceMessage(Receiver, 22009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Receiver->getType(), 220192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /*SuperLoc=*/SourceLocation(), 2202207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Sel, Method, LBracLoc, SelectorLocs, 2203f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis RBracLoc, move(Args)); 220492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 220592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 2206f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// \brief Build a new Objective-C ivar reference expression. 2207f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// 2208f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// By default, performs semantic analysis to build the new expression. 2209f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// Subclasses may override this routine to provide different behavior. 221060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, 2211f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor SourceLocation IvarLoc, 2212f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor bool IsArrow, bool IsFreeIvar) { 2213f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // FIXME: We lose track of the IsFreeIvar bit. 2214f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor CXXScopeSpec SS; 2215429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Base = getSema().Owned(BaseArg); 2216f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, 2217f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Sema::LookupMemberName); 221860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2219f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FIME:*/IvarLoc, 2220d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, 2221ad00b7705f9bbee81beeac428e7c6587734ab5a6John McCall false); 2222429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Result.isInvalid() || Base.isInvalid()) 2223f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2224c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2225f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Result.get()) 2226f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor return move(Result); 2227c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2228429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), 2229c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /*FIXME:*/IvarLoc, IsArrow, SS, 2230f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FirstQualifierInScope=*/0, 2231c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt R, 2232f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*TemplateArgs=*/0); 2233f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor } 2234e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor 2235e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// \brief Build a new Objective-C property reference expression. 2236e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// 2237e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2238e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 223960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, 22403c3b7f90a863af43fa63043d396553ecf205351cJohn McCall ObjCPropertyDecl *Property, 22413c3b7f90a863af43fa63043d396553ecf205351cJohn McCall SourceLocation PropertyLoc) { 2242e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor CXXScopeSpec SS; 2243429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Base = getSema().Owned(BaseArg); 2244e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, 2245e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor Sema::LookupMemberName); 2246e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor bool IsArrow = false; 224760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2248e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*FIME:*/PropertyLoc, 2249d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, false); 2250429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Result.isInvalid() || Base.isInvalid()) 2251f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2252c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2253e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (Result.get()) 2254e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor return move(Result); 2255c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2256429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), 2257c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /*FIXME:*/PropertyLoc, IsArrow, 2258c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SS, 2259e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*FirstQualifierInScope=*/0, 2260c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt R, 2261e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*TemplateArgs=*/0); 2262e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor } 2263c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 226412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// \brief Build a new Objective-C property reference expression. 22659cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor /// 22669cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor /// By default, performs semantic analysis to build the new expression. 226712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// Subclasses may override this routine to provide different behavior. 226812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, 226912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *Getter, 227012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *Setter, 227112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation PropertyLoc) { 227212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // Since these expressions can only be value-dependent, we do not 227312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // need to perform semantic analysis again. 227412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return Owned( 227512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, 227612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall VK_LValue, OK_ObjCProperty, 227712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall PropertyLoc, Base)); 22789cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor } 22799cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor 2280f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// \brief Build a new Objective-C "isa" expression. 2281f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// 2282f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// By default, performs semantic analysis to build the new expression. 2283f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// Subclasses may override this routine to provide different behavior. 228460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, 2285f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor bool IsArrow) { 2286f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor CXXScopeSpec SS; 2287429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Base = getSema().Owned(BaseArg); 2288f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, 2289f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Sema::LookupMemberName); 229060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2291f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FIME:*/IsaLoc, 2292d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, false); 2293429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Result.isInvalid() || Base.isInvalid()) 2294f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2295c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2296f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Result.get()) 2297f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor return move(Result); 2298c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2299429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), 2300c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /*FIXME:*/IsaLoc, IsArrow, SS, 2301f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FirstQualifierInScope=*/0, 2302c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt R, 2303f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*TemplateArgs=*/0); 2304f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor } 2305c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2306b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new shuffle vector expression. 2307b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2308b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2309b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 231060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, 2311f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall MultiExprArg SubExprs, 2312f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation RParenLoc) { 2313b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Find the declaration for __builtin_shufflevector 23141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const IdentifierInfo &Name 2315b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.Context.Idents.get("__builtin_shufflevector"); 2316b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); 2317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); 2318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); 23191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Build a reference to the __builtin_shufflevector builtin 2321b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); 2322429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Callee 2323429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), 2324429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley VK_LValue, BuiltinLoc)); 2325429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley Callee = SemaRef.UsualUnaryConversions(Callee.take()); 2326429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Callee.isInvalid()) 2327429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return ExprError(); 23281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Build the CallExpr 2330b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor unsigned NumSubExprs = SubExprs.size(); 2331b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Expr **Subs = (Expr **)SubExprs.release(); 2332429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult TheCall = SemaRef.Owned( 2333429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(), 2334b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Subs, NumSubExprs, 23355291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor Builtin->getCallResultType(), 2336f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr::getValueKindForType(Builtin->getResultType()), 2337429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley RParenLoc)); 23381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2339b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Type-check the __builtin_shufflevector expression. 2340429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take())); 2341b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 234243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 23438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \brief Build a new template argument pack expansion. 23448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 23458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// By default, performs semantic analysis to build a new pack expansion 23468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// for a template argument. Subclasses may override this routine to provide 23478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// different behavior. 23488491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, 2349cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor SourceLocation EllipsisLoc, 2350cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 23518491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor switch (Pattern.getArgument().getKind()) { 23527a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor case TemplateArgument::Expression: { 23537a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor ExprResult Result 235467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor = getSema().CheckPackExpansion(Pattern.getSourceExpression(), 235567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor EllipsisLoc, NumExpansions); 23567a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor if (Result.isInvalid()) 23577a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor return TemplateArgumentLoc(); 23587a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor 23597a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor return TemplateArgumentLoc(Result.get(), Result.get()); 23607a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor } 2361dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 23628491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Template: 2363a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor return TemplateArgumentLoc(TemplateArgument( 2364a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor Pattern.getArgument().getAsTemplate(), 23652be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor NumExpansions), 2366b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Pattern.getTemplateQualifierLoc(), 2367a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor Pattern.getTemplateNameLoc(), 2368a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor EllipsisLoc); 23698491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 23708491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Null: 23718491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Integral: 23728491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Declaration: 23738491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Pack: 2374a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 23758491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor llvm_unreachable("Pack expansion pattern has no parameter packs"); 23768491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 23778491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Type: 23788491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (TypeSourceInfo *Expansion 23798491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), 2380cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor EllipsisLoc, 2381cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions)) 23828491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), 23838491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Expansion); 23848491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor break; 23858491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 23868491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 23878491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return TemplateArgumentLoc(); 23888491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 23898491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 2390dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// \brief Build a new expression pack expansion. 2391dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// 2392dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// By default, performs semantic analysis to build a new pack expansion 2393dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// for an expression. Subclasses may override this routine to provide 2394dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// different behavior. 239567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, 239667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> NumExpansions) { 239767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); 2398dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2399dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 2400dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman /// \brief Build a new atomic operation expression. 2401dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman /// 2402dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman /// By default, performs semantic analysis to build the new expression. 2403dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman /// Subclasses may override this routine to provide different behavior. 2404dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, 2405dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman MultiExprArg SubExprs, 2406dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman QualType RetTy, 2407dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman AtomicExpr::AtomicOp Op, 2408dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman SourceLocation RParenLoc) { 2409dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman // Just create the expression; there is not any interesting semantic 2410dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman // analysis here because we can't actually build an AtomicExpr until 2411dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman // we are sure it is semantically sound. 2412dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman unsigned NumSubExprs = SubExprs.size(); 2413dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman Expr **Subs = (Expr **)SubExprs.release(); 2414dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs, 2415dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman NumSubExprs, RetTy, Op, 2416dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman RParenLoc); 2417dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman } 2418dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 241943fed0de4f5bc189e45562491f83d5193eb8dac0John McCallprivate: 2420c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TypeLoc TransformTypeInObjectScope(TypeLoc TL, 2421c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType, 2422c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *FirstQualifierInScope, 2423c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor CXXScopeSpec &SS); 2424b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 2425b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, 2426b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor QualType ObjectType, 2427b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor NamedDecl *FirstQualifierInScope, 2428b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor CXXScopeSpec &SS); 2429577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}; 2430b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 243143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 243260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { 243343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!S) 243443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return SemaRef.Owned(S); 24351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 243643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor switch (S->getStmtClass()) { 243743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor case Stmt::NoStmtClass: break; 24381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 243943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform individual statement nodes 244043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) \ 244143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); 244263c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define ABSTRACT_STMT(Node) 244343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) 24444bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 24451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 244643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform expressions by calling TransformExpr. 244743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) 24487381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 244943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) case Stmt::Node##Class: 24504bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 245143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor { 245260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); 245343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (E.isInvalid()) 2454f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 24551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take())); 245743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 24581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 24591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24603fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 246143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 24621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2464670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregortemplate<typename Derived> 246560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { 2466b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!E) 2467b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.Owned(E); 2468b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2469b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor switch (E->getStmtClass()) { 2470b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::NoStmtClass: break; 2471b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define STMT(Node, Parent) case Stmt::Node##Class: break; 24727381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 2473b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent) \ 2474454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); 24754bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 24761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 24771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24783fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 2479657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor} 2480657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor 2481657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregortemplate<typename Derived> 2482aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorbool TreeTransform<Derived>::TransformExprs(Expr **Inputs, 2483aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor unsigned NumInputs, 2484aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool IsCall, 2485686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<Expr *> &Outputs, 2486aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool *ArgChanged) { 2487aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor for (unsigned I = 0; I != NumInputs; ++I) { 2488aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor // If requested, drop call arguments that need to be dropped. 2489aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (IsCall && getDerived().DropCallArgument(Inputs[I])) { 2490aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (ArgChanged) 2491aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor *ArgChanged = true; 2492aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2493aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor break; 2494aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 2495aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2496dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { 2497dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Expr *Pattern = Expansion->getPattern(); 2498dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2499686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<UnexpandedParameterPack, 2> Unexpanded; 2500dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 2501dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 2502dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2503dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // Determine whether the set of unexpanded parameter packs can and should 2504dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // be expanded. 2505dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor bool Expand = true; 2506d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 250767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> OrigNumExpansions 250867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor = Expansion->getNumExpansions(); 250967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; 2510dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), 2511dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Pattern->getSourceRange(), 2512a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 2513d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Expand, RetainExpansion, 2514d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) 2515dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2516dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2517dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (!Expand) { 2518dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // The transform has determined that we should perform a simple 2519dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // transformation on the pack expansion, producing another pack 2520dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // expansion. 2521dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 2522dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult OutPattern = getDerived().TransformExpr(Pattern); 2523dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (OutPattern.isInvalid()) 2524dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2525dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2526dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), 252767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor Expansion->getEllipsisLoc(), 252867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor NumExpansions); 2529dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (Out.isInvalid()) 2530dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2531dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2532dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (ArgChanged) 2533dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor *ArgChanged = true; 2534dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Outputs.push_back(Out.get()); 2535dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor continue; 2536dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2537c8fc90a854b4ccba21c85884676a80334159dd94John McCall 2538c8fc90a854b4ccba21c85884676a80334159dd94John McCall // Record right away that the argument was changed. This needs 2539c8fc90a854b4ccba21c85884676a80334159dd94John McCall // to happen even if the array expands to nothing. 2540c8fc90a854b4ccba21c85884676a80334159dd94John McCall if (ArgChanged) *ArgChanged = true; 2541dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2542dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // The transform has determined that we should perform an elementwise 2543dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // expansion of the pattern. Do so. 2544cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 2545dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 2546dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult Out = getDerived().TransformExpr(Pattern); 2547dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (Out.isInvalid()) 2548dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2549dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 255077d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.get()->containsUnexpandedParameterPack()) { 255167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), 255267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor OrigNumExpansions); 255377d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.isInvalid()) 255477d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor return true; 255577d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor } 255677d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor 2557dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Outputs.push_back(Out.get()); 2558dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2559dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2560dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor continue; 2561dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2562dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2563aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor ExprResult Result = getDerived().TransformExpr(Inputs[I]); 2564aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (Result.isInvalid()) 2565aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return true; 2566aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2567aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (Result.get() != Inputs[I] && ArgChanged) 2568aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor *ArgChanged = true; 2569aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2570aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Outputs.push_back(Result.get()); 2571aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 2572aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2573aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return false; 2574aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor} 2575aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2576aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregortemplate<typename Derived> 2577c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorNestedNameSpecifierLoc 2578c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorTreeTransform<Derived>::TransformNestedNameSpecifierLoc( 2579c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc NNS, 2580c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType, 2581c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *FirstQualifierInScope) { 2582686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; 2583c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; 2584c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Qualifier = Qualifier.getPrefix()) 2585c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Qualifiers.push_back(Qualifier); 2586c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2587c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor CXXScopeSpec SS; 2588c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor while (!Qualifiers.empty()) { 2589c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); 2590c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); 2591c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2592c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor switch (QNNS->getKind()) { 2593c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::Identifier: 2594c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0, 2595c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor *QNNS->getAsIdentifier(), 2596c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalBeginLoc(), 2597c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalEndLoc(), 2598c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor ObjectType, false, SS, 2599c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor FirstQualifierInScope, false)) 2600c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(); 2601c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2602c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2603c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2604c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::Namespace: { 2605c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamespaceDecl *NS 2606c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast_or_null<NamespaceDecl>( 2607c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor getDerived().TransformDecl( 2608c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalBeginLoc(), 2609c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QNNS->getAsNamespace())); 2610c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); 2611c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2612c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 2613c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2614c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::NamespaceAlias: { 2615c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamespaceAliasDecl *Alias 2616c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast_or_null<NamespaceAliasDecl>( 2617c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor getDerived().TransformDecl(Q.getLocalBeginLoc(), 2618c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QNNS->getAsNamespaceAlias())); 2619c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), 2620c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalEndLoc()); 2621c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2622c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 2623c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2624c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::Global: 2625c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // There is no meaningful transformation that one could perform on the 2626c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // global scope. 2627c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); 2628c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2629c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2630c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::TypeSpecWithTemplate: 2631c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::TypeSpec: { 2632c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, 2633c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor FirstQualifierInScope, SS); 2634c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2635c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (!TL) 2636c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(); 2637c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2638c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || 2639c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor (SemaRef.getLangOptions().CPlusPlus0x && 2640c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TL.getType()->isEnumeralType())) { 2641c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor assert(!TL.getType().hasLocalQualifiers() && 2642c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor "Can't get cv-qualifiers here"); 264395aafb2453e1fecec8dcfd9e125cd78277f45859Richard Smith if (TL.getType()->isEnumeralType()) 264495aafb2453e1fecec8dcfd9e125cd78277f45859Richard Smith SemaRef.Diag(TL.getBeginLoc(), 264595aafb2453e1fecec8dcfd9e125cd78277f45859Richard Smith diag::warn_cxx98_compat_enum_nested_name_spec); 2646c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, 2647c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalEndLoc()); 2648c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2649c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 265000c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu // If the nested-name-specifier is an invalid type def, don't emit an 265100c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu // error because a previous error should have already been emitted. 265200c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL); 265300c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) { 265400c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) 265500c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu << TL.getType() << SS.getRange(); 265600c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu } 2657c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(); 2658c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 26597c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor } 2660c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 26617c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor // The qualifier-in-scope and object type only apply to the leftmost entity. 2662c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor FirstQualifierInScope = 0; 26637c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor ObjectType = QualType(); 2664c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 2665c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2666c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // Don't rebuild the nested-name-specifier if we don't have to. 2667c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && 2668c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor !getDerived().AlwaysRebuild()) 2669c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NNS; 2670c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2671c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // If we can re-use the source-location data from the original 2672c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // nested-name-specifier, do so. 2673c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (SS.location_size() == NNS.getDataLength() && 2674c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) 2675c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); 2676c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2677c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // Allocate new nested-name-specifier location information. 2678c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return SS.getWithLocInContext(SemaRef.Context); 2679c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor} 2680c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2681c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived> 26822577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclarationNameInfo 26832577743c5650c646fb705df01403707e94f2df04Abramo BagnaraTreeTransform<Derived> 268443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { 26852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName Name = NameInfo.getName(); 268681499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor if (!Name) 26872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(); 268881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor 268981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor switch (Name.getNameKind()) { 269081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::Identifier: 269181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCZeroArgSelector: 269281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCOneArgSelector: 269381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCMultiArgSelector: 269481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXOperatorName: 26953e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt case DeclarationName::CXXLiteralOperatorName: 269681499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXUsingDirective: 26972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return NameInfo; 26981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 269981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXConstructorName: 270081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXDestructorName: 270181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXConversionFunctionName: { 27022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TypeSourceInfo *NewTInfo; 27032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara CanQualType NewCanTy; 27042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { 270543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NewTInfo = getDerived().TransformType(OldTInfo); 270643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (!NewTInfo) 270743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return DeclarationNameInfo(); 270843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); 27092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 27102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara else { 27112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewTInfo = 0; 27122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); 271343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType NewT = getDerived().TransformType(Name.getCXXNameType()); 27142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (NewT.isNull()) 27152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(); 27162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewCanTy = SemaRef.Context.getCanonicalType(NewT); 27172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 27181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName NewName 27202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), 27212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewCanTy); 27222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NewNameInfo(NameInfo); 27232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewNameInfo.setName(NewName); 27242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewNameInfo.setNamedTypeInfo(NewTInfo); 27252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return NewNameInfo; 272681499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor } 27271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 27281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2729b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unknown name kind."); 273081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor} 273181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor 273281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregortemplate<typename Derived> 27331eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 2734fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, 2735fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName Name, 2736fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 2737fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor QualType ObjectType, 2738fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor NamedDecl *FirstQualifierInScope) { 2739fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { 2740fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateDecl *Template = QTN->getTemplateDecl(); 2741fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor assert(Template && "qualified template name must refer to a template"); 2742fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2743fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateDecl *TransTemplate 2744fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, 2745fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor Template)); 2746fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!TransTemplate) 2747fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 2748fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2749fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2750fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SS.getScopeRep() == QTN->getQualifier() && 2751fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransTemplate == Template) 2752fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 2753fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2754fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), 2755fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransTemplate); 2756fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2757fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2758fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { 2759fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (SS.getScopeRep()) { 2760fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor // These apply to the scope specifier, not the template. 2761fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType = QualType(); 2762fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor FirstQualifierInScope = 0; 2763fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2764fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2765fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2766fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SS.getScopeRep() == DTN->getQualifier() && 2767fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType.isNull()) 2768fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 2769fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2770fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (DTN->isIdentifier()) { 2771fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(SS, 2772fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor *DTN->getIdentifier(), 2773fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor NameLoc, 2774fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType, 2775fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor FirstQualifierInScope); 2776fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2777fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2778fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, 2779fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType); 2780fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2781fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2782fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (TemplateDecl *Template = Name.getAsTemplateDecl()) { 2783fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateDecl *TransTemplate 2784fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, 2785fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor Template)); 2786fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!TransTemplate) 2787fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 2788fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2789fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2790fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransTemplate == Template) 2791fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 2792fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2793fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(TransTemplate); 2794fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2795fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2796fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (SubstTemplateTemplateParmPackStorage *SubstPack 2797fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = Name.getAsSubstTemplateTemplateParmPack()) { 2798fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateTemplateParmDecl *TransParam 2799fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = cast_or_null<TemplateTemplateParmDecl>( 2800fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); 2801fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!TransParam) 2802fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 2803fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2804fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2805fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransParam == SubstPack->getParameterPack()) 2806fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 2807fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2808fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(TransParam, 2809fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SubstPack->getArgumentPack()); 2810fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2811fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2812fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor // These should be getting filtered out before they reach the AST. 2813fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor llvm_unreachable("overloaded function decl survived to here"); 2814fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 2815fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor} 2816fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2817fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregortemplate<typename Derived> 2818833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallvoid TreeTransform<Derived>::InventTemplateArgumentLoc( 2819833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgument &Arg, 2820833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &Output) { 2821833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation Loc = getDerived().getBaseLocation(); 2822670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor switch (Arg.getKind()) { 2823670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Null: 28249f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin llvm_unreachable("null template argument in TreeTransform"); 2825833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2826833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2827833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Type: 2828833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(Arg, 2829a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); 2830c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2831833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2832833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2833788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: 2834b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor case TemplateArgument::TemplateExpansion: { 2835b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor NestedNameSpecifierLocBuilder Builder; 2836b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor TemplateName Template = Arg.getAsTemplate(); 2837b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) 2838b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); 2839b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) 2840b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); 2841b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor 2842b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (Arg.getKind() == TemplateArgument::Template) 2843b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Output = TemplateArgumentLoc(Arg, 2844b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.getWithLocInContext(SemaRef.Context), 2845b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Loc); 2846b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor else 2847b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Output = TemplateArgumentLoc(Arg, 2848b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.getWithLocInContext(SemaRef.Context), 2849b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Loc, Loc); 2850b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor 2851a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor break; 2852b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor } 2853a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 2854833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Expression: 2855833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); 2856833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2857833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2858833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Declaration: 2859670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Integral: 2860833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Pack: 2861828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); 2862833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2863833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 2864833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 2865833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2866833ca991c1bfc967f0995974ca86f66ba1f666b5John McCalltemplate<typename Derived> 2867833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TreeTransform<Derived>::TransformTemplateArgument( 2868833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc &Input, 2869833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &Output) { 2870833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgument &Arg = Input.getArgument(); 2871833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall switch (Arg.getKind()) { 2872833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Null: 2873833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Integral: 2874833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = Input; 2875833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 28761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2877670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Type: { 2878a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *DI = Input.getTypeSourceInfo(); 2879833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (DI == NULL) 2880a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall DI = InventTypeSourceInfo(Input.getArgument().getAsType()); 2881833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2882833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall DI = getDerived().TransformType(DI); 2883833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!DI) return true; 2884833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2885833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); 2886833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2887670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 28881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2889670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Declaration: { 2890833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: we should never have to transform one of these. 2891972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor DeclarationName Name; 2892972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) 2893972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor Name = ND->getDeclName(); 2894788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor TemporaryBase Rebase(*this, Input.getLocation(), Name); 28957c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); 2896833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!D) return true; 2897833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2898828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Expr *SourceExpr = Input.getSourceDeclExpression(); 2899828bff2079b6a91ecd7ed5b842c59527d7682789John McCall if (SourceExpr) { 2900828bff2079b6a91ecd7ed5b842c59527d7682789John McCall EnterExpressionEvaluationContext Unevaluated(getSema(), 2901f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::Unevaluated); 290260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(SourceExpr); 29039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SourceExpr = (E.isInvalid() ? 0 : E.take()); 2904828bff2079b6a91ecd7ed5b842c59527d7682789John McCall } 2905828bff2079b6a91ecd7ed5b842c59527d7682789John McCall 2906828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); 2907833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2908670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 29091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2910788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: { 2911b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); 2912b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (QualifierLoc) { 2913b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); 2914b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (!QualifierLoc) 2915b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor return true; 2916b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor } 2917b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor 29181d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor CXXScopeSpec SS; 29191d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor SS.Adopt(QualifierLoc); 2920788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor TemplateName Template 29211d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), 29221d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor Input.getTemplateNameLoc()); 2923788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor if (Template.isNull()) 2924788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return true; 2925c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2926b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, 2927788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor Input.getTemplateNameLoc()); 2928788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return false; 2929788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor } 2930a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 2931a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 2932a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor llvm_unreachable("Caller should expand pack expansions"); 2933a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 2934670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Expression: { 2935670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Template argument expressions are not potentially evaluated. 29361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EnterExpressionEvaluationContext Unevaluated(getSema(), 2937f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::Unevaluated); 29381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2939833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Expr *InputExpr = Input.getSourceExpression(); 2940833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); 2941833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2942223de2497fdaacf3a6b0a123c12265ca837abf19Chris Lattner ExprResult E = getDerived().TransformExpr(InputExpr); 2943833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (E.isInvalid()) return true; 29449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); 2945833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2946670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 29471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2948670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Pack: { 2949686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<TemplateArgument, 4> TransformedArgs; 2950670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor TransformedArgs.reserve(Arg.pack_size()); 29511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (TemplateArgument::pack_iterator A = Arg.pack_begin(), 2952670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor AEnd = Arg.pack_end(); 2953670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor A != AEnd; ++A) { 29541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2955833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: preserve source information here when we start 2956833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // caring about parameter packs. 2957833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2958828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TemplateArgumentLoc InputArg; 2959828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TemplateArgumentLoc OutputArg; 2960828bff2079b6a91ecd7ed5b842c59527d7682789John McCall getDerived().InventTemplateArgumentLoc(*A, InputArg); 2961828bff2079b6a91ecd7ed5b842c59527d7682789John McCall if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) 2962833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 2963833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2964828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TransformedArgs.push_back(OutputArg.getArgument()); 2965670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 2966910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor 2967910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TemplateArgument *TransformedArgsPtr 2968910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor = new (getSema().Context) TemplateArgument[TransformedArgs.size()]; 2969910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor std::copy(TransformedArgs.begin(), TransformedArgs.end(), 2970910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TransformedArgsPtr); 2971910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr, 2972910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TransformedArgs.size()), 2973910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor Input.getLocInfo()); 2974833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2975670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 2976670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 29771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2978670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Work around bogus GCC warning 2979833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 2980670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor} 2981670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor 29827ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// \brief Iterator adaptor that invents template argument location information 29837ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// for each of the template arguments in its underlying iterator. 29847ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename Derived, typename InputIterator> 29857ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorclass TemplateArgumentLocInventIterator { 29867ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TreeTransform<Derived> &Self; 29877ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Iter; 29887ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29897ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorpublic: 29907ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc value_type; 29917ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc reference; 29927ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef typename std::iterator_traits<InputIterator>::difference_type 29937ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor difference_type; 29947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef std::input_iterator_tag iterator_category; 29957ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class pointer { 29977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Arg; 2998fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 29997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 30007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } 30017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLoc *operator->() const { return &Arg; } 30037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 30047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator() { } 30067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, 30087ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Iter) 30097ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor : Self(Self), Iter(Iter) { } 30107ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30117ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator &operator++() { 30127ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++Iter; 30137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return *this; 3014fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor } 3015fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 30167ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator operator++(int) { 30177ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator Old(*this); 30187ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++(*this); 30197ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Old; 30207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 30217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor reference operator*() const { 30237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Result; 30247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor Self.InventTemplateArgumentLoc(*Iter, Result); 30257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Result; 30267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 30277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor pointer operator->() const { return pointer(**this); } 30297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator==(const TemplateArgumentLocInventIterator &X, 30317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLocInventIterator &Y) { 30327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Iter == Y.Iter; 30337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 3034fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 30357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator!=(const TemplateArgumentLocInventIterator &X, 30367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLocInventIterator &Y) { 30377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Iter != Y.Iter; 30387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 30397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor}; 30407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30417f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregortemplate<typename Derived> 30427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename InputIterator> 30437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorbool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, 30447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Last, 30457f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor TemplateArgumentListInfo &Outputs) { 30467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor for (; First != Last; ++First) { 30477f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor TemplateArgumentLoc Out; 30487ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc In = *First; 30498491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30508491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (In.getArgument().getKind() == TemplateArgument::Pack) { 30518491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // Unpack argument packs, which we translate them into separate 30528491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // arguments. 30537ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // FIXME: We could do much better if we could guarantee that the 30547ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // TemplateArgumentLocInfo for the pack expansion would be usable for 30557ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // all of the template arguments in the argument pack. 30567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLocInventIterator<Derived, 30577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgument::pack_iterator> 30587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor PackLocIterator; 30597ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor if (TransformTemplateArguments(PackLocIterator(*this, 30607ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor In.getArgument().pack_begin()), 30617ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor PackLocIterator(*this, 30627ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor In.getArgument().pack_end()), 30637ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor Outputs)) 30647ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return true; 30658491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30668491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 30678491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 30688491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30698491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (In.getArgument().isPackExpansion()) { 30708491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // We have a pack expansion, for which we will be substituting into 30718491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // the pattern. 30728491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor SourceLocation Ellipsis; 3073cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> OrigNumExpansions; 30748491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc Pattern 3075cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions, 3076cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor getSema().Context); 30778491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 3078686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<UnexpandedParameterPack, 2> Unexpanded; 30798491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 30808491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 30818491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30828491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // Determine whether the set of unexpanded parameter packs can and should 30838491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // be expanded. 30848491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor bool Expand = true; 3085d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 3086cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; 30878491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TryExpandParameterPacks(Ellipsis, 30888491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Pattern.getSourceRange(), 3089a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 3090d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Expand, 3091d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor RetainExpansion, 3092d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) 30938491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 30948491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30958491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (!Expand) { 30968491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The transform has determined that we should perform a simple 30978491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // transformation on the pack expansion, producing another pack 30988491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // expansion. 30998491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc OutPattern; 31008491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 31018491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) 31028491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 31038491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 3104cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, 3105cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions); 31068491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (Out.getArgument().isNull()) 31078491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 31088491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 31098491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Outputs.addArgument(Out); 31108491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 31118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 31128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 31138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The transform has determined that we should perform an elementwise 31148491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // expansion of the pattern. Do so. 3115cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 31168491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 31178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 31188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, Out)) 31198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 31208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 312177d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.getArgument().containsUnexpandedParameterPack()) { 3122cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Out = getDerived().RebuildPackExpansion(Out, Ellipsis, 3123cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor OrigNumExpansions); 312477d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.getArgument().isNull()) 312577d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor return true; 312677d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor } 312777d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor 31288491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Outputs.addArgument(Out); 31298491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 31308491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 31313cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 31323cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // forgetting the partially-substituted parameter pack. 31333cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (RetainExpansion) { 31343cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 31353cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 31363cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, Out)) 31373cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor return true; 31383cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 3139cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Out = getDerived().RebuildPackExpansion(Out, Ellipsis, 3140cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor OrigNumExpansions); 31413cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (Out.getArgument().isNull()) 31423cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor return true; 31433cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 31443cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor Outputs.addArgument(Out); 31453cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor } 3146d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 31478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 31488491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 31498491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 31508491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The simple case: 31518491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(In, Out)) 31527f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return true; 31537f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 31547f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor Outputs.addArgument(Out); 31557f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor } 31567f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 31577f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return false; 31587f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 31597f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor} 31607f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 3161577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 3162577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// Type transformation 3163577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 3164577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3165577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 316643fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::TransformType(QualType T) { 3167577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (getDerived().AlreadyTransformed(T)) 3168577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return T; 31691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3170a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Temporary workaround. All of these transformations should 3171a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // eventually turn into transformations on TypeLocs. 3172c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, 3173c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor getDerived().getBaseLocation()); 3174c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 317543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeSourceInfo *NewDI = getDerived().TransformType(DI); 31761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3177a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (!NewDI) 3178a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 31791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3180a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return NewDI->getType(); 3181577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 31821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3183577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 318443fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { 3185a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlreadyTransformed(DI->getType())) 3186a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return DI; 31871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3188a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder TLB; 31891bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 3190a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLoc TL = DI->getTypeLoc(); 3191a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TLB.reserve(TL.getFullDataSize()); 31921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 319343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result = getDerived().TransformType(TLB, TL); 3194a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3195a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return 0; 31961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3197a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall return TLB.getTypeSourceInfo(SemaRef.Context, Result); 3198577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 31991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3201a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 320243fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { 3203a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall switch (T.getTypeLocClass()) { 3204a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT) 3205a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT) \ 3206a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall case TypeLoc::CLASS: \ 320743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); 3208a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def" 3209a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3210577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 32119f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin llvm_unreachable("unhandled type loc!"); 3212a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3213577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 32141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3215a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// FIXME: By default, this routine adds type qualifiers only to types 3216a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that can have qualifiers, and silently suppresses those qualifiers 3217a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that are not permitted (e.g., qualifiers on reference or function 3218a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// types). This is the right thing for template instantiation, but 3219a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// probably not for other clients. 32201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 32211eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3222a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, 322343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualifiedTypeLoc T) { 3224a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor Qualifiers Quals = T.getType().getLocalQualifiers(); 3225a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 322643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); 3227a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3228577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 32291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3230a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Silently suppress qualifiers if the result type can't be qualified. 3231a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: this is the right thing for template instantiation, but 3232a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // probably not for other clients. 3233a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result->isFunctionType() || Result->isReferenceType()) 3234a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 32351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3236f85e193739c953358c865005855253af4f68a497John McCall // Suppress Objective-C lifetime qualifiers if they don't make sense for the 3237e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // resulting type. 3238e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor if (Quals.hasObjCLifetime()) { 3239e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor if (!Result->isObjCLifetimeType() && !Result->isDependentType()) 3240e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Quals.removeObjCLifetime(); 32414020caec546d221170072d2388b57d151cb26111Douglas Gregor else if (Result.getObjCLifetime()) { 3242e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // Objective-C ARC: 3243e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // A lifetime qualifier applied to a substituted template parameter 3244e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // overrides the lifetime qualifier from the template argument. 3245e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor if (const SubstTemplateTypeParmType *SubstTypeParam 3246e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor = dyn_cast<SubstTemplateTypeParmType>(Result)) { 3247e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor QualType Replacement = SubstTypeParam->getReplacementType(); 3248e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Qualifiers Qs = Replacement.getQualifiers(); 3249e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Qs.removeObjCLifetime(); 3250e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Replacement 3251e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), 3252e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Qs); 3253e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Result = SemaRef.Context.getSubstTemplateTypeParmType( 3254e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor SubstTypeParam->getReplacedParameter(), 3255e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Replacement); 3256e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor TLB.TypeWasModifiedSafely(Result); 3257e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } else { 32584020caec546d221170072d2388b57d151cb26111Douglas Gregor // Otherwise, complain about the addition of a qualifier to an 32594020caec546d221170072d2388b57d151cb26111Douglas Gregor // already-qualified type. 32604020caec546d221170072d2388b57d151cb26111Douglas Gregor SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange(); 3261b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant) 32624020caec546d221170072d2388b57d151cb26111Douglas Gregor << Result << R; 32634020caec546d221170072d2388b57d151cb26111Douglas Gregor 3264e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Quals.removeObjCLifetime(); 3265e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } 3266e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } 3267e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } 32682865474261a608c7873b87ba4af110d17907896dJohn McCall if (!Quals.empty()) { 32692865474261a608c7873b87ba4af110d17907896dJohn McCall Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); 32702865474261a608c7873b87ba4af110d17907896dJohn McCall TLB.push<QualifiedTypeLoc>(Result); 32712865474261a608c7873b87ba4af110d17907896dJohn McCall // No location information to preserve. 32722865474261a608c7873b87ba4af110d17907896dJohn McCall } 3273a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3274a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3275a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 3276a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 327743fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived> 3278b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTypeLoc 3279b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, 328043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 328143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *UnqualLookup, 3282b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor CXXScopeSpec &SS) { 3283b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor QualType T = TL.getType(); 328443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (getDerived().AlreadyTransformed(T)) 3285b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TL; 3286b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 328743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeLocBuilder TLB; 328843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result; 3289b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 329043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (isa<TemplateSpecializationType>(T)) { 3291b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TemplateSpecializationTypeLoc SpecTL 3292b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = cast<TemplateSpecializationTypeLoc>(TL); 3293b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 329443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template = 3295b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor getDerived().TransformTemplateName(SS, 3296b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL.getTypePtr()->getTemplateName(), 3297b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL.getTemplateNameLoc(), 329843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType, UnqualLookup); 3299b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor if (Template.isNull()) 3300b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TypeLoc(); 3301b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 3302b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, 3303b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Template); 330443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } else if (isa<DependentTemplateSpecializationType>(T)) { 3305b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor DependentTemplateSpecializationTypeLoc SpecTL 3306b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = cast<DependentTemplateSpecializationTypeLoc>(TL); 3307a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 3308b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TemplateName Template 3309b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = getDerived().RebuildTemplateName(SS, 3310b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor *SpecTL.getTypePtr()->getIdentifier(), 3311b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL.getNameLoc(), 3312b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor ObjectType, UnqualLookup); 3313a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (Template.isNull()) 3314b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TypeLoc(); 3315b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 3316b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Result = getDerived().TransformDependentTemplateSpecializationType(TLB, 3317b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL, 3318087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor Template, 3319087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor SS); 332043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } else { 332143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // Nothing special needs to be done for these. 3322b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Result = getDerived().TransformType(TLB, TL); 332343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } 3324b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 3325b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor if (Result.isNull()) 3326b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TypeLoc(); 3327b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 3328b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc(); 332943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall} 333043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 3331c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived> 3332b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTypeSourceInfo * 3333b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, 3334c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType, 3335c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *UnqualLookup, 3336c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor CXXScopeSpec &SS) { 3337c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // FIXME: Painfully copy-paste from the above! 3338c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3339b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor QualType T = TSInfo->getType(); 3340c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (getDerived().AlreadyTransformed(T)) 3341b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TSInfo; 3342c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3343c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TypeLocBuilder TLB; 3344c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType Result; 3345c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3346b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TypeLoc TL = TSInfo->getTypeLoc(); 3347c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (isa<TemplateSpecializationType>(T)) { 3348c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TemplateSpecializationTypeLoc SpecTL 3349c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast<TemplateSpecializationTypeLoc>(TL); 3350c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3351b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TemplateName Template 3352b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = getDerived().TransformTemplateName(SS, 3353fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SpecTL.getTypePtr()->getTemplateName(), 3354fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SpecTL.getTemplateNameLoc(), 3355c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor ObjectType, UnqualLookup); 3356c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (Template.isNull()) 3357b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return 0; 3358c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3359c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, 3360c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Template); 3361c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } else if (isa<DependentTemplateSpecializationType>(T)) { 3362c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor DependentTemplateSpecializationTypeLoc SpecTL 3363c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast<DependentTemplateSpecializationTypeLoc>(TL); 3364c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3365a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateName Template 3366fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = getDerived().RebuildTemplateName(SS, 33677c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor *SpecTL.getTypePtr()->getIdentifier(), 3368fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SpecTL.getNameLoc(), 33697c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor ObjectType, UnqualLookup); 3370a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (Template.isNull()) 3371b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return 0; 3372a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 3373c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Result = getDerived().TransformDependentTemplateSpecializationType(TLB, 3374a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor SpecTL, 3375087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor Template, 3376087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor SS); 3377c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } else { 3378c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // Nothing special needs to be done for these. 3379c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Result = getDerived().TransformType(TLB, TL); 3380c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 3381c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3382c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (Result.isNull()) 3383b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return 0; 3384c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3385b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TLB.getTypeSourceInfo(SemaRef.Context, Result); 3386c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor} 3387c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3388a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate <class TyLoc> static inline 3389a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { 3390a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TyLoc NewT = TLB.push<TyLoc>(T.getType()); 3391a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewT.setNameLoc(T.getNameLoc()); 3392a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return T.getType(); 3393a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 3394a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3395a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3396a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, 339743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall BuiltinTypeLoc T) { 3398ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); 3399ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor NewT.setBuiltinLoc(T.getBuiltinLoc()); 3400ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor if (T.needsExtraLocalData()) 3401ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); 3402ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return T.getType(); 3403577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3404577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 34051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3406a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, 340743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ComplexTypeLoc T) { 3408a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: recurse? 3409a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return TransformTypeSpecType(TLB, T); 3410a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 34111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3412a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3413a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, 341443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall PointerTypeLoc TL) { 3415c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt QualType PointeeType 3416c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt = getDerived().TransformType(TLB, TL.getPointeeLoc()); 341792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (PointeeType.isNull()) 341892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return QualType(); 341992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 342092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor QualType Result = TL.getType(); 3421c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (PointeeType->getAs<ObjCObjectType>()) { 342292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // A dependent pointer type 'T *' has is being transformed such 342392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // that an Objective-C class type is being replaced for 'T'. The 342492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // resulting pointer type is an ObjCObjectPointerType, not a 342592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // PointerType. 3426c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); 3427c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3428c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); 3429c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall NewT.setStarLoc(TL.getStarLoc()); 343092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return Result; 343192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 343243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 343392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (getDerived().AlwaysRebuild() || 343492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor PointeeType != TL.getPointeeLoc().getType()) { 343592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); 343692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (Result.isNull()) 343792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return QualType(); 343892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 3439f85e193739c953358c865005855253af4f68a497John McCall 3440f85e193739c953358c865005855253af4f68a497John McCall // Objective-C ARC can add lifetime qualifiers to the type that we're 3441f85e193739c953358c865005855253af4f68a497John McCall // pointing to. 3442f85e193739c953358c865005855253af4f68a497John McCall TLB.TypeWasModifiedSafely(Result->getPointeeType()); 3443f85e193739c953358c865005855253af4f68a497John McCall 344492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); 344592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor NewT.setSigilLoc(TL.getSigilLoc()); 3446c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return Result; 3447577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3448577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 34491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 34501eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3451a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, 345243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall BlockPointerTypeLoc TL) { 3453db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor QualType PointeeType 3454c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt = getDerived().TransformType(TLB, TL.getPointeeLoc()); 3455c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (PointeeType.isNull()) 3456c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return QualType(); 3457c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3458c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt QualType Result = TL.getType(); 3459c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (getDerived().AlwaysRebuild() || 3460c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt PointeeType != TL.getPointeeLoc().getType()) { 3461c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Result = getDerived().RebuildBlockPointerType(PointeeType, 3462db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor TL.getSigilLoc()); 3463db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor if (Result.isNull()) 3464db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor return QualType(); 3465db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor } 3466db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor 346739968adc66ab02275d2f561e372a20ae454bd4e7Douglas Gregor BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); 3468db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor NewT.setSigilLoc(TL.getSigilLoc()); 3469db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor return Result; 3470a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 34711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 347285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// Transforms a reference type. Note that somewhat paradoxically we 347385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// don't care whether the type itself is an l-value type or an r-value 347485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// type; we only care if the type was *written* as an l-value type 347585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// or an r-value type. 347685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCalltemplate<typename Derived> 347785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType 347885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, 347943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ReferenceTypeLoc TL) { 348085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall const ReferenceType *T = TL.getTypePtr(); 348185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 348285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall // Note that this works with the pointee-as-written. 348385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 348485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (PointeeType.isNull()) 348585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return QualType(); 348685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 348785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType Result = TL.getType(); 348885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (getDerived().AlwaysRebuild() || 348985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall PointeeType != T->getPointeeTypeAsWritten()) { 349085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Result = getDerived().RebuildReferenceType(PointeeType, 349185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->isSpelledAsLValue(), 349285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getSigilLoc()); 349385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (Result.isNull()) 349485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return QualType(); 349585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall } 349685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 3497f85e193739c953358c865005855253af4f68a497John McCall // Objective-C ARC can add lifetime qualifiers to the type that we're 3498f85e193739c953358c865005855253af4f68a497John McCall // referring to. 3499f85e193739c953358c865005855253af4f68a497John McCall TLB.TypeWasModifiedSafely( 3500f85e193739c953358c865005855253af4f68a497John McCall Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); 3501f85e193739c953358c865005855253af4f68a497John McCall 350285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall // r-value references can be rebuilt as l-value references. 350385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall ReferenceTypeLoc NewTL; 350485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (isa<LValueReferenceType>(Result)) 350585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL = TLB.push<LValueReferenceTypeLoc>(Result); 350685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall else 350785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL = TLB.push<RValueReferenceTypeLoc>(Result); 350885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL.setSigilLoc(TL.getSigilLoc()); 350985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 351085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return Result; 351185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall} 351285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 3513a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3514a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3515a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, 351643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall LValueReferenceTypeLoc TL) { 351743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TransformReferenceType(TLB, TL); 3518a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 35191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3520a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3521a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3522a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, 352343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall RValueReferenceTypeLoc TL) { 352443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TransformReferenceType(TLB, TL); 3525577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 35261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3527577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 35281eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3529a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, 353043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall MemberPointerTypeLoc TL) { 3531a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 3532577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (PointeeType.isNull()) 3533577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 35341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3535b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); 3536b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara TypeSourceInfo* NewClsTInfo = 0; 3537b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (OldClsTInfo) { 3538b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsTInfo = getDerived().TransformType(OldClsTInfo); 3539b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (!NewClsTInfo) 3540b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara return QualType(); 3541b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara } 3542b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara 3543b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara const MemberPointerType *T = TL.getTypePtr(); 3544b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara QualType OldClsType = QualType(T->getClass(), 0); 3545b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara QualType NewClsType; 3546b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (NewClsTInfo) 3547b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsType = NewClsTInfo->getType(); 3548b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara else { 3549b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsType = getDerived().TransformType(OldClsType); 3550b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (NewClsType.isNull()) 3551b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara return QualType(); 3552b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara } 35531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3554a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3555a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3556a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall PointeeType != T->getPointeeType() || 3557b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsType != OldClsType) { 3558b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, 355985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getStarLoc()); 3560a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3561a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3562a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3563577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3564a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); 3565a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSigilLoc(TL.getSigilLoc()); 3566b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewTL.setClassTInfo(NewClsTInfo); 3567a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3568a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3569577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3570577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 35711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 35721eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3573a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, 357443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ConstantArrayTypeLoc TL) { 3575f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const ConstantArrayType *T = TL.getTypePtr(); 3576a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3577577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3578577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 35791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3580a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3581a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3582a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3583a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildConstantArrayType(ElementType, 3584a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 3585a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSize(), 358685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->getIndexTypeCVRQualifiers(), 358785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3588a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3589a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3590a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3591c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3592a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); 3593a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3594a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 35951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3596a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Expr *Size = TL.getSizeExpr(); 3597a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Size) { 3598f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 3599a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); 3600a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3601a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(Size); 3602a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3603a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3604577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 36051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3606577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 3607577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformIncompleteArrayType( 3608a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 360943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall IncompleteArrayTypeLoc TL) { 3610f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const IncompleteArrayType *T = TL.getTypePtr(); 3611a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3612577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3613577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3615a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3616a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3617a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3618a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildIncompleteArrayType(ElementType, 3619a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 362085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->getIndexTypeCVRQualifiers(), 362185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3622a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3623a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3624a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3625c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3626a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); 3627a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3628a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 3629a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(0); 3630577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3631a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3632577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 36331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3634577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 3635a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3636a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, 363743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall VariableArrayTypeLoc TL) { 3638f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const VariableArrayType *T = TL.getTypePtr(); 3639a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3640577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3641577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3643670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Array bounds are not potentially evaluated contexts 3644f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 3645670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor 364660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SizeResult 3647a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall = getDerived().TransformExpr(T->getSizeExpr()); 3648a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (SizeResult.isInvalid()) 3649577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Size = SizeResult.take(); 3652a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3653a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3654a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3655a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType() || 3656a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Size != T->getSizeExpr()) { 3657a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildVariableArrayType(ElementType, 3658a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 36599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Size, 3660a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getIndexTypeCVRQualifiers(), 366185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3662a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3663a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3664577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 3665c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3666a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); 3667a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3668a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 3669a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(Size); 36701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3671a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3672577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 36731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3675a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3676a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, 367743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentSizedArrayTypeLoc TL) { 3678f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentSizedArrayType *T = TL.getTypePtr(); 3679a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3680577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3681577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3683670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Array bounds are not potentially evaluated contexts 3684f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 36851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36863b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Prefer the expression from the TypeLoc; the other may have been uniqued. 36873b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Expr *origSize = TL.getSizeExpr(); 36883b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!origSize) origSize = T->getSizeExpr(); 36893b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 36903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExprResult sizeResult 36913b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall = getDerived().TransformExpr(origSize); 36923b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (sizeResult.isInvalid()) 3693577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Expr *size = sizeResult.get(); 3696a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3697a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3698a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3699a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType() || 37003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall size != origSize) { 3701a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildDependentSizedArrayType(ElementType, 3702a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 37033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall size, 3704a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getIndexTypeCVRQualifiers(), 370585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3706a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3707a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3708577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 37091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3710a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // We might have any sort of array type now, but fortunately they 3711a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // all have the same location layout. 3712a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); 3713a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3714a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 37153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall NewTL.setSizeExpr(size); 3716a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3717a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3718577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 37191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3721577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( 3722a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 372343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentSizedExtVectorTypeLoc TL) { 3724f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentSizedExtVectorType *T = TL.getTypePtr(); 3725a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3726a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: ext vector locs should be nested 3727577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3728577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3729577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 37301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3731670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Vector sizes are not potentially evaluated contexts 3732f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 3733670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor 373460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); 3735577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (Size.isInvalid()) 3736577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 37371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3738a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3739a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3740eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall ElementType != T->getElementType() || 3741eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall Size.get() != T->getSizeExpr()) { 3742a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, 37439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Size.take(), 3744577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor T->getAttributeLoc()); 3745a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3746a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3747a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3748a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3749a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Result might be dependent or not. 3750a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (isa<DependentSizedExtVectorType>(Result)) { 3751a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall DependentSizedExtVectorTypeLoc NewTL 3752a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall = TLB.push<DependentSizedExtVectorTypeLoc>(Result); 3753a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 3754a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } else { 3755a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); 3756a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 3757a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3758a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3759a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3760577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 37611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3763a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, 376443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall VectorTypeLoc TL) { 3765f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const VectorType *T = TL.getTypePtr(); 3766577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3767577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3768577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 3769577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3770a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3771a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3772a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 377382287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), 3774e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson T->getVectorKind()); 3775a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3776a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3777a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3778c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3779a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); 3780a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 37811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3782a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3783577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 37841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3786a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, 378743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ExtVectorTypeLoc TL) { 3788f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const VectorType *T = TL.getTypePtr(); 3789577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3790577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3791577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 37921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3793a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3794a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3795a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3796a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildExtVectorType(ElementType, 3797a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getNumElements(), 3798a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /*FIXME*/ SourceLocation()); 3799a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3800a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3801a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3802c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3803a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); 3804a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 38051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3806a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3807577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3808577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 38091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 381021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallParmVarDecl * 38116a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas GregorTreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm, 3812fb44de956f27875def889482b5393475060392afJohn McCall int indexAdjustment, 38136a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 381421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); 38156a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeSourceInfo *NewDI = 0; 38166a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 38176a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { 38186a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor // If we're substituting into a pack expansion type and we know the 38196a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeLoc OldTL = OldDI->getTypeLoc(); 38206a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL); 38216a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 38226a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeLocBuilder TLB; 38236a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeLoc NewTL = OldDI->getTypeLoc(); 38246a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TLB.reserve(NewTL.getFullDataSize()); 38256a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 38266a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor QualType Result = getDerived().TransformType(TLB, 38276a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OldExpansionTL.getPatternLoc()); 38286a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor if (Result.isNull()) 38296a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor return 0; 38306a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 38316a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor Result = RebuildPackExpansionType(Result, 38326a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OldExpansionTL.getPatternLoc().getSourceRange(), 38336a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OldExpansionTL.getEllipsisLoc(), 38346a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NumExpansions); 38356a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor if (Result.isNull()) 38366a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor return 0; 38376a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 38386a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor PackExpansionTypeLoc NewExpansionTL 38396a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = TLB.push<PackExpansionTypeLoc>(Result); 38406a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); 38416a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); 38426a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor } else 38436a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NewDI = getDerived().TransformType(OldDI); 384421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall if (!NewDI) 384521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return 0; 384621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 3847fb44de956f27875def889482b5393475060392afJohn McCall if (NewDI == OldDI && indexAdjustment == 0) 384821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return OldParm; 3849fb44de956f27875def889482b5393475060392afJohn McCall 3850fb44de956f27875def889482b5393475060392afJohn McCall ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, 3851fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getDeclContext(), 3852fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getInnerLocStart(), 3853fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getLocation(), 3854fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getIdentifier(), 3855fb44de956f27875def889482b5393475060392afJohn McCall NewDI->getType(), 3856fb44de956f27875def889482b5393475060392afJohn McCall NewDI, 3857fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getStorageClass(), 3858fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getStorageClassAsWritten(), 3859fb44de956f27875def889482b5393475060392afJohn McCall /* DefArg */ NULL); 3860fb44de956f27875def889482b5393475060392afJohn McCall newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), 3861fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getFunctionScopeIndex() + indexAdjustment); 3862fb44de956f27875def889482b5393475060392afJohn McCall return newParm; 386321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall} 386421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 386521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived> 386621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallbool TreeTransform<Derived>:: 3867a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TransformFunctionTypeParams(SourceLocation Loc, 3868a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParmVarDecl **Params, unsigned NumParams, 3869a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor const QualType *ParamTypes, 3870686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<QualType> &OutParamTypes, 3871686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<ParmVarDecl*> *PVars) { 3872fb44de956f27875def889482b5393475060392afJohn McCall int indexAdjustment = 0; 3873fb44de956f27875def889482b5393475060392afJohn McCall 3874a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor for (unsigned i = 0; i != NumParams; ++i) { 3875a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (ParmVarDecl *OldParm = Params[i]) { 3876fb44de956f27875def889482b5393475060392afJohn McCall assert(OldParm->getFunctionScopeIndex() == i); 3877fb44de956f27875def889482b5393475060392afJohn McCall 38786a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor llvm::Optional<unsigned> NumExpansions; 3879406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor ParmVarDecl *NewParm = 0; 3880603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (OldParm->isParameterPack()) { 3881603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We have a function parameter pack that may need to be expanded. 3882686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<UnexpandedParameterPack, 2> Unexpanded; 3883603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3884603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Find the parameter packs that could be expanded. 3885c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); 3886c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL); 3887c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor TypeLoc Pattern = ExpansionTL.getPatternLoc(); 3888c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); 3889406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); 3890406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor 3891603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Determine whether we should expand the parameter packs. 3892603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor bool ShouldExpand = false; 3893d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 38946a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor llvm::Optional<unsigned> OrigNumExpansions 38956a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = ExpansionTL.getTypePtr()->getNumExpansions(); 38966a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NumExpansions = OrigNumExpansions; 3897c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), 3898c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor Pattern.getSourceRange(), 3899a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 3900d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ShouldExpand, 3901d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor RetainExpansion, 3902d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) { 3903603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 3904603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3905603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3906603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (ShouldExpand) { 3907603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Expand the function parameter pack into multiple, separate 3908603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // parameters. 390912c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor getDerived().ExpandingFunctionParameterPack(OldParm); 3910cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 3911603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 3912603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor ParmVarDecl *NewParm 39136a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = getDerived().TransformFunctionTypeParam(OldParm, 3914fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment++, 39156a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OrigNumExpansions); 3916603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (!NewParm) 3917603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 3918603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3919a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewParm->getType()); 3920a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 3921a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(NewParm); 3922603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3923d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 3924d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 3925d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor // forgetting the partially-substituted parameter pack. 3926d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (RetainExpansion) { 3927d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 3928d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ParmVarDecl *NewParm 39296a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = getDerived().TransformFunctionTypeParam(OldParm, 3930fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment++, 39316a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OrigNumExpansions); 3932d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (!NewParm) 3933d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor return true; 3934d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 3935d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor OutParamTypes.push_back(NewParm->getType()); 3936d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (PVars) 3937d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor PVars->push_back(NewParm); 3938d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor } 3939d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 3940fb44de956f27875def889482b5393475060392afJohn McCall // The next parameter should have the same adjustment as the 3941fb44de956f27875def889482b5393475060392afJohn McCall // last thing we pushed, but we post-incremented indexAdjustment 3942fb44de956f27875def889482b5393475060392afJohn McCall // on every push. Also, if we push nothing, the adjustment should 3943fb44de956f27875def889482b5393475060392afJohn McCall // go down by one. 3944fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment--; 3945fb44de956f27875def889482b5393475060392afJohn McCall 3946603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We're done with the pack expansion. 3947603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor continue; 3948603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3949603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3950603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We'll substitute the parameter now without expanding the pack 3951603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // expansion. 3952406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 3953406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewParm = getDerived().TransformFunctionTypeParam(OldParm, 3954fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment, 3955406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NumExpansions); 3956406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor } else { 3957406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewParm = getDerived().TransformFunctionTypeParam(OldParm, 3958fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment, 3959406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor llvm::Optional<unsigned>()); 3960603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3961406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor 396221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall if (!NewParm) 396321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return true; 3964603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3965a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewParm->getType()); 3966a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 3967a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(NewParm); 3968603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor continue; 3969603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3970a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3971a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Deal with the possibility that we don't have a parameter 3972a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // declaration for this parameter. 3973a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor QualType OldType = ParamTypes[i]; 3974603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor bool IsPackExpansion = false; 3975cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions; 3976406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor QualType NewType; 3977603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (const PackExpansionType *Expansion 3978603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor = dyn_cast<PackExpansionType>(OldType)) { 3979603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We have a function parameter pack that may need to be expanded. 3980603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor QualType Pattern = Expansion->getPattern(); 3981686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<UnexpandedParameterPack, 2> Unexpanded; 3982603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 3983603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3984603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Determine whether we should expand the parameter packs. 3985603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor bool ShouldExpand = false; 3986d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 3987a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), 3988a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 3989d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ShouldExpand, 3990d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor RetainExpansion, 3991d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) { 399221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return true; 3993603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3994603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3995603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (ShouldExpand) { 3996603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Expand the function parameter pack into multiple, separate 3997603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // parameters. 3998cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 3999603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 4000603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor QualType NewType = getDerived().TransformType(Pattern); 4001603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (NewType.isNull()) 4002603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 4003603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4004a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewType); 4005a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 4006a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(0); 4007603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4008603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4009603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We're done with the pack expansion. 4010603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor continue; 4011603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4012603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 40133cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 40143cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // forgetting the partially-substituted parameter pack. 40153cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (RetainExpansion) { 40163cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 40173cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor QualType NewType = getDerived().TransformType(Pattern); 40183cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (NewType.isNull()) 40193cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor return true; 40203cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 40213cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor OutParamTypes.push_back(NewType); 40223cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (PVars) 40233cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor PVars->push_back(0); 40243cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor } 4025d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 4026603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We'll substitute the parameter now without expanding the pack 4027603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // expansion. 4028603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor OldType = Expansion->getPattern(); 4029603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor IsPackExpansion = true; 4030406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 4031406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewType = getDerived().TransformType(OldType); 4032406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor } else { 4033406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewType = getDerived().TransformType(OldType); 4034a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4035603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4036603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (NewType.isNull()) 4037603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 40381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4039603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (IsPackExpansion) 4040cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NewType = getSema().Context.getPackExpansionType(NewType, 4041cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions); 4042603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4043a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewType); 4044a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 4045a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(0); 4046577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 40471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4048fb44de956f27875def889482b5393475060392afJohn McCall#ifndef NDEBUG 4049fb44de956f27875def889482b5393475060392afJohn McCall if (PVars) { 4050fb44de956f27875def889482b5393475060392afJohn McCall for (unsigned i = 0, e = PVars->size(); i != e; ++i) 4051fb44de956f27875def889482b5393475060392afJohn McCall if (ParmVarDecl *parm = (*PVars)[i]) 4052fb44de956f27875def889482b5393475060392afJohn McCall assert(parm->getFunctionScopeIndex() == i); 4053603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4054fb44de956f27875def889482b5393475060392afJohn McCall#endif 4055fb44de956f27875def889482b5393475060392afJohn McCall 4056fb44de956f27875def889482b5393475060392afJohn McCall return false; 4057fb44de956f27875def889482b5393475060392afJohn McCall} 405821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 405921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived> 406021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallQualType 406121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallTreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, 406243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FunctionProtoTypeLoc TL) { 40637e010a04fef171049291d8cb3047f118566da090Douglas Gregor // Transform the parameters and return type. 40647e010a04fef171049291d8cb3047f118566da090Douglas Gregor // 40657e010a04fef171049291d8cb3047f118566da090Douglas Gregor // We instantiate in source order, with the return type first followed by 40667e010a04fef171049291d8cb3047f118566da090Douglas Gregor // the parameters, because users tend to expect this (even if they shouldn't 40677e010a04fef171049291d8cb3047f118566da090Douglas Gregor // rely on it!). 40687e010a04fef171049291d8cb3047f118566da090Douglas Gregor // 4069dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // When the function has a trailing return type, we instantiate the 4070dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // parameters before the return type, since the return type can then refer 4071dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // to the parameters themselves (via decltype, sizeof, etc.). 4072dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // 4073686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<QualType, 4> ParamTypes; 4074686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<ParmVarDecl*, 4> ParamDecls; 4075f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const FunctionProtoType *T = TL.getTypePtr(); 40767e010a04fef171049291d8cb3047f118566da090Douglas Gregor 4077dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor QualType ResultType; 4078dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 4079dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (TL.getTrailingReturn()) { 4080a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), 4081a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getParmArray(), 4082a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getNumArgs(), 4083a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getTypePtr()->arg_type_begin(), 4084a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParamTypes, &ParamDecls)) 4085dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 4086dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 4087dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 4088dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (ResultType.isNull()) 4089dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 4090dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor } 4091dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor else { 4092dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 4093dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (ResultType.isNull()) 4094dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 4095dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 4096a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), 4097a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getParmArray(), 4098a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getNumArgs(), 4099a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getTypePtr()->arg_type_begin(), 4100a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParamTypes, &ParamDecls)) 4101dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 4102dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor } 4103dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 4104a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4105a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4106a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ResultType != T->getResultType() || 4107bd5f9f708aa31920d3bd73aa10fcb5de424c657aDouglas Gregor T->getNumArgs() != ParamTypes.size() || 4108a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { 4109a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildFunctionProtoType(ResultType, 4110a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ParamTypes.data(), 4111a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ParamTypes.size(), 4112a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->isVariadic(), 4113fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman T->getTypeQuals(), 4114c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor T->getRefQualifier(), 4115fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman T->getExtInfo()); 4116a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4117a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4118a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 41191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4120a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); 4121796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); 4122796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); 4123dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor NewTL.setTrailingReturn(TL.getTrailingReturn()); 4124a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) 4125a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setArg(i, ParamDecls[i]); 4126a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4127a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4128577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 41291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4130577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4131577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformFunctionNoProtoType( 4132a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 413343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FunctionNoProtoTypeLoc TL) { 4134f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const FunctionNoProtoType *T = TL.getTypePtr(); 4135a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 4136a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (ResultType.isNull()) 4137a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4138a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4139a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4140a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4141a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ResultType != T->getResultType()) 4142a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildFunctionNoProtoType(ResultType); 4143a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4144a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); 4145796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); 4146796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); 4147dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor NewTL.setTrailingReturn(false); 4148a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4149a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4150577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 41511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4152ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> QualType 4153ed97649e9574b9d854fa4d6109c9333ae0993554John McCallTreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, 415443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall UnresolvedUsingTypeLoc TL) { 4155f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const UnresolvedUsingType *T = TL.getTypePtr(); 41567c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); 4157ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (!D) 4158ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return QualType(); 4159ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4160ed97649e9574b9d854fa4d6109c9333ae0993554John McCall QualType Result = TL.getType(); 4161ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (getDerived().AlwaysRebuild() || D != T->getDecl()) { 4162ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Result = getDerived().RebuildUnresolvedUsingType(D); 4163ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (Result.isNull()) 4164ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return QualType(); 4165ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 4166ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4167ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // We might get an arbitrary type spec type back. We should at 4168ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // least always get a type spec type, though. 4169ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); 4170ed97649e9574b9d854fa4d6109c9333ae0993554John McCall NewTL.setNameLoc(TL.getNameLoc()); 4171ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4172ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return Result; 4173ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 4174ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4175577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4176a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, 417743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypedefTypeLoc TL) { 4178f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const TypedefType *T = TL.getTypePtr(); 4179162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TypedefNameDecl *Typedef 4180162e1c1b487352434552147967c3dd296ebee2f7Richard Smith = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), 4181162e1c1b487352434552147967c3dd296ebee2f7Richard Smith T->getDecl())); 4182577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Typedef) 4183577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 41841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4185a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4186a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4187a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Typedef != T->getDecl()) { 4188a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildTypedefType(Typedef); 4189a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4190a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4191a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4192a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4193a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); 4194a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 41951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4196a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4197577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 41981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4199577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4200a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, 420143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeOfExprTypeLoc TL) { 4202670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // typeof expressions are not potentially evaluated contexts 4203f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 42041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 420560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); 4206577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (E.isInvalid()) 4207577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 4208577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 4209a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4210a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4211cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall E.get() != TL.getUnderlyingExpr()) { 42122a984cad5ac3fdceeff2bd99daa7b90979313475John McCall Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); 4213a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4214a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4215577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 4216a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall else E.take(); 42171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4218a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); 4219cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setTypeofLoc(TL.getTypeofLoc()); 4220cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setLParenLoc(TL.getLParenLoc()); 4221cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setRParenLoc(TL.getRParenLoc()); 4222a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4223a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4224577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 42251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4227a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, 422843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeOfTypeLoc TL) { 4229cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); 4230cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); 4231cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall if (!New_Under_TI) 4232577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 42331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4234a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4235cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { 4236cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); 4237a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4238a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4239a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 42401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4241a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); 4242cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setTypeofLoc(TL.getTypeofLoc()); 4243cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setLParenLoc(TL.getLParenLoc()); 4244cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setRParenLoc(TL.getRParenLoc()); 4245cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setUnderlyingTInfo(New_Under_TI); 4246a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4247a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4248577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 42491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4251a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, 425243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DecltypeTypeLoc TL) { 4253f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DecltypeType *T = TL.getTypePtr(); 4254a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4255670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // decltype expressions are not potentially evaluated contexts 4256f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 42571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 425860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); 4259577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (E.isInvalid()) 4260577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 42611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4262a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4263a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4264a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall E.get() != T->getUnderlyingExpr()) { 42652a984cad5ac3fdceeff2bd99daa7b90979313475John McCall Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); 4266a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4267a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4268577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 4269a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall else E.take(); 4270a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4271a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); 4272a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 42731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4274a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4275577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 4276577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 4277577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4278ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType TreeTransform<Derived>::TransformUnaryTransformType( 4279ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt TypeLocBuilder &TLB, 4280ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformTypeLoc TL) { 4281ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType Result = TL.getType(); 4282ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt if (Result->isDependentType()) { 4283ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt const UnaryTransformType *T = TL.getTypePtr(); 4284ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType NewBase = 4285ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); 4286ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Result = getDerived().RebuildUnaryTransformType(NewBase, 4287ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt T->getUTTKind(), 4288ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt TL.getKWLoc()); 4289ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt if (Result.isNull()) 4290ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return QualType(); 4291ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt } 4292ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 4293ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); 4294ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt NewTL.setKWLoc(TL.getKWLoc()); 4295ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt NewTL.setParensRange(TL.getParensRange()); 4296ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); 4297ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return Result; 4298ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt} 4299ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 4300ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunttemplate<typename Derived> 430134b41d939a1328f484511c6002ba2456db879a29Richard SmithQualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, 430234b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoTypeLoc TL) { 430334b41d939a1328f484511c6002ba2456db879a29Richard Smith const AutoType *T = TL.getTypePtr(); 430434b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType OldDeduced = T->getDeducedType(); 430534b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType NewDeduced; 430634b41d939a1328f484511c6002ba2456db879a29Richard Smith if (!OldDeduced.isNull()) { 430734b41d939a1328f484511c6002ba2456db879a29Richard Smith NewDeduced = getDerived().TransformType(OldDeduced); 430834b41d939a1328f484511c6002ba2456db879a29Richard Smith if (NewDeduced.isNull()) 430934b41d939a1328f484511c6002ba2456db879a29Richard Smith return QualType(); 431034b41d939a1328f484511c6002ba2456db879a29Richard Smith } 431134b41d939a1328f484511c6002ba2456db879a29Richard Smith 431234b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType Result = TL.getType(); 431334b41d939a1328f484511c6002ba2456db879a29Richard Smith if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) { 431434b41d939a1328f484511c6002ba2456db879a29Richard Smith Result = getDerived().RebuildAutoType(NewDeduced); 431534b41d939a1328f484511c6002ba2456db879a29Richard Smith if (Result.isNull()) 431634b41d939a1328f484511c6002ba2456db879a29Richard Smith return QualType(); 431734b41d939a1328f484511c6002ba2456db879a29Richard Smith } 431834b41d939a1328f484511c6002ba2456db879a29Richard Smith 431934b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); 432034b41d939a1328f484511c6002ba2456db879a29Richard Smith NewTL.setNameLoc(TL.getNameLoc()); 432134b41d939a1328f484511c6002ba2456db879a29Richard Smith 432234b41d939a1328f484511c6002ba2456db879a29Richard Smith return Result; 432334b41d939a1328f484511c6002ba2456db879a29Richard Smith} 432434b41d939a1328f484511c6002ba2456db879a29Richard Smith 432534b41d939a1328f484511c6002ba2456db879a29Richard Smithtemplate<typename Derived> 4326a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, 432743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall RecordTypeLoc TL) { 4328f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const RecordType *T = TL.getTypePtr(); 4329577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor RecordDecl *Record 43307c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), 43317c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor T->getDecl())); 4332577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Record) 4333577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 43341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4335a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4336a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4337a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Record != T->getDecl()) { 4338a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildRecordType(Record); 4339a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4340a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4341a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 43421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4343a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); 4344a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 4345a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4346a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4347577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 43481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 43491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4350a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, 435143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall EnumTypeLoc TL) { 4352f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const EnumType *T = TL.getTypePtr(); 4353577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor EnumDecl *Enum 43547c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), 43557c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor T->getDecl())); 4356577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Enum) 4357577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 43581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4359a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4360a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4361a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Enum != T->getDecl()) { 4362a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildEnumType(Enum); 4363a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4364a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4365a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4366a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4367a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); 4368a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 43691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4370a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4371577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 43727da2431c23ef1ee8acb114e39692246e1801afc2John McCall 43733cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCalltemplate<typename Derived> 43743cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallQualType TreeTransform<Derived>::TransformInjectedClassNameType( 43753cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TypeLocBuilder &TLB, 437643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall InjectedClassNameTypeLoc TL) { 43773cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall Decl *D = getDerived().TransformDecl(TL.getNameLoc(), 43783cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TL.getTypePtr()->getDecl()); 43793cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall if (!D) return QualType(); 43803cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 43813cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); 43823cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); 43833cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return T; 43843cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 43853cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 4386577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4387577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateTypeParmType( 4388a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 438943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateTypeParmTypeLoc TL) { 4390a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return TransformTypeSpecType(TLB, TL); 4391577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 4392577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 43931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 439449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( 4395a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 439643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall SubstTemplateTypeParmTypeLoc TL) { 43970b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor const SubstTemplateTypeParmType *T = TL.getTypePtr(); 43980b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor 43990b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // Substitute into the replacement type, which itself might involve something 44000b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // that needs to be transformed. This only tends to occur with default 44010b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // template arguments of template template parameters. 44020b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); 44030b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor QualType Replacement = getDerived().TransformType(T->getReplacementType()); 44040b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor if (Replacement.isNull()) 44050b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor return QualType(); 44060b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor 44070b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // Always canonicalize the replacement type. 44080b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor Replacement = SemaRef.Context.getCanonicalType(Replacement); 44090b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor QualType Result 44100b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), 44110b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor Replacement); 44120b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor 44130b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // Propagate type-source information. 44140b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor SubstTemplateTypeParmTypeLoc NewTL 44150b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); 44160b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor NewTL.setNameLoc(TL.getNameLoc()); 44170b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor return Result; 44180b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor 441949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall} 442049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 442149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCalltemplate<typename Derived> 4422c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( 4423c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor TypeLocBuilder &TLB, 4424c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackTypeLoc TL) { 4425c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return TransformTypeSpecType(TLB, TL); 4426c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 4427c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 4428c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregortemplate<typename Derived> 4429833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallQualType TreeTransform<Derived>::TransformTemplateSpecializationType( 443043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeLocBuilder &TLB, 443143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateSpecializationTypeLoc TL) { 443243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall const TemplateSpecializationType *T = TL.getTypePtr(); 4433828bff2079b6a91ecd7ed5b842c59527d7682789John McCall 44341d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor // The nested-name-specifier never matters in a TemplateSpecializationType, 44351d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor // because we can't have a dependent nested-name-specifier anyway. 44361d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor CXXScopeSpec SS; 443743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template 44381d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor = getDerived().TransformTemplateName(SS, T->getTemplateName(), 44391d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor TL.getTemplateNameLoc()); 444043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (Template.isNull()) 444143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return QualType(); 4442833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 444343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); 4444dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor} 444543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 4446b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmantemplate<typename Derived> 4447b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli FriedmanQualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, 4448b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicTypeLoc TL) { 4449b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); 4450b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (ValueType.isNull()) 4451b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return QualType(); 4452b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4453b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType Result = TL.getType(); 4454b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (getDerived().AlwaysRebuild() || 4455b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman ValueType != TL.getValueLoc().getType()) { 4456b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); 4457b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (Result.isNull()) 4458b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return QualType(); 4459b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 4460b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4461b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); 4462b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman NewTL.setKWLoc(TL.getKWLoc()); 4463b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman NewTL.setLParenLoc(TL.getLParenLoc()); 4464b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman NewTL.setRParenLoc(TL.getRParenLoc()); 4465b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4466b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return Result; 4467b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman} 4468b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 44697ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregornamespace { 44707ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \brief Simple iterator that traverses the template arguments in a 44717ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// container that provides a \c getArgLoc() member function. 44727ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// 44737ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// This iterator is intended to be used with the iterator form of 44747ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \c TreeTransform<Derived>::TransformTemplateArguments(). 44757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor template<typename ArgLocContainer> 44767ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class TemplateArgumentLocContainerIterator { 44777ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgLocContainer *Container; 44787ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor unsigned Index; 44797ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 44807ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 44817ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc value_type; 44827ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc reference; 44837ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef int difference_type; 44847ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef std::input_iterator_tag iterator_category; 44857ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 44867ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class pointer { 44877ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Arg; 44887ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 44897ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 44907ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } 44917ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 44927ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLoc *operator->() const { 44937ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return &Arg; 44947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 44957ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 44967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 44977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 44987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator() {} 44997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator(ArgLocContainer &Container, 45017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor unsigned Index) 45027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor : Container(&Container), Index(Index) { } 45037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator &operator++() { 45057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++Index; 45067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return *this; 45077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 45087ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45097ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator operator++(int) { 45107ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator Old(*this); 45117ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++(*this); 45127ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Old; 45137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 45147ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45157ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc operator*() const { 45167ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Container->getArgLoc(Index); 45177ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 45187ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45197ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor pointer operator->() const { 45207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return pointer(Container->getArgLoc(Index)); 45217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 45227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator==(const TemplateArgumentLocContainerIterator &X, 4524f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor const TemplateArgumentLocContainerIterator &Y) { 45257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Container == Y.Container && X.Index == Y.Index; 45267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 45277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator!=(const TemplateArgumentLocContainerIterator &X, 4529f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor const TemplateArgumentLocContainerIterator &Y) { 45307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return !(X == Y); 45317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 45327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 45337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor} 45347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 453643fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate <typename Derived> 4537577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateSpecializationType( 4538833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TypeLocBuilder &TLB, 4539833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateSpecializationTypeLoc TL, 454043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template) { 4541d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo NewTemplateArgs; 4542d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 4543d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 45447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> 45457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgIterator; 45467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 45477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgIterator(TL, TL.getNumArgs()), 45487ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor NewTemplateArgs)) 45497f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return QualType(); 45501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4551833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: maybe don't rebuild if all the template arguments are the same. 4552833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 4553833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall QualType Result = 4554833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall getDerived().RebuildTemplateSpecializationType(Template, 4555833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TL.getTemplateNameLoc(), 4556d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs); 45571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4558833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!Result.isNull()) { 45593e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // Specializations of template template parameters are represented as 45603e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // TemplateSpecializationTypes, and substitution of type alias templates 45613e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // within a dependent context can transform them into 45623e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // DependentTemplateSpecializationTypes. 45633e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (isa<DependentTemplateSpecializationType>(Result)) { 45643e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith DependentTemplateSpecializationTypeLoc NewTL 45653e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 45663e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setKeywordLoc(TL.getTemplateNameLoc()); 45673e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setQualifierLoc(NestedNameSpecifierLoc()); 45683e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setNameLoc(TL.getTemplateNameLoc()); 45693e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setLAngleLoc(TL.getLAngleLoc()); 45703e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setRAngleLoc(TL.getRAngleLoc()); 45713e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 45723e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 45733e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return Result; 45743e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 45753e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 4576833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateSpecializationTypeLoc NewTL 4577833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall = TLB.push<TemplateSpecializationTypeLoc>(Result); 4578833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 4579833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setLAngleLoc(TL.getLAngleLoc()); 4580833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setRAngleLoc(TL.getRAngleLoc()); 4581833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 4582833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 4583833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 45841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4585833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return Result; 4586577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 45871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4588a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregortemplate <typename Derived> 4589a88f09f34e86125ee4e6949a757aaed314012664Douglas GregorQualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( 4590a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TypeLocBuilder &TLB, 4591a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc TL, 4592087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor TemplateName Template, 4593087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor CXXScopeSpec &SS) { 4594a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateArgumentListInfo NewTemplateArgs; 4595a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 4596a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 4597a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor typedef TemplateArgumentLocContainerIterator< 4598a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc> ArgIterator; 4599a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 4600a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor ArgIterator(TL, TL.getNumArgs()), 4601a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs)) 4602a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return QualType(); 4603a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4604a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor // FIXME: maybe don't rebuild if all the template arguments are the same. 4605a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4606a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { 4607a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor QualType Result 4608a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = getSema().Context.getDependentTemplateSpecializationType( 4609a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TL.getTypePtr()->getKeyword(), 4610a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DTN->getQualifier(), 4611a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DTN->getIdentifier(), 4612a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs); 4613a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4614a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc NewTL 4615a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 4616a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setKeywordLoc(TL.getKeywordLoc()); 461794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 461894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); 4619a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setNameLoc(TL.getNameLoc()); 4620a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setLAngleLoc(TL.getLAngleLoc()); 4621a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setRAngleLoc(TL.getRAngleLoc()); 4622a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 4623a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 4624a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return Result; 4625a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor } 4626a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4627a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor QualType Result 4628a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = getDerived().RebuildTemplateSpecializationType(Template, 4629a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TL.getNameLoc(), 4630a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs); 4631a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4632a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (!Result.isNull()) { 4633a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor /// FIXME: Wrap this in an elaborated-type-specifier? 4634a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateSpecializationTypeLoc NewTL 4635a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = TLB.push<TemplateSpecializationTypeLoc>(Result); 4636a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setTemplateNameLoc(TL.getNameLoc()); 4637a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setLAngleLoc(TL.getLAngleLoc()); 4638a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setRAngleLoc(TL.getRAngleLoc()); 4639a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 4640a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 4641a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor } 4642a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4643a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return Result; 4644a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor} 4645a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 46461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4647a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 4648465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, 464943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ElaboratedTypeLoc TL) { 4650f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const ElaboratedType *T = TL.getTypePtr(); 4651465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 46529e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 4653465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara // NOTE: the qualifier in an ElaboratedType is optional. 46549e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor if (TL.getQualifierLoc()) { 46559e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc 46569e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 46579e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor if (!QualifierLoc) 4658465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return QualType(); 4659465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 46601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 466143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); 466243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (NamedT.isNull()) 466343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return QualType(); 4664a63db84b164d3f1c987a3ea6251e3092db4f317bDaniel Dunbar 46653e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // C++0x [dcl.type.elab]p2: 46663e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // If the identifier resolves to a typedef-name or the simple-template-id 46673e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // resolves to an alias template specialization, the 46683e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // elaborated-type-specifier is ill-formed. 46691804174e1591bf59118f317775b48edd0382c3f0Richard Smith if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { 46701804174e1591bf59118f317775b48edd0382c3f0Richard Smith if (const TemplateSpecializationType *TST = 46711804174e1591bf59118f317775b48edd0382c3f0Richard Smith NamedT->getAs<TemplateSpecializationType>()) { 46721804174e1591bf59118f317775b48edd0382c3f0Richard Smith TemplateName Template = TST->getTemplateName(); 46731804174e1591bf59118f317775b48edd0382c3f0Richard Smith if (TypeAliasTemplateDecl *TAT = 46741804174e1591bf59118f317775b48edd0382c3f0Richard Smith dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) { 46751804174e1591bf59118f317775b48edd0382c3f0Richard Smith SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), 46761804174e1591bf59118f317775b48edd0382c3f0Richard Smith diag::err_tag_reference_non_tag) << 4; 46771804174e1591bf59118f317775b48edd0382c3f0Richard Smith SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); 46781804174e1591bf59118f317775b48edd0382c3f0Richard Smith } 46793e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 46803e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 46813e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 4682a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4683a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 46849e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc != TL.getQualifierLoc() || 4685e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NamedT != T->getNamedType()) { 468621e413fe6305a198564d436ac515497716c47844John McCall Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(), 46879e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor T->getKeyword(), 46889e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc, NamedT); 4689a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4690a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4691a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4692577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 4693465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 4694e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setKeywordLoc(TL.getKeywordLoc()); 46959e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 4696a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4697577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 46981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 46991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 47009d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallQualType TreeTransform<Derived>::TransformAttributedType( 47019d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall TypeLocBuilder &TLB, 47029d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeLoc TL) { 47039d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall const AttributedType *oldType = TL.getTypePtr(); 47049d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); 47059d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (modifiedType.isNull()) 47069d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return QualType(); 47079d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 47089d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType result = TL.getType(); 47099d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 47109d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // FIXME: dependent operand expressions? 47119d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (getDerived().AlwaysRebuild() || 47129d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall modifiedType != oldType->getModifiedType()) { 47139d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // TODO: this is really lame; we should really be rebuilding the 47149d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // equivalent type from first principles. 47159d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType equivalentType 47169d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall = getDerived().TransformType(oldType->getEquivalentType()); 47179d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (equivalentType.isNull()) 47189d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return QualType(); 47199d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), 47209d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall modifiedType, 47219d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall equivalentType); 47229d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 47239d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 47249d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); 47259d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrNameLoc(TL.getAttrNameLoc()); 47269d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (TL.hasAttrOperand()) 47279d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); 47289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (TL.hasAttrExprOperand()) 47299d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrExprOperand(TL.getAttrExprOperand()); 47309d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall else if (TL.hasAttrEnumOperand()) 47319d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); 47329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 47339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return result; 47349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall} 47359d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 47369d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCalltemplate<typename Derived> 4737075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType 4738075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraTreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, 4739075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenTypeLoc TL) { 4740075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); 4741075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (Inner.isNull()) 4742075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(); 4743075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 4744075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Result = TL.getType(); 4745075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (getDerived().AlwaysRebuild() || 4746075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Inner != TL.getInnerLoc().getType()) { 4747075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Result = getDerived().RebuildParenType(Inner); 4748075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (Result.isNull()) 4749075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(); 4750075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 4751075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 4752075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); 4753075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara NewTL.setLParenLoc(TL.getLParenLoc()); 4754075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara NewTL.setRParenLoc(TL.getRParenLoc()); 4755075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return Result; 4756075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 4757075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 4758075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaratemplate<typename Derived> 47594714c12a1ab759156b78be8f109ea4c12213af57Douglas GregorQualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, 476043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentNameTypeLoc TL) { 4761f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentNameType *T = TL.getTypePtr(); 4762833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 47632494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor NestedNameSpecifierLoc QualifierLoc 47642494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 47652494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor if (!QualifierLoc) 4766577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 47671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 476833500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Result 47692494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor = getDerived().RebuildDependentNameType(T->getKeyword(), 477033500955d731c73717af52088b7fc0e7a85681e7John McCall TL.getKeywordLoc(), 47712494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor QualifierLoc, 47722494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor T->getIdentifier(), 477333500955d731c73717af52088b7fc0e7a85681e7John McCall TL.getNameLoc()); 4774a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4775a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4776a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4777e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { 4778e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara QualType NamedT = ElabT->getNamedType(); 477933500955d731c73717af52088b7fc0e7a85681e7John McCall TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); 478033500955d731c73717af52088b7fc0e7a85681e7John McCall 4781e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 4782e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setKeywordLoc(TL.getKeywordLoc()); 47839e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 478433500955d731c73717af52088b7fc0e7a85681e7John McCall } else { 4785e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); 4786e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setKeywordLoc(TL.getKeywordLoc()); 47872494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 4788e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setNameLoc(TL.getNameLoc()); 4789e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 4790a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4791577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 47921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4793577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 479433500955d731c73717af52088b7fc0e7a85681e7John McCallQualType TreeTransform<Derived>:: 479533500955d731c73717af52088b7fc0e7a85681e7John McCall TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 479643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentTemplateSpecializationTypeLoc TL) { 479794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 479894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (TL.getQualifierLoc()) { 479994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualifierLoc 480094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 480194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (!QualifierLoc) 4802a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return QualType(); 4803a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor } 4804a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 480543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived() 480694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); 480743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall} 480843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 480943fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived> 481043fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>:: 481194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas GregorTransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 481294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor DependentTemplateSpecializationTypeLoc TL, 481394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NestedNameSpecifierLoc QualifierLoc) { 481494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor const DependentTemplateSpecializationType *T = TL.getTypePtr(); 481594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 481694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor TemplateArgumentListInfo NewTemplateArgs; 481794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 481894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 481994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 482094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor typedef TemplateArgumentLocContainerIterator< 482194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor DependentTemplateSpecializationTypeLoc> ArgIterator; 482294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 482394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor ArgIterator(TL, TL.getNumArgs()), 482494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs)) 482594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return QualType(); 482694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 482794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualType Result 482894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), 482994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualifierLoc, 483094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor T->getIdentifier(), 483194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor TL.getNameLoc(), 483294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs); 483394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (Result.isNull()) 483494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return QualType(); 483594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 483694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { 483794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualType NamedT = ElabT->getNamedType(); 483894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 483994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Copy information relevant to the template specialization. 484094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor TemplateSpecializationTypeLoc NamedTL 48410a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor = TLB.push<TemplateSpecializationTypeLoc>(NamedT); 4842a35d5d7700b519d713039afd31477e95e2da7aa7Chandler Carruth NamedTL.setTemplateNameLoc(TL.getNameLoc()); 484394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NamedTL.setLAngleLoc(TL.getLAngleLoc()); 484494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NamedTL.setRAngleLoc(TL.getRAngleLoc()); 4845944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 48460a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 484794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 484894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Copy information relevant to the elaborated type. 484994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 485094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTL.setKeywordLoc(TL.getKeywordLoc()); 485194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 48520a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor } else if (isa<DependentTemplateSpecializationType>(Result)) { 48530a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor DependentTemplateSpecializationTypeLoc SpecTL 48540a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 4855944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor SpecTL.setKeywordLoc(TL.getKeywordLoc()); 48560a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setQualifierLoc(QualifierLoc); 4857a35d5d7700b519d713039afd31477e95e2da7aa7Chandler Carruth SpecTL.setNameLoc(TL.getNameLoc()); 48580a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setLAngleLoc(TL.getLAngleLoc()); 48590a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setRAngleLoc(TL.getRAngleLoc()); 4860944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 48610a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 486294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor } else { 48630a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor TemplateSpecializationTypeLoc SpecTL 48640a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor = TLB.push<TemplateSpecializationTypeLoc>(Result); 4865a35d5d7700b519d713039afd31477e95e2da7aa7Chandler Carruth SpecTL.setTemplateNameLoc(TL.getNameLoc()); 48660a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setLAngleLoc(TL.getLAngleLoc()); 48670a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setRAngleLoc(TL.getRAngleLoc()); 4868944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 48690a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 487094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor } 487194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return Result; 487294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor} 487394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 487494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregortemplate<typename Derived> 48757536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas GregorQualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, 48767536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor PackExpansionTypeLoc TL) { 48772fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor QualType Pattern 48782fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor = getDerived().TransformType(TLB, TL.getPatternLoc()); 48792fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor if (Pattern.isNull()) 48802fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor return QualType(); 48812fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor 48822fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor QualType Result = TL.getType(); 48832fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor if (getDerived().AlwaysRebuild() || 48842fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor Pattern != TL.getPatternLoc().getType()) { 48852fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor Result = getDerived().RebuildPackExpansionType(Pattern, 48862fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor TL.getPatternLoc().getSourceRange(), 4887cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor TL.getEllipsisLoc(), 4888cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor TL.getTypePtr()->getNumExpansions()); 48892fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor if (Result.isNull()) 48902fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor return QualType(); 48912fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor } 48922fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor 48932fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); 48942fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor NewT.setEllipsisLoc(TL.getEllipsisLoc()); 48952fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor return Result; 48967536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor} 48977536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 48987536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregortemplate<typename Derived> 4899a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 4900a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, 490143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCInterfaceTypeLoc TL) { 4902ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor // ObjCInterfaceType is never dependent. 4903c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 4904c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return TL.getType(); 4905c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 4906c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4907c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCalltemplate<typename Derived> 4908c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallQualType 4909c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallTreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, 491043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCObjectTypeLoc TL) { 4911c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // ObjCObjectType is never dependent. 4912c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 4913ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor return TL.getType(); 4914577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 49151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4917a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 4918a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, 491943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCObjectPointerTypeLoc TL) { 4920ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor // ObjCObjectPointerType is never dependent. 4921c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 4922ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor return TL.getType(); 492324fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis} 492424fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 4925577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 492643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor// Statement transformation 492743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===// 492843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 492960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 49301eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformNullStmt(NullStmt *S) { 49313fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 493243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 493343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 493443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 493560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 493643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { 493743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().TransformCompoundStmt(S, false); 493843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 493943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 494043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 494160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 49421eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, 494343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool IsStmtExpr) { 49447114cbab7eb6e8b714eb22f014327daf2c741c08John McCall bool SubStmtInvalid = false; 494543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool SubStmtChanged = false; 4946ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Stmt*> Statements(getSema()); 494743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); 494843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor B != BEnd; ++B) { 494960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Result = getDerived().TransformStmt(*B); 49507114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (Result.isInvalid()) { 49517114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // Immediately fail if this was a DeclStmt, since it's very 49527114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // likely that this will cause problems for future statements. 49537114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (isa<DeclStmt>(*B)) 49547114cbab7eb6e8b714eb22f014327daf2c741c08John McCall return StmtError(); 49557114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 49567114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // Otherwise, just keep processing substatements and fail later. 49577114cbab7eb6e8b714eb22f014327daf2c741c08John McCall SubStmtInvalid = true; 49587114cbab7eb6e8b714eb22f014327daf2c741c08John McCall continue; 49597114cbab7eb6e8b714eb22f014327daf2c741c08John McCall } 49601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 496143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SubStmtChanged = SubStmtChanged || Result.get() != *B; 496243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Statements.push_back(Result.takeAs<Stmt>()); 496343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 49641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49657114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (SubStmtInvalid) 49667114cbab7eb6e8b714eb22f014327daf2c741c08John McCall return StmtError(); 49677114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 496843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 496943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !SubStmtChanged) 49703fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 497143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 497243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildCompoundStmt(S->getLBracLoc(), 497343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor move_arg(Statements), 497443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getRBracLoc(), 497543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor IsStmtExpr); 497643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 49771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 497843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 497960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 49801eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { 498160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS, RHS; 4982264c1f8ec895952466eab59b84b8b06801e721faEli Friedman { 4983264c1f8ec895952466eab59b84b8b06801e721faEli Friedman // The case value expressions are not potentially evaluated. 4984f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 49851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4986264c1f8ec895952466eab59b84b8b06801e721faEli Friedman // Transform the left-hand case value. 4987264c1f8ec895952466eab59b84b8b06801e721faEli Friedman LHS = getDerived().TransformExpr(S->getLHS()); 4988264c1f8ec895952466eab59b84b8b06801e721faEli Friedman if (LHS.isInvalid()) 4989f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 49901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4991264c1f8ec895952466eab59b84b8b06801e721faEli Friedman // Transform the right-hand case value (for the GNU case-range extension). 4992264c1f8ec895952466eab59b84b8b06801e721faEli Friedman RHS = getDerived().TransformExpr(S->getRHS()); 4993264c1f8ec895952466eab59b84b8b06801e721faEli Friedman if (RHS.isInvalid()) 4994f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4995264c1f8ec895952466eab59b84b8b06801e721faEli Friedman } 49961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 499743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Build the case statement. 499843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Case statements are always rebuilt so that they will attached to their 499943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transformed switch statement. 500060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), 50019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), 500243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getEllipsisLoc(), 50039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get(), 500443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getColonLoc()); 500543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Case.isInvalid()) 5006f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 500843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the statement following the case 500960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 501043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 5011f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 501343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Attach the body to the case statement 50149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); 501543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 501643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 501743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 501860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 50191eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { 502043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the statement following the default case 502160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 502243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 5023f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 502543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Default statements are always rebuilt 502643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), 50279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubStmt.get()); 502843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 50291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 503043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 503160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 50321eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { 503360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 503443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 5035f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 503757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), 503857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner S->getDecl()); 503957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner if (!LD) 504057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return StmtError(); 504157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 504257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 504343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // FIXME: Pass the real colon location in. 5044ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner return getDerived().RebuildLabelStmt(S->getIdentLoc(), 504557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner cast<LabelDecl>(LD), SourceLocation(), 504657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner SubStmt.get()); 504743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 50481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 504943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 505060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 50511eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIfStmt(IfStmt *S) { 505243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 505360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 50548cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor VarDecl *ConditionVar = 0; 50558cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor if (S->getConditionVariable()) { 5056c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 50578cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor = cast_or_null<VarDecl>( 5058aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5059aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5060aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 50618cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor if (!ConditionVar) 5062f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 506399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 50648cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 5065c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 506699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5067f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5068eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 5069eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor // Convert the condition to a boolean value. 5070afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 50718491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), 50728491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 5073afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 5074f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5075eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 50769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE.get(); 5077afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 507899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 5079c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 50809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 50819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 5082f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5083eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 508443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the "then" branch. 508560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Then = getDerived().TransformStmt(S->getThen()); 508643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Then.isInvalid()) 5087f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 508943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the "else" branch. 509060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Else = getDerived().TransformStmt(S->getElse()); 509143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Else.isInvalid()) 5092f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 509443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 50959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 509699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor ConditionVar == S->getConditionVariable() && 509743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Then.get() == S->getThen() && 509843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Else.get() == S->getElse()) 50993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 51001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5101eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, 510244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis Then.get(), 51039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall S->getElseLoc(), Else.get()); 510443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 510543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 510643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 510760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 51081eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { 510943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition. 511060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 5111d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor VarDecl *ConditionVar = 0; 5112d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor if (S->getConditionVariable()) { 5113c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 5114d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor = cast_or_null<VarDecl>( 5115aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5116aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5117aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 5118d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor if (!ConditionVar) 5119f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 512099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 5121d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 5122c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 512399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5124f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 512599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 51261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 512743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Rebuild the switch statement. 512860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Switch 51299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), 5130586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor ConditionVar); 513143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Switch.isInvalid()) 5132f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 513443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body of the switch statement. 513560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 513643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5137f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 513943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Complete the switch statement. 51409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), 51419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 514243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 51431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 514443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 514560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 51461eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { 514743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 514860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 51495656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor VarDecl *ConditionVar = 0; 51505656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor if (S->getConditionVariable()) { 5151c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 51525656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor = cast_or_null<VarDecl>( 5153aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5154aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5155aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 51565656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor if (!ConditionVar) 5157f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 515899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 51595656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 5160c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 516199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5162f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5163afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 5164afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 5165afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor // Convert the condition to a boolean value. 51668491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), 51678491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 5168afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 5169f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE; 5171afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 517299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 51731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 51749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 51759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 5176f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5177eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 517843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 517960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 518043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5181f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 518343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 51849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 518599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor ConditionVar == S->getConditionVariable() && 518643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 51879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Owned(S); 51881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5189eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, 51909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ConditionVar, Body.get()); 519143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 51921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 519343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 519460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 519543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformDoStmt(DoStmt *S) { 519643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 519760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 519843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5199f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5201eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor // Transform the condition 520260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(S->getCond()); 5203eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor if (Cond.isInvalid()) 5204f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5205eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 520643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 520743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Cond.get() == S->getCond() && 520843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 52093fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 52101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), 52129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall /*FIXME:*/S->getWhileLoc(), Cond.get(), 521343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getRParenLoc()); 521443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 52151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 521643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 521760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 52181eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformForStmt(ForStmt *S) { 521943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the initialization statement 522060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Init = getDerived().TransformStmt(S->getInit()); 522143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Init.isInvalid()) 5222f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 522443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 522560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 522699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor VarDecl *ConditionVar = 0; 522799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (S->getConditionVariable()) { 5228c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 522999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor = cast_or_null<VarDecl>( 5230aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5231aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5232aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 523399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (!ConditionVar) 5234f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 523599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 523699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 5237c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 523899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5239f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5240afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 5241afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 5242afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor // Convert the condition to a boolean value. 52438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), 52448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 5245afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 5246f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5247afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 52489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE.get(); 5249afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 525099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 52511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 52539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 5254f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5255eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 525643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the increment 525760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Inc = getDerived().TransformExpr(S->getInc()); 525843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Inc.isInvalid()) 5259f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get())); 52629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (S->getInc() && !FullInc.get()) 5263f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5264eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 526543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 526660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 526743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5268f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 527043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 527143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Init.get() == S->getInit() && 52729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 527343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Inc.get() == S->getInc() && 527443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 52753fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 52761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 527743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), 52789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init.get(), FullCond, ConditionVar, 52799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullInc, S->getRParenLoc(), Body.get()); 528043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 528143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 528243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 528360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 52841eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { 528557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), 528657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner S->getLabel()); 528757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner if (!LD) 528857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return StmtError(); 528957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 529043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Goto statements must always be rebuilt, to resolve the label. 52911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), 529257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner cast<LabelDecl>(LD)); 529343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 529443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 529543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 529660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 52971eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { 529860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Target = getDerived().TransformExpr(S->getTarget()); 529943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Target.isInvalid()) 5300f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 53011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 530243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 530343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Target.get() == S->getTarget()) 53043fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 530543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 530643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), 53079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Target.get()); 530843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 530943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 531043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 531160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 53121eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { 53133fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 531443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 53151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 531643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 531760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 53181eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { 53193fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 532043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 53211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 532243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 532360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 53241eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { 532560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(S->getRetValue()); 532643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Result.isInvalid()) 5327f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 532843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 53291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // FIXME: We always rebuild the return statement because there is no way 533043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // to tell whether the return type of the function has changed. 53319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); 533243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 53331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 533443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 533560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 53361eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { 533743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool DeclChanged = false; 5338686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<Decl *, 4> Decls; 533943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); 534043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor D != DEnd; ++D) { 5341aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), 5342aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor *D); 534343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!Transformed) 5344f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 53451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 534643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Transformed != *D) 534743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor DeclChanged = true; 53481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 534943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Decls.push_back(Transformed); 535043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 53511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 535243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && !DeclChanged) 53533fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 53541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 53551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), 535643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getStartLoc(), S->getEndLoc()); 535743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 53581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 535943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 536060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 536143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { 5362c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5363ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Constraints(getSema()); 5364ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Exprs(getSema()); 5365686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<IdentifierInfo *, 4> Names; 5366a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson 536760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult AsmString; 5368ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Clobbers(getSema()); 5369703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5370703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool ExprsChanged = false; 5371c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5372703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the outputs. 5373703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { 5374ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson Names.push_back(S->getOutputIdentifier(I)); 5375c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5376703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the constraint literal. 53773fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Constraints.push_back(S->getOutputConstraintLiteral(I)); 5378c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5379703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Transform the output expr. 5380703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson Expr *OutputExpr = S->getOutputExpr(I); 538160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(OutputExpr); 5382703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (Result.isInvalid()) 5383f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5384c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5385703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson ExprsChanged |= Result.get() != OutputExpr; 5386c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 53879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs.push_back(Result.get()); 5388703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 5389c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5390703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the inputs. 5391703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { 5392ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson Names.push_back(S->getInputIdentifier(I)); 5393c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5394703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the constraint literal. 53953fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Constraints.push_back(S->getInputConstraintLiteral(I)); 5396c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5397703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Transform the input expr. 5398703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson Expr *InputExpr = S->getInputExpr(I); 539960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(InputExpr); 5400703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (Result.isInvalid()) 5401f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5402c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5403703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson ExprsChanged |= Result.get() != InputExpr; 5404c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 54059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs.push_back(Result.get()); 5406703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 5407c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5408703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (!getDerived().AlwaysRebuild() && !ExprsChanged) 54093fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 5410703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5411703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the clobbers. 5412703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) 54133fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Clobbers.push_back(S->getClobber(I)); 5414703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5415703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the asm string literal. 5416703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson AsmString = SemaRef.Owned(S->getAsmString()); 5417703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5418703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson return getDerived().RebuildAsmStmt(S->getAsmLoc(), 5419703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isSimple(), 5420703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isVolatile(), 5421703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getNumOutputs(), 5422703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getNumInputs(), 5423a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson Names.data(), 5424703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson move_arg(Constraints), 5425703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson move_arg(Exprs), 54269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall AsmString.get(), 5427703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson move_arg(Clobbers), 5428703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getRParenLoc(), 5429703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isMSAsm()); 543043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 543143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 543243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 543343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 543460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 54351eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { 54364dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the body of the @try. 543760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); 54384dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (TryBody.isInvalid()) 5439f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5440c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 54418f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor // Transform the @catch statements (if present). 54428f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor bool AnyCatchChanged = false; 5443ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Stmt*> CatchStmts(SemaRef); 54448f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { 544560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); 54464dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Catch.isInvalid()) 5447f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 54488f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor if (Catch.get() != S->getCatchStmt(I)) 54498f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor AnyCatchChanged = true; 54508f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor CatchStmts.push_back(Catch.release()); 54514dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 5452c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 54534dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the @finally statement (if present). 545460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Finally; 54554dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (S->getFinallyStmt()) { 54564dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Finally = getDerived().TransformStmt(S->getFinallyStmt()); 54574dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Finally.isInvalid()) 5458f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 54594dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 54604dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 54614dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // If nothing changed, just retain this statement. 54624dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (!getDerived().AlwaysRebuild() && 54634dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor TryBody.get() == S->getTryBody() && 54648f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor !AnyCatchChanged && 54654dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Finally.get() == S->getFinallyStmt()) 54663fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 5467c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 54684dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Build a new statement. 54699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), 54709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall move_arg(CatchStmts), Finally.get()); 547143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 54721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 547343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 547460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 54751eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { 5476be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor // Transform the @catch parameter, if there is one. 5477be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *Var = 0; 5478be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (VarDecl *FromVar = S->getCatchParamDecl()) { 5479be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TypeSourceInfo *TSInfo = 0; 5480be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (FromVar->getTypeSourceInfo()) { 5481be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); 5482be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (!TSInfo) 5483f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5484be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 5485c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5486be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor QualType T; 5487be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (TSInfo) 5488be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor T = TSInfo->getType(); 5489be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor else { 5490be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor T = getDerived().TransformType(FromVar->getType()); 5491be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (T.isNull()) 5492f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5493be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 5494c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5495be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); 5496be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (!Var) 5497f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5498be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 5499c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 550060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); 5501be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (Body.isInvalid()) 5502f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5503c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5504c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), 5505be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor S->getRParenLoc(), 55069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Var, Body.get()); 550743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 55081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 550943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 551060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 55111eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { 55124dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the body. 551360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); 55144dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Body.isInvalid()) 5515f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5516c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 55174dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // If nothing changed, just retain this statement. 55184dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (!getDerived().AlwaysRebuild() && 55194dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Body.get() == S->getFinallyBody()) 55203fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 55214dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 55224dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Build a new statement. 55234dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), 55249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 552543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 55261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 552743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 552860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 55291eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { 553060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Operand; 5531d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (S->getThrowExpr()) { 5532d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor Operand = getDerived().TransformExpr(S->getThrowExpr()); 5533d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (Operand.isInvalid()) 5534f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5535d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor } 5536c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5537d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (!getDerived().AlwaysRebuild() && 5538d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor Operand.get() == S->getThrowExpr()) 55393fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return getSema().Owned(S); 5540c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 55419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); 554243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 55431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 554443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 554560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 554643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCAtSynchronizedStmt( 55471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCAtSynchronizedStmt *S) { 55488fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Transform the object we are locking. 554960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); 55508fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (Object.isInvalid()) 5551f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 555207524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Object = 555307524039dce5c820f111a1b3f772b4261f004b4aJohn McCall getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), 555407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Object.get()); 555507524039dce5c820f111a1b3f772b4261f004b4aJohn McCall if (Object.isInvalid()) 555607524039dce5c820f111a1b3f772b4261f004b4aJohn McCall return StmtError(); 5557c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 55588fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Transform the body. 555960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); 55608fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (Body.isInvalid()) 5561f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5562c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 55638fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // If nothing change, just retain the current statement. 55648fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (!getDerived().AlwaysRebuild() && 55658fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor Object.get() == S->getSynchExpr() && 55668fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor Body.get() == S->getSynchBody()) 55673fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 55688fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor 55698fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Build a new statement. 55708fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), 55719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Object.get(), Body.get()); 557243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 557343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 557443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 557560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 5576f85e193739c953358c865005855253af4f68a497John McCallTreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( 5577f85e193739c953358c865005855253af4f68a497John McCall ObjCAutoreleasePoolStmt *S) { 5578f85e193739c953358c865005855253af4f68a497John McCall // Transform the body. 5579f85e193739c953358c865005855253af4f68a497John McCall StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); 5580f85e193739c953358c865005855253af4f68a497John McCall if (Body.isInvalid()) 5581f85e193739c953358c865005855253af4f68a497John McCall return StmtError(); 5582f85e193739c953358c865005855253af4f68a497John McCall 5583f85e193739c953358c865005855253af4f68a497John McCall // If nothing changed, just retain this statement. 5584f85e193739c953358c865005855253af4f68a497John McCall if (!getDerived().AlwaysRebuild() && 5585f85e193739c953358c865005855253af4f68a497John McCall Body.get() == S->getSubStmt()) 5586f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(S); 5587f85e193739c953358c865005855253af4f68a497John McCall 5588f85e193739c953358c865005855253af4f68a497John McCall // Build a new statement. 5589f85e193739c953358c865005855253af4f68a497John McCall return getDerived().RebuildObjCAutoreleasePoolStmt( 5590f85e193739c953358c865005855253af4f68a497John McCall S->getAtLoc(), Body.get()); 5591f85e193739c953358c865005855253af4f68a497John McCall} 5592f85e193739c953358c865005855253af4f68a497John McCall 5593f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived> 5594f85e193739c953358c865005855253af4f68a497John McCallStmtResult 559543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCForCollectionStmt( 55961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCForCollectionStmt *S) { 5597c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the element statement. 559860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Element = getDerived().TransformStmt(S->getElement()); 5599c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Element.isInvalid()) 5600f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5601c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5602c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the collection expression. 560360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Collection = getDerived().TransformExpr(S->getCollection()); 5604c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Collection.isInvalid()) 5605f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5606990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(), 5607990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall Collection.take()); 5608990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall if (Collection.isInvalid()) 5609990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall return StmtError(); 5610c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5611c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the body. 561260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 5613c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Body.isInvalid()) 5614f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5615c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5616c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // If nothing changed, just retain this statement. 5617c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (!getDerived().AlwaysRebuild() && 5618c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Element.get() == S->getElement() && 5619c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Collection.get() == S->getCollection() && 5620c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Body.get() == S->getBody()) 56213fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 5622c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5623c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Build a new statement. 5624c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), 5625c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /*FIXME:*/S->getForLoc(), 56269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Element.get(), 56279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Collection.get(), 5628c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor S->getRParenLoc(), 56299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 563043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 563143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 563243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 563343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 563460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 563543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { 563643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the exception declaration, if any. 563743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor VarDecl *Var = 0; 563843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (S->getExceptionDecl()) { 563943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor VarDecl *ExceptionDecl = S->getExceptionDecl(); 564083cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor TypeSourceInfo *T = getDerived().TransformType( 564183cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor ExceptionDecl->getTypeSourceInfo()); 564283cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor if (!T) 5643f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 56441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 564583cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, 5646ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getInnerLocStart(), 5647ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getLocation(), 5648ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getIdentifier()); 5649ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor if (!Var || Var->isInvalidDecl()) 5650f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 565143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 56521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 565343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the actual exception handler. 565460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); 5655ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor if (Handler.isInvalid()) 5656f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 56571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 565843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 565943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !Var && 566043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Handler.get() == S->getHandlerBlock()) 56613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 566243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 566343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), 566443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Var, 56659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Handler.get()); 566643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 56671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 566843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 566960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 567043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { 567143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the try block itself. 567260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TryBlock 567343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor = getDerived().TransformCompoundStmt(S->getTryBlock()); 567443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (TryBlock.isInvalid()) 5675f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 56761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 567743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the handlers. 567843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool HandlerChanged = false; 5679ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Stmt*> Handlers(SemaRef); 568043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { 568160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Handler 568243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor = getDerived().TransformCXXCatchStmt(S->getHandler(I)); 568343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Handler.isInvalid()) 5684f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 56851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 568643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); 568743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Handlers.push_back(Handler.takeAs<Stmt>()); 568843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 56891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 569043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 569143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor TryBlock.get() == S->getTryBlock() && 569243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !HandlerChanged) 56933fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 569443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 56959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), 56961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump move_arg(Handlers)); 569743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 56981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5699ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate<typename Derived> 5700ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithStmtResult 5701ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithTreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { 5702ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); 5703ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Range.isInvalid()) 5704ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5705ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5706ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt()); 5707ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (BeginEnd.isInvalid()) 5708ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5709ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5710ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ExprResult Cond = getDerived().TransformExpr(S->getCond()); 5711ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Cond.isInvalid()) 5712ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5713ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5714ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ExprResult Inc = getDerived().TransformExpr(S->getInc()); 5715ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Inc.isInvalid()) 5716ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5717ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5718ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); 5719ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (LoopVar.isInvalid()) 5720ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5721ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5722ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult NewStmt = S; 5723ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (getDerived().AlwaysRebuild() || 5724ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Range.get() != S->getRangeStmt() || 5725ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith BeginEnd.get() != S->getBeginEndStmt() || 5726ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Cond.get() != S->getCond() || 5727ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Inc.get() != S->getInc() || 5728ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith LoopVar.get() != S->getLoopVarStmt()) 5729ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), 5730ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getColonLoc(), Range.get(), 5731ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith BeginEnd.get(), Cond.get(), 5732ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Inc.get(), LoopVar.get(), 5733ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getRParenLoc()); 5734ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5735ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult Body = getDerived().TransformStmt(S->getBody()); 5736ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Body.isInvalid()) 5737ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5738ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5739ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith // Body has changed but we didn't rebuild the for-range statement. Rebuild 5740ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith // it now so we have a new statement to attach the body to. 5741ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Body.get() != S->getBody() && NewStmt.get() == S) 5742ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), 5743ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getColonLoc(), Range.get(), 5744ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith BeginEnd.get(), Cond.get(), 5745ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Inc.get(), LoopVar.get(), 5746ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getRParenLoc()); 5747ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5748ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (NewStmt.get() == S) 5749ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return SemaRef.Owned(S); 5750ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5751ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); 5752ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith} 5753ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 575428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 575528bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 5756ba0513de93d2fab6db5ab30b6927209fcc883078Douglas GregorTreeTransform<Derived>::TransformMSDependentExistsStmt( 5757ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor MSDependentExistsStmt *S) { 5758ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // Transform the nested-name-specifier, if any. 5759ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 5760ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (S->getQualifierLoc()) { 5761ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor QualifierLoc 5762ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); 5763ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (!QualifierLoc) 5764ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return StmtError(); 5765ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor } 5766ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5767ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // Transform the declaration name. 5768ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor DeclarationNameInfo NameInfo = S->getNameInfo(); 5769ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (NameInfo.getName()) { 5770ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 5771ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (!NameInfo.getName()) 5772ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return StmtError(); 5773ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor } 5774ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5775ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // Check whether anything changed. 5776ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (!getDerived().AlwaysRebuild() && 5777ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor QualifierLoc == S->getQualifierLoc() && 5778ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NameInfo.getName() == S->getNameInfo().getName()) 5779ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return S; 5780ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5781ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // Determine whether this name exists, if we can. 5782ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor CXXScopeSpec SS; 5783ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor SS.Adopt(QualifierLoc); 5784ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor bool Dependent = false; 5785ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) { 5786ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor case Sema::IER_Exists: 5787ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (S->isIfExists()) 5788ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor break; 5789ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5790ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return new (getSema().Context) NullStmt(S->getKeywordLoc()); 5791ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5792ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor case Sema::IER_DoesNotExist: 5793ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (S->isIfNotExists()) 5794ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor break; 5795ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5796ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return new (getSema().Context) NullStmt(S->getKeywordLoc()); 5797ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5798ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor case Sema::IER_Dependent: 5799ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor Dependent = true; 5800ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor break; 580165019acfc46ffb191fac4e781ac0c4b8d0c8434eDouglas Gregor 580265019acfc46ffb191fac4e781ac0c4b8d0c8434eDouglas Gregor case Sema::IER_Error: 580365019acfc46ffb191fac4e781ac0c4b8d0c8434eDouglas Gregor return StmtError(); 5804ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor } 5805ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5806ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // We need to continue with the instantiation, so do so now. 5807ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); 5808ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (SubStmt.isInvalid()) 5809ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return StmtError(); 5810ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5811ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // If we have resolved the name, just transform to the substatement. 5812ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (!Dependent) 5813ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return SubStmt; 5814ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5815ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // The name is still dependent, so build a dependent expression again. 5816ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), 5817ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor S->isIfExists(), 5818ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor QualifierLoc, 5819ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NameInfo, 5820ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor SubStmt.get()); 5821ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor} 5822ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5823ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregortemplate<typename Derived> 5824ba0513de93d2fab6db5ab30b6927209fcc883078Douglas GregorStmtResult 582528bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { 582628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock()); 582728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(TryBlock.isInvalid()) return StmtError(); 582828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 582928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); 583028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(!getDerived().AlwaysRebuild() && 583128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley TryBlock.get() == S->getTryBlock() && 583228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Handler.get() == S->getHandler()) 583328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return SemaRef.Owned(S); 583428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 583528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), 583628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley S->getTryLoc(), 583728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley TryBlock.take(), 583828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Handler.take()); 583928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 584028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 584128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 584228bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 584328bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { 584428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); 584528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(Block.isInvalid()) return StmtError(); 584628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 584728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), 584828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Block.take()); 584928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 585028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 585128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 585228bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 585328bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { 585428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); 585528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(FilterExpr.isInvalid()) return StmtError(); 585628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 585728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); 585828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(Block.isInvalid()) return StmtError(); 585928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 586028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), 586128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley FilterExpr.take(), 586228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Block.take()); 586328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 586428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 586528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 586628bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 586728bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { 586828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(isa<SEHFinallyStmt>(Handler)) 586928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); 587028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley else 587128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); 587228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 587328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 587443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===// 5875b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Expression transformation 5876577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 58771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 587860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5879454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { 58803fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 58811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 58821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 58831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 588460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5885454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { 588640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc; 588740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (E->getQualifierLoc()) { 588840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc 588940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 589040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!QualifierLoc) 5891f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5892a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 5893dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 5894dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *ND 58957c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), 58967c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getDecl())); 5897b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!ND) 5898f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 58991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5900ec8045d3f0375302eadaa63deb373bacaf25a569John McCall DeclarationNameInfo NameInfo = E->getNameInfo(); 5901ec8045d3f0375302eadaa63deb373bacaf25a569John McCall if (NameInfo.getName()) { 5902ec8045d3f0375302eadaa63deb373bacaf25a569John McCall NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 5903ec8045d3f0375302eadaa63deb373bacaf25a569John McCall if (!NameInfo.getName()) 5904f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5905ec8045d3f0375302eadaa63deb373bacaf25a569John McCall } 59062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 59072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!getDerived().AlwaysRebuild() && 590840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc == E->getQualifierLoc() && 5909a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor ND == E->getDecl() && 59102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getDecl()->getDeclName() && 5911096832c5ed5b9106fa177ebc148489760c3bc496John McCall !E->hasExplicitTemplateArgs()) { 59121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5913dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // Mark it referenced in the new context regardless. 5914dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // FIXME: this is a bit instantiation-specific. 5915dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); 5916a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 59173fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5918a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 5919dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 5920dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; 5921096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (E->hasExplicitTemplateArgs()) { 5922dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TemplateArgs = &TransArgs; 5923dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TransArgs.setLAngleLoc(E->getLAngleLoc()); 5924dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TransArgs.setRAngleLoc(E->getRAngleLoc()); 5925fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 5926fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 5927fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 5928fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 5929dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall } 5930dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 593140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, 593240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor TemplateArgs); 5933577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 59341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5935b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 593660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5937454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { 59383fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5939577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 59401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5941b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 594260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5943454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { 59443fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5945b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 59461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5947b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 594860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5949454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { 59503fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5951b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 59521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 59531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 595460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5955454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { 59563fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5957b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 59581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5959b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 596060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5961454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { 59623fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5963b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 59641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5965b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 596660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5967f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneTreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { 5968f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult ControllingExpr = 5969f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne getDerived().TransformExpr(E->getControllingExpr()); 5970f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (ControllingExpr.isInvalid()) 5971f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ExprError(); 5972f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 5973686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<Expr *, 4> AssocExprs; 5974686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<TypeSourceInfo *, 4> AssocTypes; 5975f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne for (unsigned i = 0; i != E->getNumAssocs(); ++i) { 5976f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); 5977f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (TS) { 5978f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo *AssocType = getDerived().TransformType(TS); 5979f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!AssocType) 5980f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ExprError(); 5981f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes.push_back(AssocType); 5982f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } else { 5983f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes.push_back(0); 5984f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 5985f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 5986f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); 5987f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (AssocExpr.isInvalid()) 5988f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ExprError(); 5989f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs.push_back(AssocExpr.release()); 5990f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 5991f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 5992f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), 5993f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E->getDefaultLoc(), 5994f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E->getRParenLoc(), 5995f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ControllingExpr.release(), 5996f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes.data(), 5997f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs.data(), 5998f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E->getNumAssocs()); 5999f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne} 6000f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 6001f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbournetemplate<typename Derived> 6002f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneExprResult 6003454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { 600460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 6005b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6006f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 60071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6008b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) 60093fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 60101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), 6012b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParen()); 6013b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6014b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 60151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 601660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6017454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { 601860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 6019b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6020f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 60211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6022b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) 60233fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 60241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6025b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), 6026b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOpcode(), 60279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get()); 6028b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 60291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6030b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 603160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 60328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorTreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { 60338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Transform the type. 60348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); 60358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (!Type) 6036f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6037c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 60388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Transform all of the components into components similar to what the 60398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // parser uses. 6040c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // FIXME: It would be slightly more efficient in the non-dependent case to 6041c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // just map FieldDecls, rather than requiring the rebuilder to look for 6042c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // the fields again. However, __builtin_offsetof is rare enough in 60438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // template code that we don't care. 60448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor bool ExprChanged = false; 6045f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall typedef Sema::OffsetOfComponent Component; 60468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor typedef OffsetOfExpr::OffsetOfNode Node; 6047686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<Component, 4> Components; 60488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { 60498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor const Node &ON = E->getComponent(I); 60508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Component Comp; 605172be24f39c162448e53dd73cf57cc6357114361eDouglas Gregor Comp.isBrackets = true; 605206dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara Comp.LocStart = ON.getSourceRange().getBegin(); 605306dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara Comp.LocEnd = ON.getSourceRange().getEnd(); 60548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor switch (ON.getKind()) { 60558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Array: { 60568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); 605760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Index = getDerived().TransformExpr(FromIndex); 60588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (Index.isInvalid()) 6059f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6060c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 60618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor ExprChanged = ExprChanged || Index.get() != FromIndex; 60628ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.isBrackets = true; 60639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Comp.U.E = Index.get(); 60648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor break; 60658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 6066c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 60678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Field: 60688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Identifier: 60698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.isBrackets = false; 60708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.U.IdentInfo = ON.getFieldName(); 607129d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor if (!Comp.U.IdentInfo) 607229d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor continue; 6073c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 60748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor break; 6075c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6076cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor case Node::Base: 6077cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor // Will be recomputed during the rebuild. 6078cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor continue; 60798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 6080c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 60818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Components.push_back(Comp); 60828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 6083c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 60848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // If nothing changed, retain the existing expression. 60858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (!getDerived().AlwaysRebuild() && 60868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Type == E->getTypeSourceInfo() && 60878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor !ExprChanged) 60883fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6089c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 60908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Build a new offsetof expression. 60918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, 60928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Components.data(), Components.size(), 60938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor E->getRParenLoc()); 60947cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall} 60957cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall 60967cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCalltemplate<typename Derived> 60977cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallExprResult 60987cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallTreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { 60997cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall assert(getDerived().AlreadyTransformed(E->getType()) && 61007cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall "opaque value expression requires transformation"); 61017cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall return SemaRef.Owned(E); 61028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 61038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 61048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregortemplate<typename Derived> 610560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 61064b9c2d235fb9449e249d74f48ecfec601650de93John McCallTreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { 610701e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // Rebuild the syntactic form. The original syntactic form has 610801e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // opaque-value expressions in it, so strip those away and rebuild 610901e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // the result. This is a really awful way of doing this, but the 611001e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // better solution (rebuilding the semantic expressions and 611101e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // rebinding OVEs as necessary) doesn't work; we'd need 611201e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // TreeTransform to not strip away implicit conversions. 611301e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); 611401e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall ExprResult result = getDerived().TransformExpr(newSyntacticForm); 61154b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (result.isInvalid()) return ExprError(); 61164b9c2d235fb9449e249d74f48ecfec601650de93John McCall 61174b9c2d235fb9449e249d74f48ecfec601650de93John McCall // If that gives us a pseudo-object result back, the pseudo-object 61184b9c2d235fb9449e249d74f48ecfec601650de93John McCall // expression must have been an lvalue-to-rvalue conversion which we 61194b9c2d235fb9449e249d74f48ecfec601650de93John McCall // should reapply. 61204b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) 61214b9c2d235fb9449e249d74f48ecfec601650de93John McCall result = SemaRef.checkPseudoObjectRValue(result.take()); 61224b9c2d235fb9449e249d74f48ecfec601650de93John McCall 61234b9c2d235fb9449e249d74f48ecfec601650de93John McCall return result; 61244b9c2d235fb9449e249d74f48ecfec601650de93John McCall} 61254b9c2d235fb9449e249d74f48ecfec601650de93John McCall 61264b9c2d235fb9449e249d74f48ecfec601650de93John McCalltemplate<typename Derived> 61274b9c2d235fb9449e249d74f48ecfec601650de93John McCallExprResult 6128f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter CollingbourneTreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( 6129f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr *E) { 6130b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->isArgumentType()) { 6131a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *OldT = E->getArgumentTypeInfo(); 61325557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor 6133a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *NewT = getDerived().TransformType(OldT); 61345ab75172051a6d2ea71a80a79e81c65519fd3462John McCall if (!NewT) 6135f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61375ab75172051a6d2ea71a80a79e81c65519fd3462John McCall if (!getDerived().AlwaysRebuild() && OldT == NewT) 61383fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 61391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6140f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), 6141f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getKind(), 6142f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getSourceRange()); 6143b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 61441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 614560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr; 61461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump { 6147b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // C++0x [expr.sizeof]p1: 6148b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // The operand is either an expression, which is an unevaluated operand 6149b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // [...] 6150f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 61511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6152b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); 6153b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6154f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6156b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) 61573fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6158b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 61591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6160f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), 6161f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getOperatorLoc(), 6162f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getKind(), 6163f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getSourceRange()); 6164b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 61651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6166b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 616760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6168454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { 616960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6170b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6171f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 617360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6174b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6175f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6178b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6179b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6180b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 61813fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 61821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildArraySubscriptExpr(LHS.get(), 6184b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLHS()->getLocStart(), 61859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get(), 6186b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRBracketLoc()); 6187b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 61881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 619060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6191454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCallExpr(CallExpr *E) { 6192b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the callee. 619360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 6194b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Callee.isInvalid()) 6195f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6196b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6197b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform arguments. 6198b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgChanged = false; 6199ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 6200aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 6201aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgChanged)) 6202aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6203aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 6204b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6205b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Callee.get() == E->getCallee() && 6206b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgChanged) 62073fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 62081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6209b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Wrong source location information for the '('. 62101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeLParenLoc 6211b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = ((Expr *)Callee.get())->getSourceRange().getBegin(); 62129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, 6213b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Args), 6214b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6215b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 62161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 621860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6219454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { 622060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 6221b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Base.isInvalid()) 6222f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 622440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc; 622583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor if (E->hasQualifier()) { 622640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc 622740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 622840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 622940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!QualifierLoc) 6230f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 623183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 62321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6233f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *Member 62347c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), 62357c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getMemberDecl())); 6236b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Member) 6237f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62396bb8017bb9e828d118e15e59d71c66bba323c364John McCall NamedDecl *FoundDecl = E->getFoundDecl(); 62406bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (FoundDecl == E->getMemberDecl()) { 62416bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl = Member; 62426bb8017bb9e828d118e15e59d71c66bba323c364John McCall } else { 62436bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl = cast_or_null<NamedDecl>( 62446bb8017bb9e828d118e15e59d71c66bba323c364John McCall getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); 62456bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!FoundDecl) 6246f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62476bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 62486bb8017bb9e828d118e15e59d71c66bba323c364John McCall 6249b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6250b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Base.get() == E->getBase() && 625140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc == E->getQualifierLoc() && 62528a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor Member == E->getMemberDecl() && 62536bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl == E->getFoundDecl() && 6254096832c5ed5b9106fa177ebc148489760c3bc496John McCall !E->hasExplicitTemplateArgs()) { 6255c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 62561f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson // Mark it referenced in the new context regardless. 62571f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson // FIXME: this is a bit instantiation-specific. 62581f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); 62593fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 62601f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson } 6261b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6262d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs; 6263096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (E->hasExplicitTemplateArgs()) { 6264d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TransArgs.setLAngleLoc(E->getLAngleLoc()); 6265d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TransArgs.setRAngleLoc(E->getRAngleLoc()); 6266fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 6267fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 6268fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 6269fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 62708a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor } 6271c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6272b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Bogus source location for the operator 6273b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeOperatorLoc 6274b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); 6275b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6276c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // FIXME: to do this check properly, we will need to preserve the 6277c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // first-qualifier-in-scope here, just in case we had a dependent 6278c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // base (and therefore couldn't do the check) and a 6279c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // nested-name-qualifier (and therefore could do the lookup). 6280c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall NamedDecl *FirstQualifierInScope = 0; 6281c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 62829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, 6283b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrow(), 628440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc, 62852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara E->getMemberNameInfo(), 62868a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor Member, 62876bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl, 6288096832c5ed5b9106fa177ebc148489760c3bc496John McCall (E->hasExplicitTemplateArgs() 6289d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall ? &TransArgs : 0), 6290c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall FirstQualifierInScope); 6291b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 62921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6293b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 629460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6295454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { 629660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6297b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6298f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 630060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6301b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6302f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6304b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6305b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6306b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 63073fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 63081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6309b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), 63109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), RHS.get()); 6311b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6312b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 63131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 631460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6315b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCompoundAssignOperator( 6316454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CompoundAssignOperator *E) { 6317454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformBinaryOperator(E); 6318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 63191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 632156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallExprResult TreeTransform<Derived>:: 632256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallTransformBinaryConditionalOperator(BinaryConditionalOperator *e) { 632356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // Just rebuild the common and RHS expressions and see whether we 632456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // get any changes. 632556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 632656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); 632756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (commonExpr.isInvalid()) 632856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return ExprError(); 632956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 633056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); 633156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (rhs.isInvalid()) 633256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return ExprError(); 633356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 633456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (!getDerived().AlwaysRebuild() && 633556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall commonExpr.get() == e->getCommon() && 633656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs.get() == e->getFalseExpr()) 633756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return SemaRef.Owned(e); 633856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 633956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return getDerived().RebuildConditionalOperator(commonExpr.take(), 634056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall e->getQuestionLoc(), 634156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 0, 634256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall e->getColonLoc(), 634356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs.get()); 634456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 634556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 634656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCalltemplate<typename Derived> 634760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6348454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { 634960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(E->getCond()); 6350b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Cond.isInvalid()) 6351f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 635360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6354b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6355f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 635760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6358b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6359f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6361b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6362b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Cond.get() == E->getCond() && 6363b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6364b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 63653fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 63661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildConditionalOperator(Cond.get(), 636847e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor E->getQuestionLoc(), 63699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), 637047e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor E->getColonLoc(), 63719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get()); 6372b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 63731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 637560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6376454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { 6377a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor // Implicit casts are eliminated during transformation, since they 6378a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor // will be recomputed by semantic analysis after transformation. 63796eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return getDerived().TransformExpr(E->getSubExprAsWritten()); 6380b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 63811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6382b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 638360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6384454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { 6385ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 6386ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 6387ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 6388ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor 638960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 63906eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 6391b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6392f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6394b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6395ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 6396b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 63973fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 63981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63999d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), 6400ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type, 6401b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc(), 64029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get()); 6403b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6405b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 640660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6407454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { 640842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *OldT = E->getTypeSourceInfo(); 640942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *NewT = getDerived().TransformType(OldT); 641042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall if (!NewT) 6411f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 641360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Init = getDerived().TransformExpr(E->getInitializer()); 6414b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Init.isInvalid()) 6415f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6417b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 641842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall OldT == NewT && 6419b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Init.get() == E->getInitializer()) 64203fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6421b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 64221d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // Note: the expression type doesn't necessarily match the 64231d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // type-as-written, but that's okay, because it should always be 64241d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // derivable from the initializer. 64251d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 642642f56b50062cd3b3c6b23fdb9053578ae9145664John McCall return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, 6427b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getInitializer()->getLocEnd(), 64289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init.get()); 6429b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6431b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 643260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6433454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { 643460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 6435b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Base.isInvalid()) 6436f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6438b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6439b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Base.get() == E->getBase()) 64403fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 64411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6442b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Bad source location 64431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeOperatorLoc 6444b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); 64459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, 6446b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getAccessorLoc(), 6447b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getAccessor()); 6448b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6450b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 645160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6452454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { 6453b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool InitChanged = false; 64541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6455ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*, 4> Inits(SemaRef); 6456aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, 6457aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Inits, &InitChanged)) 6458aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6459aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 6460b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && !InitChanged) 64613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 64621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6463b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), 6464e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor E->getRBraceLoc(), E->getType()); 6465b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6467b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 646860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6469454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { 6470b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Designation Desig; 64711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 647243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transform the initializer value 647360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Init = getDerived().TransformExpr(E->getInit()); 6474b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Init.isInvalid()) 6475f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 647743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transform the designators. 6478ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef); 6479b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ExprChanged = false; 6480b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), 6481b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor DEnd = E->designators_end(); 6482b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D != DEnd; ++D) { 6483b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (D->isFieldDesignator()) { 6484b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Desig.AddDesignator(Designator::getField(D->getFieldName(), 6485b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getDotLoc(), 6486b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getFieldLoc())); 6487b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor continue; 6488b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 64891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6490b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (D->isArrayDesignator()) { 649160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); 6492b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Index.isInvalid()) 6493f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 64951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Desig.AddDesignator(Designator::getArray(Index.get(), 6496b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getLBracketLoc())); 64971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6498b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); 6499b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(Index.release()); 6500b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor continue; 6501b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 65021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6503b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor assert(D->isArrayRangeDesignator() && "New kind of designator?"); 650460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Start 6505b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = getDerived().TransformExpr(E->getArrayRangeStart(*D)); 6506b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Start.isInvalid()) 6507f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 650960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); 6510b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (End.isInvalid()) 6511f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 65131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Desig.AddDesignator(Designator::getArrayRange(Start.get(), 6514b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor End.get(), 6515b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getLBracketLoc(), 6516b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getEllipsisLoc())); 65171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6518b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || 6519b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor End.get() != E->getArrayRangeEnd(*D); 65201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6521b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(Start.release()); 6522b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(End.release()); 6523b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 65241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6525b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6526b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Init.get() == E->getInit() && 6527b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ExprChanged) 65283fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 65291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6530b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), 6531b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getEqualOrColonLoc(), 65329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall E->usesGNUSyntax(), Init.get()); 6533b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 65341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6535b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 653660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6537b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformImplicitValueInitExpr( 6538454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall ImplicitValueInitExpr *E) { 65395557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); 6540c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 65415557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor // FIXME: Will we ever have proper type location here? Will we actually 65425557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor // need to transform the type? 6543b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor QualType T = getDerived().TransformType(E->getType()); 6544b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (T.isNull()) 6545f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6547b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6548b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T == E->getType()) 65493fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 65501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6551b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildImplicitValueInitExpr(T); 6552b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 65531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6554b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 655560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6556454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { 65579bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); 65589bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor if (!TInfo) 6559f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 656160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 6562b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6563f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6565b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 65662cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TInfo == E->getWrittenTypeInfo() && 6567b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 65683fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 65691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 65709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), 65712cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TInfo, E->getRParenLoc()); 6572b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6573b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6574b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 657560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6576454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { 6577b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 6578ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*, 4> Inits(SemaRef); 6579aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, 6580aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 6581aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6582aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 6583b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildParenListExpr(E->getLParenLoc(), 6584b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Inits), 6585b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6586b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 65871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6588b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform an address-of-label expression. 6589b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 6590b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// By default, the transformation of an address-of-label expression always 6591b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// rebuilds the expression, so that the label identifier can be resolved to 6592b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// the corresponding label statement by semantic analysis. 6593b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 659460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6595454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { 659657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), 659757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner E->getLabel()); 659857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner if (!LD) 659957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return ExprError(); 660057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 6601b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), 660257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner cast<LabelDecl>(LD)); 6603b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 66051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 660660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6607454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { 660860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt 6609b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = getDerived().TransformCompoundStmt(E->getSubStmt(), true); 6610b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubStmt.isInvalid()) 6611f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6613b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6614b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubStmt.get() == E->getSubStmt()) 66153fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 66161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 66171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildStmtExpr(E->getLParenLoc(), 66189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubStmt.get(), 6619b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6620b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6622b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 662360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6624454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { 662560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(E->getCond()); 6626b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Cond.isInvalid()) 6627f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 662960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6630b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6631f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 663360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6634b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6635f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6637b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6638b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Cond.get() == E->getCond() && 6639b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6640b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 66413fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 66421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6643b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), 66449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond.get(), LHS.get(), RHS.get(), 6645b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6646b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6648b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 664960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6650454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { 66513fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6652b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6653b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6654b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 665560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6656454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { 6657668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor switch (E->getOperator()) { 6658668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_New: 6659668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Delete: 6660668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Array_New: 6661668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Array_Delete: 6662668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); 6663f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6664c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6665668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Call: { 6666668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // This is a call to an object's operator(). 6667668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); 6668668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6669668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Transform the object itself. 667060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Object = getDerived().TransformExpr(E->getArg(0)); 6671668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor if (Object.isInvalid()) 6672f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6673668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6674668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // FIXME: Poor location information 6675668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor SourceLocation FakeLParenLoc 6676668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor = SemaRef.PP.getLocForEndOfToken( 6677668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor static_cast<Expr *>(Object.get())->getLocEnd()); 6678668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6679668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Transform the call arguments. 6680ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 6681aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, 6682aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args)) 6683aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6684668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 66859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, 6686668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor move_arg(Args), 6687668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor E->getLocEnd()); 6688668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor } 6689668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6690668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ 6691668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_##Name: 6692668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) 6693668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#include "clang/Basic/OperatorKinds.def" 6694668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Subscript: 6695668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Handled below. 6696668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor break; 6697668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6698668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Conditional: 6699668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("conditional operator is not actually overloadable"); 6700f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6701668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6702668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_None: 6703668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case NUM_OVERLOADED_OPERATORS: 6704668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("not an overloaded operator?"); 6705f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6706668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor } 6707668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 670860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 6709b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Callee.isInvalid()) 6710f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 67111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 671260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult First = getDerived().TransformExpr(E->getArg(0)); 6713b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (First.isInvalid()) 6714f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6715b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 671660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Second; 6717b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->getNumArgs() == 2) { 6718b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Second = getDerived().TransformExpr(E->getArg(1)); 6719b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Second.isInvalid()) 6720f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6721b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 67221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6723b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6724b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Callee.get() == E->getCallee() && 6725b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor First.get() == E->getArg(0) && 67261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) 67273fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 67281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6729b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), 6730b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOperatorLoc(), 67319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Callee.get(), 67329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall First.get(), 67339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Second.get()); 6734b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 67351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6736b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 673760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6738454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { 6739454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCallExpr(E); 6740b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 67411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6742b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 6743e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneExprResult 6744e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneTreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { 6745e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // Transform the callee. 6746e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 6747e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (Callee.isInvalid()) 6748e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return ExprError(); 6749e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6750e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // Transform exec config. 6751e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); 6752e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (EC.isInvalid()) 6753e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return ExprError(); 6754e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6755e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // Transform arguments. 6756e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne bool ArgChanged = false; 6757e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ASTOwningVector<Expr*> Args(SemaRef); 6758e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 6759e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne &ArgChanged)) 6760e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return ExprError(); 6761e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6762e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (!getDerived().AlwaysRebuild() && 6763e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne Callee.get() == E->getCallee() && 6764e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne !ArgChanged) 6765e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return SemaRef.Owned(E); 6766e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6767e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // FIXME: Wrong source location information for the '('. 6768e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne SourceLocation FakeLParenLoc 6769e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne = ((Expr *)Callee.get())->getSourceRange().getBegin(); 6770e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, 6771e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne move_arg(Args), 6772e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne E->getRParenLoc(), EC.get()); 6773e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne} 6774e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6775e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournetemplate<typename Derived> 677660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6777454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { 6778ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 6779ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 6780ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 6781ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor 678260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 67836eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 6784b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6785f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 67861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6787b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6788ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 6789b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 67903fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 67911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6792b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Poor source location information here. 67931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeLAngleLoc 6794b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); 6795b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); 6796b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeRParenLoc 6797b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken( 6798b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getSubExpr()->getSourceRange().getEnd()); 6799b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), 68001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump E->getStmtClass(), 6801b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeLAngleLoc, 6802ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type, 6803b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRAngleLoc, 6804b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRAngleLoc, 68059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 6806b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRParenLoc); 6807b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6809b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 681060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6811454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { 6812454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 6813b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6815b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 681660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6817454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { 6818454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 6819b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6821b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 682260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6823b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXReinterpretCastExpr( 6824454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXReinterpretCastExpr *E) { 6825454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 6826b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6828b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 682960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6830454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { 6831454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 6832b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6834b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 683560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6836b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXFunctionalCastExpr( 6837454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXFunctionalCastExpr *E) { 6838ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 6839ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 6840ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 68411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 684260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 68436eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 6844b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6845f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6847b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6848ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 6849b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 68503fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 68511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6852ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return getDerived().RebuildCXXFunctionalCastExpr(Type, 6853b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getSubExpr()->getLocStart(), 68549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 6855b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6856b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6858b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 685960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6860454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { 6861b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->isTypeOperand()) { 686257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TypeSourceInfo *TInfo 686357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor = getDerived().TransformType(E->getTypeOperandSourceInfo()); 686457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor if (!TInfo) 6865f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6867b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 686857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TInfo == E->getTypeOperandSourceInfo()) 68693fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 68701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 687157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return getDerived().RebuildCXXTypeidExpr(E->getType(), 687257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor E->getLocStart(), 687357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TInfo, 6874b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 6875b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 68761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6877b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // We don't know whether the expression is potentially evaluated until 6878b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // after we perform semantic analysis, so the expression is potentially 6879b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // potentially evaluated. 68801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EnterExpressionEvaluationContext Unevaluated(SemaRef, 6881f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::PotentiallyPotentiallyEvaluated); 68821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 688360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); 6884b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6885f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6887b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6888b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getExprOperand()) 68893fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 68901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 689157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return getDerived().RebuildCXXTypeidExpr(E->getType(), 689257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor E->getLocStart(), 68939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 6894b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 6895b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6896b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6897b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 689860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 689901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetTreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { 690001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (E->isTypeOperand()) { 690101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TypeSourceInfo *TInfo 690201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet = getDerived().TransformType(E->getTypeOperandSourceInfo()); 690301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!TInfo) 690401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return ExprError(); 690501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 690601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!getDerived().AlwaysRebuild() && 690701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TInfo == E->getTypeOperandSourceInfo()) 69083fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 690901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 69103c52a218f41f091a17582d037663594d2b8dc708Douglas Gregor return getDerived().RebuildCXXUuidofExpr(E->getType(), 691101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocStart(), 691201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TInfo, 691301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocEnd()); 691401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 691501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 691601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // We don't know whether the expression is potentially evaluated until 691701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // after we perform semantic analysis, so the expression is potentially 691801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // potentially evaluated. 691901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 692001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 692101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); 692201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (SubExpr.isInvalid()) 692301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return ExprError(); 692401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 692501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!getDerived().AlwaysRebuild() && 692601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SubExpr.get() == E->getExprOperand()) 69273fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 692801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 692901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getDerived().RebuildCXXUuidofExpr(E->getType(), 693001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocStart(), 693101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SubExpr.get(), 693201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocEnd()); 693301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet} 693401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 693501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichettemplate<typename Derived> 693601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetExprResult 6937454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { 69383fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6939b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 69401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6941b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 694260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6943b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( 6944454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXNullPtrLiteralExpr *E) { 69453fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6946b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 69471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6948b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 694960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6950454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { 6951ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor DeclContext *DC = getSema().getFunctionLevelDeclContext(); 69527a614d8380297fcd2bc23986241905d97222948cRichard Smith QualType T; 69537a614d8380297fcd2bc23986241905d97222948cRichard Smith if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) 69547a614d8380297fcd2bc23986241905d97222948cRichard Smith T = MD->getThisType(getSema().Context); 69557a614d8380297fcd2bc23986241905d97222948cRichard Smith else 69567a614d8380297fcd2bc23986241905d97222948cRichard Smith T = getSema().Context.getPointerType( 69577a614d8380297fcd2bc23986241905d97222948cRichard Smith getSema().Context.getRecordType(cast<CXXRecordDecl>(DC))); 69581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6959ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!getDerived().AlwaysRebuild() && T == E->getType()) 69603fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 69611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6962828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); 6963b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 69641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6965b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 696660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6967454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { 696860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 6969b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6970f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 69711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6972b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6973b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 69743fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6975b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6976bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), 6977bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor E->isThrownVariableInScope()); 6978b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 69791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6980b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 698160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6982454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { 69831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParmVarDecl *Param 69847c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), 69857c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getParam())); 6986b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Param) 6987f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 69881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 698953cb6f82c41397917b14fb8cdcb32e6c9bd07655Chandler Carruth if (!getDerived().AlwaysRebuild() && 6990b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Param == E->getParam()) 69913fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 69921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6993036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); 6994b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 69951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6996b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 699760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6998ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas GregorTreeTransform<Derived>::TransformCXXScalarValueInitExpr( 6999ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXScalarValueInitExpr *E) { 7000ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 7001ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 7002f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7003ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor 7004b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7005ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo()) 70063fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 70071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7008ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXScalarValueInitExpr(T, 7009ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /*FIXME:*/T->getTypeLoc().getEndLoc(), 7010ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor E->getRParenLoc()); 7011b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 70121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7013b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 701460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7015454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { 7016b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the type that we're allocating 70171bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *AllocTypeInfo 70181bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); 70191bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor if (!AllocTypeInfo) 7020f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7022b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the size of the array we're allocating (if any). 702360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); 7024b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (ArraySize.isInvalid()) 7025f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7027b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the placement arguments (if any). 7028b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 7029ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> PlacementArgs(SemaRef); 7030aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getPlacementArgs(), 7031aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor E->getNumPlacementArgs(), true, 7032aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor PlacementArgs, &ArgumentChanged)) 7033aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 70341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 70354e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor // Transform the constructor arguments (if any). 70364e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor // As an annoying corner case, we may have introduced an implicit value- 70374e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor // initialization expression when allocating a new array, which we implicitly 70384e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor // drop. It will be re-created during type checking. 7039ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> ConstructorArgs(SemaRef); 70404e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor if (!(E->isArray() && E->getNumConstructorArgs() == 1 && 70414e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor isa<ImplicitValueInitExpr>(E->getConstructorArgs()[0])) && 70424e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true, 7043aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor ConstructorArgs, &ArgumentChanged)) 7044aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 70451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 70461af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Transform constructor, new operator, and delete operator. 70471af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor CXXConstructorDecl *Constructor = 0; 70481af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getConstructor()) { 70491af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor Constructor = cast_or_null<CXXConstructorDecl>( 70507c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 70517c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 70521af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!Constructor) 7053f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70541af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 70551af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor 70561af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorNew = 0; 70571af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorNew()) { 70581af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorNew = cast_or_null<FunctionDecl>( 70597c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 70607c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorNew())); 70611af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorNew) 7062f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70631af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 70641af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor 70651af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorDelete = 0; 70661af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorDelete()) { 70671af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete = cast_or_null<FunctionDecl>( 70687c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 70697c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorDelete())); 70701af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorDelete) 7071f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70721af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 7073c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7074b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 70751bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocTypeInfo == E->getAllocatedTypeSourceInfo() && 7076b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArraySize.get() == E->getArraySize() && 70771af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor Constructor == E->getConstructor() && 70781af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorNew == E->getOperatorNew() && 70791af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete == E->getOperatorDelete() && 70801af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor !ArgumentChanged) { 70811af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark any declarations we need as referenced. 70821af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: instantiation-specific. 70831af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (Constructor) 70841af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); 70851af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorNew) 70861af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); 70871af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorDelete) 70881af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); 70892ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor 70902ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor if (E->isArray() && Constructor && 70912ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor !E->getAllocatedType()->isDependentType()) { 70922ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor QualType ElementType 70932ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor = SemaRef.Context.getBaseElementType(E->getAllocatedType()); 70942ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { 70952ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); 70962ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { 70972ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), Destructor); 70982ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor } 70992ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor } 71002ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor } 71012ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor 71023fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 71031af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 71041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71051bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor QualType AllocType = AllocTypeInfo->getType(); 71065b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (!ArraySize.get()) { 71075b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // If no array size was specified, but the new expression was 71085b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // instantiated with an array type (e.g., "new T" where T is 71095b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // instantiated with "int[4]"), extract the outer bound from the 71105b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // array type as our array size. We do this with constant and 71115b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // dependently-sized array types. 71125b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); 71135b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (!ArrayT) { 71145b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // Do nothing 71155b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } else if (const ConstantArrayType *ConsArrayT 71165b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor = dyn_cast<ConstantArrayType>(ArrayT)) { 7117c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ArraySize 71189996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, 71199996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis ConsArrayT->getSize(), 71209996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis SemaRef.Context.getSizeType(), 71219996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /*FIXME:*/E->getLocStart())); 71225b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor AllocType = ConsArrayT->getElementType(); 71235b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } else if (const DependentSizedArrayType *DepArrayT 71245b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor = dyn_cast<DependentSizedArrayType>(ArrayT)) { 71255b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (DepArrayT->getSizeExpr()) { 71263fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); 71275b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor AllocType = DepArrayT->getElementType(); 71285b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 71295b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 71305b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 71311bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor 7132b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXNewExpr(E->getLocStart(), 7133b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isGlobalNew(), 7134b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLocStart(), 7135b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(PlacementArgs), 7136b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLocStart(), 71374bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor E->getTypeIdParens(), 7138b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor AllocType, 71391bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocTypeInfo, 71409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ArraySize.get(), 71414e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor E->getConstructorLParen(), 7142b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(ConstructorArgs), 71434e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor E->getConstructorRParen()); 7144b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 71451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7146b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 714760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7148454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { 714960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Operand = getDerived().TransformExpr(E->getArgument()); 7150b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Operand.isInvalid()) 7151f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 71521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71531af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Transform the delete operator, if known. 71541af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorDelete = 0; 71551af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorDelete()) { 71561af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete = cast_or_null<FunctionDecl>( 71577c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 71587c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorDelete())); 71591af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorDelete) 7160f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 71611af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 7162c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7163b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 71641af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor Operand.get() == E->getArgument() && 71651af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete == E->getOperatorDelete()) { 71661af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark any declarations we need as referenced. 71671af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: instantiation-specific. 71681af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorDelete) 71691af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); 71705833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor 71715833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor if (!E->getArgument()->isTypeDependent()) { 71725833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor QualType Destroyed = SemaRef.Context.getBaseElementType( 71735833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor E->getDestroyedType()); 71745833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { 71755833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); 71765833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), 71775833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor SemaRef.LookupDestructor(Record)); 71785833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor } 71795833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor } 71805833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor 71813fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 71821af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 71831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7184b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), 7185b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isGlobalDelete(), 7186b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrayForm(), 71879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Operand.get()); 7188b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 71891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7190b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 719160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7192a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas GregorTreeTransform<Derived>::TransformCXXPseudoDestructorExpr( 7193454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXPseudoDestructorExpr *E) { 719460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 7195a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor if (Base.isInvalid()) 7196f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 71971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7198b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectTypePtr; 7199a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor bool MayBePseudoDestructor = false; 72009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), 7201a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getOperatorLoc(), 7202a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->isArrow()? tok::arrow : tok::period, 7203a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor ObjectTypePtr, 7204a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor MayBePseudoDestructor); 7205a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (Base.isInvalid()) 7206f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7207c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7208b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall QualType ObjectType = ObjectTypePtr.get(); 7209f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); 7210f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor if (QualifierLoc) { 7211f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor QualifierLoc 7212f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); 7213f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor if (!QualifierLoc) 721443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return ExprError(); 721543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } 7216f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor CXXScopeSpec SS; 7217f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SS.Adopt(QualifierLoc); 72181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7219a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed; 7220a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (E->getDestroyedTypeInfo()) { 7221a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor TypeSourceInfo *DestroyedTypeInfo 722243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), 7223b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor ObjectType, 0, SS); 7224a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (!DestroyedTypeInfo) 7225f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7226a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed = DestroyedTypeInfo; 72276b18e740495b67b439fa366367242110365cc4d9Douglas Gregor } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { 7228a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // We aren't likely to be able to resolve the identifier down to a type 7229a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // now anyway, so just retain the identifier. 7230a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), 7231a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc()); 7232a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } else { 7233a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // Look for a destructor known with the given name. 7234b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), 7235a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor *E->getDestroyedTypeIdentifier(), 7236a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc(), 7237a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /*Scope=*/0, 7238a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor SS, ObjectTypePtr, 7239a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor false); 7240a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (!T) 7241f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7242c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7243a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed 7244a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), 7245a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc()); 7246a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 724726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor 724826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor TypeSourceInfo *ScopeTypeInfo = 0; 724926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor if (E->getScopeTypeInfo()) { 725043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo()); 725126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor if (!ScopeTypeInfo) 7252f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7253a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor } 7254c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 72559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), 7256a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor E->getOperatorLoc(), 7257a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor E->isArrow(), 7258f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SS, 725926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor ScopeTypeInfo, 726026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor E->getColonColonLoc(), 7261fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor E->getTildeLoc(), 7262a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed); 7263a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor} 72641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7265a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregortemplate<typename Derived> 726660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7267ba13543329afac4a0d01304ec2ec4924d99306a6John McCallTreeTransform<Derived>::TransformUnresolvedLookupExpr( 7268454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall UnresolvedLookupExpr *Old) { 7269f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), 7270f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall Sema::LookupOrdinaryName); 7271f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7272f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Transform all the decls. 7273f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), 7274f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall E = Old->decls_end(); I != E; ++I) { 72757c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor NamedDecl *InstD = static_cast<NamedDecl*>( 72767c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(Old->getNameLoc(), 72777c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor *I)); 72789f54ad4381370c6b771424b53d219e661d6d6706John McCall if (!InstD) { 72799f54ad4381370c6b771424b53d219e661d6d6706John McCall // Silently ignore these if a UsingShadowDecl instantiated to nothing. 72809f54ad4381370c6b771424b53d219e661d6d6706John McCall // This can happen because of dependent hiding. 72819f54ad4381370c6b771424b53d219e661d6d6706John McCall if (isa<UsingShadowDecl>(*I)) 72829f54ad4381370c6b771424b53d219e661d6d6706John McCall continue; 72839f54ad4381370c6b771424b53d219e661d6d6706John McCall else 7284f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 72859f54ad4381370c6b771424b53d219e661d6d6706John McCall } 7286f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7287f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Expand using declarations. 7288f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (isa<UsingDecl>(InstD)) { 7289f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall UsingDecl *UD = cast<UsingDecl>(InstD); 7290f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall for (UsingDecl::shadow_iterator I = UD->shadow_begin(), 7291f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall E = UD->shadow_end(); I != E; ++I) 7292f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.addDecl(*I); 7293f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall continue; 7294f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 7295f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7296f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.addDecl(InstD); 7297f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 7298f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7299f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Resolve a kind, but don't do any further analysis. If it's 7300f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // ambiguous, the callee needs to deal with it. 7301f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.resolveKind(); 7302f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7303f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Rebuild the nested-name qualifier, if present. 7304f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall CXXScopeSpec SS; 73054c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (Old->getQualifierLoc()) { 73064c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc 73074c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); 73084c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (!QualifierLoc) 7309f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7310c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 73114c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor SS.Adopt(QualifierLoc); 7312c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt } 7313c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7314c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor if (Old->getNamingClass()) { 731566c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor CXXRecordDecl *NamingClass 731666c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( 731766c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNameLoc(), 731866c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNamingClass())); 731966c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor if (!NamingClass) 7320f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7321c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 732266c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor R.setNamingClass(NamingClass); 7323f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 7324f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7325f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // If we have no template arguments, it's a normal declaration name. 7326f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!Old->hasExplicitTemplateArgs()) 7327f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); 7328f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7329f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // If we have template arguments, rebuild them, then rebuild the 7330f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // templateid expression. 7331f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); 7332fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), 7333fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor Old->getNumTemplateArgs(), 7334fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7335fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 7336f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7337f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), 7338f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall TransArgs); 7339b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 73401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7341b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 734260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7343454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { 73443d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); 73453d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor if (!T) 7346f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 73471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7348b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 73493d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor T == E->getQueriedTypeSourceInfo()) 73503fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 73511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 73521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildUnaryTypeTrait(E->getTrait(), 7353b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocStart(), 7354b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T, 7355b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 7356b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 73571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7358b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 735960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 73606ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetTreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { 73616ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); 73626ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!LhsT) 73636ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return ExprError(); 73646ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 73656ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); 73666ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!RhsT) 73676ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return ExprError(); 73686ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 73696ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!getDerived().AlwaysRebuild() && 73706ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) 73716ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return SemaRef.Owned(E); 73726ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 73736ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return getDerived().RebuildBinaryTypeTrait(E->getTrait(), 73746ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet E->getLocStart(), 73756ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet LhsT, RhsT, 73766ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet E->getLocEnd()); 73776ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet} 73786ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 73796ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichettemplate<typename Derived> 73806ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetExprResult 738121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John WiegleyTreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { 738221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); 738321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (!T) 738421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return ExprError(); 738521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 738621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (!getDerived().AlwaysRebuild() && 738721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley T == E->getQueriedTypeSourceInfo()) 738821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return SemaRef.Owned(E); 738921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 739021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ExprResult SubExpr; 739121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley { 739221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 739321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); 739421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (SubExpr.isInvalid()) 739521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return ExprError(); 739621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 739721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) 739821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return SemaRef.Owned(E); 739921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 740021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 740121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return getDerived().RebuildArrayTypeTrait(E->getTrait(), 740221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley E->getLocStart(), 740321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley T, 740421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SubExpr.get(), 740521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley E->getLocEnd()); 740621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley} 740721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 740821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleytemplate<typename Derived> 740921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John WiegleyExprResult 7410552622067dc45013d240f73952fece703f5e63bdJohn WiegleyTreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { 7411552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExprResult SubExpr; 7412552622067dc45013d240f73952fece703f5e63bdJohn Wiegley { 7413552622067dc45013d240f73952fece703f5e63bdJohn Wiegley EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 7414552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); 7415552622067dc45013d240f73952fece703f5e63bdJohn Wiegley if (SubExpr.isInvalid()) 7416552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return ExprError(); 7417552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 7418552622067dc45013d240f73952fece703f5e63bdJohn Wiegley if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) 7419552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return SemaRef.Owned(E); 7420552622067dc45013d240f73952fece703f5e63bdJohn Wiegley } 7421552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 7422552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return getDerived().RebuildExpressionTrait( 7423552622067dc45013d240f73952fece703f5e63bdJohn Wiegley E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); 7424552622067dc45013d240f73952fece703f5e63bdJohn Wiegley} 7425552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 7426552622067dc45013d240f73952fece703f5e63bdJohn Wiegleytemplate<typename Derived> 7427552622067dc45013d240f73952fece703f5e63bdJohn WiegleyExprResult 7428865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformDependentScopeDeclRefExpr( 74292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DependentScopeDeclRefExpr *E) { 743000cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc 743100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 743200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor if (!QualifierLoc) 7433f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 74341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 743543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // TODO: If this is a conversion-function-id, verify that the 743643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // destination type name (if present) resolves the same way after 743743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // instantiation as it did in the local scope. 743843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 74392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo 74402577743c5650c646fb705df01403707e94f2df04Abramo Bagnara = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); 74412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!NameInfo.getName()) 7442f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 74431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7444f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!E->hasExplicitTemplateArgs()) { 7445f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!getDerived().AlwaysRebuild() && 744600cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor QualifierLoc == E->getQualifierLoc() && 74472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // Note: it is sufficient to compare the Name component of NameInfo: 74482577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // if name has not changed, DNLoc has not changed either. 74492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getDeclName()) 74503fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 74511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 745200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, 74532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7454f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /*TemplateArgs*/ 0); 7455f17bb74e74aca9bb0525d2249041ab65c7d1fd48Douglas Gregor } 7456d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 7457d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); 7458fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 7459fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 7460fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7461fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 7462b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 746300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, 74642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7465f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall &TransArgs); 7466b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7467b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7468b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 746960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7470454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { 7471321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor // CXXConstructExprs are always implicit, so when we have a 7472321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor // 1-argument construction we just transform that argument. 7473321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor if (E->getNumArgs() == 1 || 7474321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) 7475321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor return getDerived().TransformExpr(E->getArg(0)); 7476321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor 7477b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); 7478b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7479b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor QualType T = getDerived().TransformType(E->getType()); 7480b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (T.isNull()) 7481f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7482b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7483b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXConstructorDecl *Constructor 7484b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = cast_or_null<CXXConstructorDecl>( 74857c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 74867c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 7487b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Constructor) 7488f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 74891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7490b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 7491ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 7492aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 7493aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 7494aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 7495aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 7496b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7497b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T == E->getType() && 7498b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Constructor == E->getConstructor() && 7499c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor !ArgumentChanged) { 75001af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark the constructor as referenced. 75011af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: Instantiation-specific 7502c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); 75033fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7504c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor } 75051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 75064411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), 75074411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor Constructor, E->isElidable(), 75088c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor move_arg(Args), 75097cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara E->hadMultipleCandidates(), 75108c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor E->requiresZeroInitialization(), 7511428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth E->getConstructionKind(), 7512428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth E->getParenRange()); 7513b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 75141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7515b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform a C++ temporary-binding expression. 7516b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 75175132655e4296b780672e9a96b46a740135073534Douglas Gregor/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just 75185132655e4296b780672e9a96b46a740135073534Douglas Gregor/// transform the subexpression and return that. 7519b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 752060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7521454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { 75225132655e4296b780672e9a96b46a740135073534Douglas Gregor return getDerived().TransformExpr(E->getSubExpr()); 7523b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 75241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 75254765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// \brief Transform a C++ expression that contains cleanups that should 75264765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// be run after the expression is evaluated. 7527b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 75284765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Since ExprWithCleanups nodes are implicitly generated, we 75295132655e4296b780672e9a96b46a740135073534Douglas Gregor/// just transform the subexpression and return that. 7530b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 753160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 75324765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallTreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { 75335132655e4296b780672e9a96b46a740135073534Douglas Gregor return getDerived().TransformExpr(E->getSubExpr()); 7534b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 75351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7536b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 753760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7538b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXTemporaryObjectExpr( 7539ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXTemporaryObjectExpr *E) { 7540ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 7541ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 7542f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 75431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7544b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXConstructorDecl *Constructor 7545b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = cast_or_null<CXXConstructorDecl>( 7546c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt getDerived().TransformDecl(E->getLocStart(), 75477c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 7548b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Constructor) 7549f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 75501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7551b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 7552ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 7553b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Args.reserve(E->getNumArgs()); 7554aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 7555aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 7556aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 75571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7558b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7559ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo() && 7560b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Constructor == E->getConstructor() && 756191be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor !ArgumentChanged) { 756291be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor // FIXME: Instantiation-specific 7563ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); 75643fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.MaybeBindToTemporary(E); 756591be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor } 7566ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor 7567ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXTemporaryObjectExpr(T, 7568ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /*FIXME:*/T->getTypeLoc().getEndLoc(), 7569b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Args), 7570b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 7571b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 75721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7573b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 757460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7575b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( 7576454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXUnresolvedConstructExpr *E) { 7577ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 7578ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 7579f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 75801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7581b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 7582ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 7583aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args.reserve(E->arg_size()); 7584aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, 7585aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 7586aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 7587aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 7588b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7589ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo() && 7590b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgumentChanged) 75913fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 75921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7593b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: we're faking the locations of the commas 7594ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXUnresolvedConstructExpr(T, 7595b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLParenLoc(), 7596b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Args), 7597b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 7598b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 75991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7600b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 760160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7602865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( 76032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara CXXDependentScopeMemberExpr *E) { 7604b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the base of the expression. 760560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base((Expr*) 0); 7606aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *OldBase; 7607aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType; 7608aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType ObjectType; 7609aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!E->isImplicitAccess()) { 7610aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OldBase = E->getBase(); 7611aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base = getDerived().TransformExpr(OldBase); 7612aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 7613f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 76141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7615aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall // Start the member reference and compute the object's type. 7616b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectTy; 7617d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor bool MayBePseudoDestructor = false; 76189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), 7619aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall E->getOperatorLoc(), 7620a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor E->isArrow()? tok::arrow : tok::period, 7621d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor ObjectTy, 7622d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor MayBePseudoDestructor); 7623aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 7624f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7625aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 7626b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ObjectType = ObjectTy.get(); 7627aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = ((Expr*) Base.get())->getType(); 7628aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } else { 7629aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OldBase = 0; 7630aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = getDerived().TransformType(E->getBaseType()); 7631aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); 7632aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 76331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76346cd219879ffce00920189ec1dcea927a42602961Douglas Gregor // Transform the first part of the nested-name-specifier that qualifies 76356cd219879ffce00920189ec1dcea927a42602961Douglas Gregor // the member name. 7636c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor NamedDecl *FirstQualifierInScope 76376cd219879ffce00920189ec1dcea927a42602961Douglas Gregor = getDerived().TransformFirstQualifierInScope( 76387c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor E->getFirstQualifierFoundInScope(), 76397c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor E->getQualifierLoc().getBeginLoc()); 76401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76417c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 7642a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor if (E->getQualifier()) { 76437c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc 76447c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), 76457c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor ObjectType, 76467c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor FirstQualifierInScope); 76477c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor if (!QualifierLoc) 7648f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7649a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor } 76501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 765143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // TODO: If this is a conversion-function-id, verify that the 765243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // destination type name (if present) resolves the same way after 765343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // instantiation as it did in the local scope. 765443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 76552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo 765643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); 76572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!NameInfo.getName()) 7658f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 76591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7660aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!E->hasExplicitTemplateArgs()) { 76613b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor // This is a reference to a member without an explicitly-specified 76623b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor // template argument list. Optimize for this common case. 76633b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor if (!getDerived().AlwaysRebuild() && 7664aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base.get() == OldBase && 7665aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType == E->getBaseType() && 76667c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc == E->getQualifierLoc() && 76672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getMember() && 76683b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor FirstQualifierInScope == E->getFirstQualifierFoundInScope()) 76693fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 76701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), 7672aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 76733b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor E->isArrow(), 76743b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor E->getOperatorLoc(), 76757c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc, 7676129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall FirstQualifierInScope, 76772577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7678129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /*TemplateArgs*/ 0); 76793b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 76803b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor 7681d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); 7682fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 7683fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 7684fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7685fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 76861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), 7688aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 7689b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrow(), 7690b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOperatorLoc(), 76917c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc, 76923b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor FirstQualifierInScope, 76932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7694129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall &TransArgs); 7695129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall} 7696129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7697129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCalltemplate<typename Derived> 769860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7699454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { 7700129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Transform the base of the expression. 770160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base((Expr*) 0); 7702aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType; 7703aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!Old->isImplicitAccess()) { 7704aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base = getDerived().TransformExpr(Old->getBase()); 7705aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 7706f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 77079138b4e96429cbaae00c52c15c960f72b6645088Richard Smith Base = getSema().PerformMemberExprBaseConversion(Base.take(), 77089138b4e96429cbaae00c52c15c960f72b6645088Richard Smith Old->isArrow()); 77099138b4e96429cbaae00c52c15c960f72b6645088Richard Smith if (Base.isInvalid()) 77109138b4e96429cbaae00c52c15c960f72b6645088Richard Smith return ExprError(); 77119138b4e96429cbaae00c52c15c960f72b6645088Richard Smith BaseType = Base.get()->getType(); 7712aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } else { 7713aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = getDerived().TransformType(Old->getBaseType()); 7714aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 7715129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 77164c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 77174c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (Old->getQualifierLoc()) { 77184c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor QualifierLoc 77194c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); 77204c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (!QualifierLoc) 7721f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7722129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 7723129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 77242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LookupResult R(SemaRef, Old->getMemberNameInfo(), 7725129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Sema::LookupOrdinaryName); 7726129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7727129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Transform all the decls. 7728129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), 7729129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall E = Old->decls_end(); I != E; ++I) { 77307c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor NamedDecl *InstD = static_cast<NamedDecl*>( 77317c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(Old->getMemberLoc(), 77327c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor *I)); 77339f54ad4381370c6b771424b53d219e661d6d6706John McCall if (!InstD) { 77349f54ad4381370c6b771424b53d219e661d6d6706John McCall // Silently ignore these if a UsingShadowDecl instantiated to nothing. 77359f54ad4381370c6b771424b53d219e661d6d6706John McCall // This can happen because of dependent hiding. 77369f54ad4381370c6b771424b53d219e661d6d6706John McCall if (isa<UsingShadowDecl>(*I)) 77379f54ad4381370c6b771424b53d219e661d6d6706John McCall continue; 773834f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis else { 773934f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis R.clear(); 7740f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 774134f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis } 77429f54ad4381370c6b771424b53d219e661d6d6706John McCall } 7743129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7744129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Expand using declarations. 7745129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (isa<UsingDecl>(InstD)) { 7746129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall UsingDecl *UD = cast<UsingDecl>(InstD); 7747129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall for (UsingDecl::shadow_iterator I = UD->shadow_begin(), 7748129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall E = UD->shadow_end(); I != E; ++I) 7749129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.addDecl(*I); 7750129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall continue; 7751129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 7752129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7753129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.addDecl(InstD); 7754129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 7755129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7756129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.resolveKind(); 7757129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7758c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor // Determine the naming class. 7759042d6f98ea73d781e43cc17077e8fc84a4201eefChandler Carruth if (Old->getNamingClass()) { 7760c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt CXXRecordDecl *NamingClass 7761c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( 776266c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getMemberLoc(), 776366c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNamingClass())); 776466c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor if (!NamingClass) 7765f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7766c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 776766c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor R.setNamingClass(NamingClass); 7768c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor } 7769c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7770129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TemplateArgumentListInfo TransArgs; 7771129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (Old->hasExplicitTemplateArgs()) { 7772129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TransArgs.setLAngleLoc(Old->getLAngleLoc()); 7773129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TransArgs.setRAngleLoc(Old->getRAngleLoc()); 7774fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), 7775fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor Old->getNumTemplateArgs(), 7776fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7777fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 7778129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 7779c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 7780c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // FIXME: to do this check properly, we will need to preserve the 7781c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // first-qualifier-in-scope here, just in case we had a dependent 7782c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // base (and therefore couldn't do the check) and a 7783c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // nested-name-qualifier (and therefore could do the lookup). 7784c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall NamedDecl *FirstQualifierInScope = 0; 7785c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 77869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildUnresolvedMemberExpr(Base.get(), 7787aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 7788129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Old->getOperatorLoc(), 7789129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Old->isArrow(), 77904c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor QualifierLoc, 7791c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall FirstQualifierInScope, 7792129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R, 7793129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall (Old->hasExplicitTemplateArgs() 7794129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall ? &TransArgs : 0)); 7795b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7796b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7797b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 779860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 77992e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlTreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { 7800eea06c609b73afc7bcfdf3e101efb8d9e7b3560cSean Hunt EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 78012e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); 78022e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl if (SubExpr.isInvalid()) 78032e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return ExprError(); 78042e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 78052e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) 78063fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 78072e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 78082e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); 78092e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl} 78102e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 78112e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redltemplate<typename Derived> 78122e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlExprResult 7813be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorTreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { 78144f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); 78154f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor if (Pattern.isInvalid()) 78164f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor return ExprError(); 78174f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor 78184f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) 78194f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor return SemaRef.Owned(E); 78204f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor 782167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), 782267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor E->getNumExpansions()); 7823be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor} 7824ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 7825ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregortemplate<typename Derived> 7826ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorExprResult 7827ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorTreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { 7828ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // If E is not value-dependent, then nothing will change when we transform it. 7829ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // Note: This is an instantiation-centric view. 7830ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor if (!E->isValueDependent()) 7831ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return SemaRef.Owned(E); 7832ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 7833ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // Note: None of the implementations of TryExpandParameterPacks can ever 7834ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // produce a diagnostic when given only a single unexpanded parameter pack, 7835ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // so 7836ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); 7837ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor bool ShouldExpand = false; 7838d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 7839cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions; 7840ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), 7841a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 7842d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ShouldExpand, RetainExpansion, 7843d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) 7844ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return ExprError(); 7845ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 7846089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor if (RetainExpansion) 7847ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return SemaRef.Owned(E); 7848089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor 7849089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor NamedDecl *Pack = E->getPack(); 7850089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor if (!ShouldExpand) { 7851089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(), 7852089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor Pack)); 7853089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor if (!Pack) 7854089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor return ExprError(); 7855089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor } 7856089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor 7857be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 7858ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // We now know the length of the parameter pack, so build a new expression 7859ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // that stores that length. 7860089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, 7861ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor E->getPackLoc(), E->getRParenLoc(), 7862089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor NumExpansions); 7863ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor} 7864ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 7865be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregortemplate<typename Derived> 7866be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorExprResult 7867c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorTreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( 7868c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor SubstNonTypeTemplateParmPackExpr *E) { 7869c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor // Default behavior is to do nothing with this transformation. 787091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return SemaRef.Owned(E); 787191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall} 787291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 787391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCalltemplate<typename Derived> 787491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallExprResult 787591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallTreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( 787691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall SubstNonTypeTemplateParmExpr *E) { 787791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall // Default behavior is to do nothing with this transformation. 7878c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor return SemaRef.Owned(E); 7879c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor} 7880c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor 7881c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregortemplate<typename Derived> 7882c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorExprResult 788303e80030515c800d1ab44125b9052dfffd1bd04cDouglas GregorTreeTransform<Derived>::TransformMaterializeTemporaryExpr( 788403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor MaterializeTemporaryExpr *E) { 788503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return getDerived().TransformExpr(E->GetTemporaryExpr()); 788603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor} 788703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 788803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregortemplate<typename Derived> 788903e80030515c800d1ab44125b9052dfffd1bd04cDouglas GregorExprResult 7890454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { 78913fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7892b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7893b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 78941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 789560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7896454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { 789781d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *EncodedTypeInfo 789881d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor = getDerived().TransformType(E->getEncodedTypeSourceInfo()); 789981d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor if (!EncodedTypeInfo) 7900f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 79011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7902b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 790381d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedTypeInfo == E->getEncodedTypeSourceInfo()) 79043fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7905b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7906b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), 790781d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedTypeInfo, 7908b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 7909b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 79101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7911b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 7912f85e193739c953358c865005855253af4f68a497John McCallExprResult TreeTransform<Derived>:: 7913f85e193739c953358c865005855253af4f68a497John McCallTransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { 7914f85e193739c953358c865005855253af4f68a497John McCall ExprResult result = getDerived().TransformExpr(E->getSubExpr()); 7915f85e193739c953358c865005855253af4f68a497John McCall if (result.isInvalid()) return ExprError(); 7916f85e193739c953358c865005855253af4f68a497John McCall Expr *subExpr = result.take(); 7917f85e193739c953358c865005855253af4f68a497John McCall 7918f85e193739c953358c865005855253af4f68a497John McCall if (!getDerived().AlwaysRebuild() && 7919f85e193739c953358c865005855253af4f68a497John McCall subExpr == E->getSubExpr()) 7920f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(E); 7921f85e193739c953358c865005855253af4f68a497John McCall 7922f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(new(SemaRef.Context) 7923f85e193739c953358c865005855253af4f68a497John McCall ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy())); 7924f85e193739c953358c865005855253af4f68a497John McCall} 7925f85e193739c953358c865005855253af4f68a497John McCall 7926f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived> 7927f85e193739c953358c865005855253af4f68a497John McCallExprResult TreeTransform<Derived>:: 7928f85e193739c953358c865005855253af4f68a497John McCallTransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { 7929f85e193739c953358c865005855253af4f68a497John McCall TypeSourceInfo *TSInfo 7930f85e193739c953358c865005855253af4f68a497John McCall = getDerived().TransformType(E->getTypeInfoAsWritten()); 7931f85e193739c953358c865005855253af4f68a497John McCall if (!TSInfo) 7932f85e193739c953358c865005855253af4f68a497John McCall return ExprError(); 7933f85e193739c953358c865005855253af4f68a497John McCall 7934f85e193739c953358c865005855253af4f68a497John McCall ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); 7935f85e193739c953358c865005855253af4f68a497John McCall if (Result.isInvalid()) 7936f85e193739c953358c865005855253af4f68a497John McCall return ExprError(); 7937f85e193739c953358c865005855253af4f68a497John McCall 7938f85e193739c953358c865005855253af4f68a497John McCall if (!getDerived().AlwaysRebuild() && 7939f85e193739c953358c865005855253af4f68a497John McCall TSInfo == E->getTypeInfoAsWritten() && 7940f85e193739c953358c865005855253af4f68a497John McCall Result.get() == E->getSubExpr()) 7941f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(E); 7942f85e193739c953358c865005855253af4f68a497John McCall 7943f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), 7944f85e193739c953358c865005855253af4f68a497John McCall E->getBridgeKeywordLoc(), TSInfo, 7945f85e193739c953358c865005855253af4f68a497John McCall Result.get()); 7946f85e193739c953358c865005855253af4f68a497John McCall} 7947f85e193739c953358c865005855253af4f68a497John McCall 7948f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived> 794960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7950454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { 795192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Transform arguments. 795292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor bool ArgChanged = false; 7953ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 7954aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args.reserve(E->getNumArgs()); 7955aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, 7956aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgChanged)) 7957aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 7958aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 795992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (E->getReceiverKind() == ObjCMessageExpr::Class) { 796092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Class message: transform the receiver type. 796192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor TypeSourceInfo *ReceiverTypeInfo 796292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor = getDerived().TransformType(E->getClassReceiverTypeInfo()); 796392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!ReceiverTypeInfo) 7964f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7965c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 796692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // If nothing changed, just retain the existing message send. 796792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!getDerived().AlwaysRebuild() && 796892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) 79693fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 797092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 797192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Build a new class message send. 7972207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SmallVector<SourceLocation, 16> SelLocs; 7973207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis E->getSelectorLocs(SelLocs); 797492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, 797592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getSelector(), 7976207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocs, 797792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getMethodDecl(), 797892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getLeftLoc(), 797992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor move_arg(Args), 798092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getRightLoc()); 798192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 798292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 798392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Instance message: transform the receiver 798492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor assert(E->getReceiverKind() == ObjCMessageExpr::Instance && 798592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor "Only class and instance messages may be instantiated"); 798660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Receiver 798792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor = getDerived().TransformExpr(E->getInstanceReceiver()); 798892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (Receiver.isInvalid()) 7989f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 799092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 799192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // If nothing changed, just retain the existing message send. 799292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!getDerived().AlwaysRebuild() && 799392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Receiver.get() == E->getInstanceReceiver() && !ArgChanged) 79943fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7995c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 799692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Build a new instance message send. 7997207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SmallVector<SourceLocation, 16> SelLocs; 7998207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis E->getSelectorLocs(SelLocs); 79999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCMessageExpr(Receiver.get(), 800092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getSelector(), 8001207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocs, 800292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getMethodDecl(), 800392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getLeftLoc(), 800492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor move_arg(Args), 800592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getRightLoc()); 8006b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8007b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 80081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 800960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8010454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { 80113fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8012b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8013b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 80141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 801560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8016454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { 80173fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8018b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8019b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 80201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 802160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8022454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { 8023f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // Transform the base expression. 802460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 8025f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Base.isInvalid()) 8026f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8027f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor 8028f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // We don't need to transform the ivar; it will never change. 8029c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8030f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // If nothing changed, just retain the existing expression. 8031f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (!getDerived().AlwaysRebuild() && 8032f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Base.get() == E->getBase()) 80333fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8034c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 80359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), 8036f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->getLocation(), 8037f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->isArrow(), E->isFreeIvar()); 8038b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8039b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 80401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 804160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8042454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { 804312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // 'super' and types never change. Property never changes. Just 804412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // retain the existing expression. 804512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (!E->isObjectReceiver()) 80463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 80478ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian 8048e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // Transform the base expression. 804960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 8050e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (Base.isInvalid()) 8051f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8052c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8053e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // We don't need to transform the property; it will never change. 8054c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8055e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // If nothing changed, just retain the existing expression. 8056e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (!getDerived().AlwaysRebuild() && 8057e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor Base.get() == E->getBase()) 80583fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8059b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 806012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (E->isExplicitProperty()) 806112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getDerived().RebuildObjCPropertyRefExpr(Base.get(), 806212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getExplicitProperty(), 806312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getLocation()); 806412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 806512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getDerived().RebuildObjCPropertyRefExpr(Base.get(), 80663c3b7f90a863af43fa63043d396553ecf205351cJohn McCall SemaRef.Context.PseudoObjectTy, 806712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getImplicitPropertyGetter(), 806812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getImplicitPropertySetter(), 806912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getLocation()); 8070b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8071b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 80721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 807360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8074454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { 8075f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // Transform the base expression. 807660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 8077f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Base.isInvalid()) 8078f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8079c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8080f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // If nothing changed, just retain the existing expression. 8081f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (!getDerived().AlwaysRebuild() && 8082f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Base.get() == E->getBase()) 80833fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8084c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 80859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), 8086f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->isArrow()); 8087b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8088b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 80891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 809060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8091454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { 8092b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 8093ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> SubExprs(SemaRef); 8094aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor SubExprs.reserve(E->getNumSubExprs()); 8095aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, 8096aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor SubExprs, &ArgumentChanged)) 8097aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 80981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8099b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 8100b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgumentChanged) 81013fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 81021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8103b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), 8104b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(SubExprs), 8105b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 8106b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8107b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 81081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 810960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8110454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { 8111c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall BlockDecl *oldBlock = E->getBlockDecl(); 8112a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 8113c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); 8114c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall BlockScopeInfo *blockScope = SemaRef.getCurBlock(); 8115c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 8116c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); 8117ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian // We built a new blockScopeInfo in call to ActOnBlockStart 8118ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian // in above, CapturesCXXThis need be set here from the block 8119ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian // expression. 8120ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian blockScope->CapturesCXXThis = oldBlock->capturesCXXThis(); 8121ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian 8122686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<ParmVarDecl*, 4> params; 8123686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<QualType, 4> paramTypes; 8124a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 8125a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian // Parameter substitution. 8126c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), 8127c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldBlock->param_begin(), 8128c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldBlock->param_size(), 8129c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 0, paramTypes, ¶ms)) 8130a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor return true; 8131c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 8132c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall const FunctionType *exprFunctionType = E->getFunctionType(); 8133c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall QualType exprResultType = exprFunctionType->getResultType(); 8134c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (!exprResultType.isNull()) { 8135c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (!exprResultType->isDependentType()) 8136c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->ReturnType = exprResultType; 8137c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall else if (exprResultType != getSema().Context.DependentTy) 8138c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->ReturnType = getDerived().TransformType(exprResultType); 8139a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian } 8140a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 8141a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // If the return type has not been determined yet, leave it as a dependent 8142a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // type; it'll get set when we process the body. 8143c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (blockScope->ReturnType.isNull()) 8144c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->ReturnType = getSema().Context.DependentTy; 8145a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 8146a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // Don't allow returning a objc interface by value. 8147c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (blockScope->ReturnType->isObjCObjectType()) { 8148c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall getSema().Diag(E->getCaretLocation(), 8149a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor diag::err_object_cannot_be_passed_returned_by_value) 8150c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall << 0 << blockScope->ReturnType; 8151a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor return ExprError(); 8152a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor } 8153711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 8154c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall QualType functionType = getDerived().RebuildFunctionProtoType( 8155c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->ReturnType, 8156c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall paramTypes.data(), 8157c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall paramTypes.size(), 8158c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldBlock->isVariadic(), 8159c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 0, RQ_None, 8160c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall exprFunctionType->getExtInfo()); 8161c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->FunctionType = functionType; 8162711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 8163711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Set the parameters on the block decl. 8164c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (!params.empty()) 81654278c654b645402554eb52a48e9c7097c9f1233aDavid Blaikie blockScope->TheDecl->setParams(params); 8166a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 8167a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // If the return type wasn't explicitly set, it will have been marked as a 8168a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // dependent type (DependentTy); clear out the return type setting so 8169a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // we will deduce the return type when type-checking the block's body. 8170c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (blockScope->ReturnType == getSema().Context.DependentTy) 8171c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->ReturnType = QualType(); 8172a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 8173711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Transform the body 8174c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall StmtResult body = getDerived().TransformStmt(E->getBody()); 8175c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (body.isInvalid()) 8176711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return ExprError(); 8177711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 8178c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#ifndef NDEBUG 8179c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall // In builds with assertions, make sure that we captured everything we 8180c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall // captured before. 8181fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor if (!SemaRef.getDiagnostics().hasErrorOccurred()) { 8182fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), 8183fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor e = oldBlock->capture_end(); i != e; ++i) { 8184fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor VarDecl *oldCapture = i->getVariable(); 8185fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor 8186fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor // Ignore parameter packs. 8187fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor if (isa<ParmVarDecl>(oldCapture) && 8188fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor cast<ParmVarDecl>(oldCapture)->isParameterPack()) 8189fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor continue; 8190c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 8191fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor VarDecl *newCapture = 8192fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), 8193fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor oldCapture)); 8194fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor assert(blockScope->CaptureMap.count(newCapture)); 8195fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor } 8196c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall } 8197c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#endif 8198c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 8199c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), 8200c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall /*Scope=*/0); 8201b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8202b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 82031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 820460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8205454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { 8206a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian ValueDecl *ND 8207a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), 8208a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian E->getDecl())); 8209a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian if (!ND) 8210f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 82112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 8212a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian if (!getDerived().AlwaysRebuild() && 8213a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian ND == E->getDecl()) { 8214a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian // Mark it referenced in the new context regardless. 8215a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian // FIXME: this is a bit instantiation-specific. 8216a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); 8217a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 82183fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8219a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian } 8220a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 82212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation()); 822240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(), 82232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ND, NameInfo, 0); 8224b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 82251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 822661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnertemplate<typename Derived> 822761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya LattnerExprResult 822861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya LattnerTreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { 8229b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Cannot transform asType expressions yet"); 823061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner} 8231276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 8232276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmantemplate<typename Derived> 8233276b061970939293f1abaf694bd3ef05b2cbda79Eli FriedmanExprResult 8234276b061970939293f1abaf694bd3ef05b2cbda79Eli FriedmanTreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { 8235dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman QualType RetTy = getDerived().TransformType(E->getType()); 8236dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman bool ArgumentChanged = false; 8237dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ASTOwningVector<Expr*> SubExprs(SemaRef); 8238dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman SubExprs.reserve(E->getNumSubExprs()); 8239dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, 8240dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman SubExprs, &ArgumentChanged)) 8241dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman return ExprError(); 8242dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 8243dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (!getDerived().AlwaysRebuild() && 8244dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman !ArgumentChanged) 8245dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman return SemaRef.Owned(E); 8246dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 8247dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs), 8248dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman RetTy, E->getOp(), E->getRParenLoc()); 8249276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman} 825061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 8251b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===// 8252b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Type reconstruction 8253b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===// 8254b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 82551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 825685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, 825785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Star) { 82582865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildPointerType(PointeeType, Star, 8259b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor getDerived().getBaseEntity()); 8260b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8261b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 82621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 826385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, 826485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Star) { 82652865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildBlockPointerType(PointeeType, Star, 8266b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor getDerived().getBaseEntity()); 8267b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8268b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 82691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 82701eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 827185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, 827285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall bool WrittenAsLValue, 827385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil) { 82742865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, 827585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Sigil, getDerived().getBaseEntity()); 8276b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8277b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 82781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 82791eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 828085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, 828185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType ClassType, 828285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil) { 82832865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildMemberPointerType(PointeeType, ClassType, 828485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Sigil, getDerived().getBaseEntity()); 8285577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8286577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8287577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 82881eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 8289577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorTreeTransform<Derived>::RebuildArrayType(QualType ElementType, 8290577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 8291577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt *Size, 8292577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Expr *SizeExpr, 8293577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 8294577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 8295577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (SizeExpr || !Size) 8296577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, 8297577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange, 8298577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor getDerived().getBaseEntity()); 82991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 83001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Types[] = { 83011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, 83021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, 83031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty 8304577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor }; 8305577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const unsigned NumTypes = sizeof(Types) / sizeof(QualType); 8306577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType SizeType; 8307577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor for (unsigned I = 0; I != NumTypes; ++I) 8308577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { 8309577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SizeType = Types[I]; 8310577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor break; 8311577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 83121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 83139996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType, 83149996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /*FIXME*/BracketsRange.getBegin()); 83151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, 8316577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange, 83171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getDerived().getBaseEntity()); 8318577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 83191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8320577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 83211eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 83221eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, 8323577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 8324577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt &Size, 832585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 832685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange) { 83271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, 832885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall IndexTypeQuals, BracketsRange); 8329577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8330577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8331577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 83321eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 83331eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, 8334577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 833585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 833685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange) { 83371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, 833885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall IndexTypeQuals, BracketsRange); 8339577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 83401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8341577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 83421eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 83431eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, 8344577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 83459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 8346577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 8347577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 83481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 83499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SizeExpr, 8350577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange); 8351577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8352577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8353577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 83541eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 83551eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, 8356577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 83579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 8358577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 8359577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 83601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 83619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SizeExpr, 8362577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange); 8363577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8364577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8365577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8366577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, 8367e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson unsigned NumElements, 8368e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::VectorKind VecKind) { 8369577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor // FIXME: semantic checking! 8370e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); 8371577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 83721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8373577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8374577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, 8375577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumElements, 8376577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc) { 8377577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), 8378577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor NumElements, true); 8379577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IntegerLiteral *VectorSize 83809996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, 83819996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis AttributeLoc); 83829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); 8383577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 83841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8385577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 83861eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 83871eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, 83889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 8389577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc) { 83909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); 8391577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 83921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8393577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8394577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, 83951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType *ParamTypes, 8396577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumParamTypes, 83971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool Variadic, 8398fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman unsigned Quals, 8399c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind RefQualifier, 8400fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman const FunctionType::ExtInfo &Info) { 84011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, 8402c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor Quals, RefQualifier, 8403577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor getDerived().getBaseLocation(), 8404fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman getDerived().getBaseEntity(), 8405fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman Info); 8406577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 84071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8408577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8409a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { 8410a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return SemaRef.Context.getFunctionNoProtoType(T); 8411a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 8412a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 8413a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 8414ed97649e9574b9d854fa4d6109c9333ae0993554John McCallQualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { 8415ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(D && "no decl found"); 8416ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (D->isInvalidDecl()) return QualType(); 8417ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 841892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // FIXME: Doesn't account for ObjCInterfaceDecl! 8419ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TypeDecl *Ty; 8420ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (isa<UsingDecl>(D)) { 8421ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UsingDecl *Using = cast<UsingDecl>(D); 8422ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(Using->isTypeName() && 8423ed97649e9574b9d854fa4d6109c9333ae0993554John McCall "UnresolvedUsingTypenameDecl transformed to non-typename using"); 8424ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 8425ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // A valid resolved using typename decl points to exactly one type decl. 8426ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(++Using->shadow_begin() == Using->shadow_end()); 8427ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); 8428c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8429ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } else { 8430ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(isa<UnresolvedUsingTypenameDecl>(D) && 8431ed97649e9574b9d854fa4d6109c9333ae0993554John McCall "UnresolvedUsingTypenameDecl transformed to non-using decl"); 8432ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Ty = cast<UnresolvedUsingTypenameDecl>(D); 8433ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 8434ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 8435ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return SemaRef.Context.getTypeDeclType(Ty); 8436ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 8437ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 8438ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> 84392a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, 84402a984cad5ac3fdceeff2bd99daa7b90979313475John McCall SourceLocation Loc) { 84412a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return SemaRef.BuildTypeofExprType(E, Loc); 8442577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8443577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8444577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8445577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { 8446577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeOfType(Underlying); 8447577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8448577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8449577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 84502a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, 84512a984cad5ac3fdceeff2bd99daa7b90979313475John McCall SourceLocation Loc) { 84522a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return SemaRef.BuildDecltypeType(E, Loc); 8453577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8454577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8455577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8456ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, 8457ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType::UTTKind UKind, 8458ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt SourceLocation Loc) { 8459ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); 8460ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt} 8461ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 8462ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunttemplate<typename Derived> 8463577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTemplateSpecializationType( 8464833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateName Template, 8465833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation TemplateNameLoc, 846667714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor TemplateArgumentListInfo &TemplateArgs) { 8467d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); 8468577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 84691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8470dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived> 8471b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli FriedmanQualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, 8472b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman SourceLocation KWLoc) { 8473b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return SemaRef.BuildAtomicType(ValueType, KWLoc); 8474b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman} 8475b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 8476b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmantemplate<typename Derived> 84771eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 8478fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 8479d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor bool TemplateKW, 8480d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TemplateDecl *Template) { 8481fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, 8482d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor Template); 8483d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor} 8484d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor 8485d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived> 84861eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 8487fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 8488fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor const IdentifierInfo &Name, 8489fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 849043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 849143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope) { 8492fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor UnqualifiedId TemplateName; 8493fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName.setIdentifier(&Name, NameLoc); 8494d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Sema::TemplateTy Template; 8495d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor getSema().ActOnDependentTemplateName(/*Scope=*/0, 8496fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /*FIXME:*/SourceLocation(), 8497d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor SS, 8498fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName, 8499b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType::make(ObjectType), 8500d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor /*EnteringContext=*/false, 8501d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Template); 850243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return Template.get(); 8503d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor} 85041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8505b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 8506ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTemplateName 8507fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 8508ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor OverloadedOperatorKind Operator, 8509fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 8510ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor QualType ObjectType) { 8511ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId Name; 8512fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor // FIXME: Bogus location information. 8513fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; 8514fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); 8515d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Sema::TemplateTy Template; 8516d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor getSema().ActOnDependentTemplateName(/*Scope=*/0, 8517fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /*FIXME:*/SourceLocation(), 8518d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor SS, 8519d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Name, 8520b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType::make(ObjectType), 8521d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor /*EnteringContext=*/false, 8522d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Template); 8523d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor return Template.template getAsVal<TemplateName>(); 8524ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor} 8525c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8526ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregortemplate<typename Derived> 852760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8528b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, 8529b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 85309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *OrigCallee, 85319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *First, 85329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Second) { 85339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Callee = OrigCallee->IgnoreParenCasts(); 85349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); 85351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8536b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Determine whether this should be a builtin operation. 8537f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl if (Op == OO_Subscript) { 85389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType() && 85399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall !Second->getType()->isOverloadableType()) 85409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().CreateBuiltinArraySubscriptExpr(First, 85419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Callee->getLocStart(), 85429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Second, OpLoc); 85431a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman } else if (Op == OO_Arrow) { 85441a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman // -> is never a builtin operation. 85459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); 85469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall } else if (Second == 0 || isPostIncDec) { 85479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType()) { 8548b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // The argument is not of overloadable type, so try to create a 8549b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // built-in unary operation. 85502de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc 8551b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); 85521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 85539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); 8554b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 8555b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } else { 85569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType() && 85579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall !Second->getType()->isOverloadableType()) { 8558b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Neither of the arguments is an overloadable type, so try to 8559b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // create a built-in binary operation. 85602de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 856160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 85629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); 8563b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 8564f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 85651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8566b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return move(Result); 8567b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 8568b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 85691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 85701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Compute the transformed set of functions (and function templates) to be 8571b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // used during overload resolution. 85726e26689f5d513e24ad7783a4493201930fdeccc0John McCall UnresolvedSet<16> Functions; 85731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 85749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { 8575ba13543329afac4a0d01304ec2ec4924d99306a6John McCall assert(ULE->requiresADL()); 8576ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 8577ba13543329afac4a0d01304ec2ec4924d99306a6John McCall // FIXME: Do we have to check 8578ba13543329afac4a0d01304ec2ec4924d99306a6John McCall // IsAcceptableNonMemberOperatorCandidate for each of these? 85796e26689f5d513e24ad7783a4493201930fdeccc0John McCall Functions.append(ULE->decls_begin(), ULE->decls_end()); 8580ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } else { 85819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl()); 8582ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } 85831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8584b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Add any functions found via argument-dependent lookup. 85859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Args[2] = { First, Second }; 85869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall unsigned NumArgs = 1 + (Second != 0); 85871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8588b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Create the overloaded operator invocation for unary operators. 8589b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (NumArgs == 1 || isPostIncDec) { 85902de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc 8591b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); 85929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); 8593b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 85941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 85955b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor if (Op == OO_Subscript) { 85965b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor SourceLocation LBrace; 85975b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor SourceLocation RBrace; 85985b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor 85995b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { 86005b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo(); 86015b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor LBrace = SourceLocation::getFromRawEncoding( 86025b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor NameLoc.CXXOperatorName.BeginOpNameLoc); 86035b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor RBrace = SourceLocation::getFromRawEncoding( 86045b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor NameLoc.CXXOperatorName.EndOpNameLoc); 86055b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor } else { 86065b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor LBrace = Callee->getLocStart(); 86075b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor RBrace = OpLoc; 86085b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor } 86095b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor 86105b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, 86115b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor First, Second); 86125b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor } 8613f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl 8614b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Create the overloaded operator invocation for binary operators. 86152de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 861660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 8617b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); 8618b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 8619f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 86201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 86211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return move(Result); 8622b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 86231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 862426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregortemplate<typename Derived> 862560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 86269ae2f076ca5ab1feb3ba95629099ec2319833701John McCallTreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, 862726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SourceLocation OperatorLoc, 862826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor bool isArrow, 8629f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor CXXScopeSpec &SS, 863026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor TypeSourceInfo *ScopeType, 863126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SourceLocation CCLoc, 8632fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SourceLocation TildeLoc, 8633a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed) { 86349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall QualType BaseType = Base->getType(); 86359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (Base->isTypeDependent() || Destroyed.getIdentifier() || 863626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor (!isArrow && !BaseType->getAs<RecordType>()) || 8637c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt (isArrow && BaseType->getAs<PointerType>() && 8638bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif !BaseType->getAs<PointerType>()->getPointeeType() 8639bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif ->template getAs<RecordType>())){ 864026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor // This pseudo-destructor expression is still a pseudo-destructor. 86419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, 864226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor isArrow? tok::arrow : tok::period, 8643fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SS, ScopeType, CCLoc, TildeLoc, 8644a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed, 864526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /*FIXME?*/true); 864626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor } 86472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 8648a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); 86492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( 86502577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SemaRef.Context.getCanonicalType(DestroyedType->getType()))); 86512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); 86522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.setNamedTypeInfo(DestroyedType); 86532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 865426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor // FIXME: the ScopeType should be tacked onto SS. 86552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 86569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, BaseType, 865726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor OperatorLoc, isArrow, 865826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SS, /*FIXME: FirstQualifier*/ 0, 86592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 866026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /*TemplateArgs*/ 0); 866126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor} 866226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor 8663577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} // end namespace clang 8664577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8665577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H 8666