TreeTransform.h revision d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7
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, 533d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor llvm::Optional<unsigned> NumExpansions, 534d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor bool ExpectParameterPack); 53521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 53643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); 537833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 53860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); 53960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); 5401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 54143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) \ 54260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Transform##Node(Node *S); 543b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent) \ 54460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Transform##Node(Node *E); 5457381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 5464bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 5471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 548577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new pointer type given its pointee type. 549577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 550577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the pointer type. 551577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 55285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); 553577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 554577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new block pointer type given its pointee type. 555577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 5561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, performs semantic analysis when building the block pointer 557577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// type. Subclasses may override this routine to provide different behavior. 55885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); 559577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 56085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// \brief Build a new reference type given the type it references. 561577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 56285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// By default, performs semantic analysis when building the 56385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// reference type. Subclasses may override this routine to provide 56485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// different behavior. 565577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 56685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// \param LValue whether the type was written with an lvalue sigil 56785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// or an rvalue sigil. 56885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildReferenceType(QualType ReferentType, 56985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall bool LValue, 57085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil); 5711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 572577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new member pointer type given the pointee type and the 573577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// class type it refers into. 574577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 575577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the member pointer 576577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// type. Subclasses may override this routine to provide different behavior. 57785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, 57885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil); 5791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 580577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new array type given the element type, size 581577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// modifier, size of the array (if known), size expression, and index type 582577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// qualifiers. 583577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 584577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 585577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 5861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Also by default, all of the other Rebuild*Array 587577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildArrayType(QualType ElementType, 588577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 589577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt *Size, 590577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Expr *SizeExpr, 591577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 592577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange); 5931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 594577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new constant array type given the element type, size 595577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// modifier, (known) size of the array, and index type qualifiers. 596577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 597577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 598577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 5991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildConstantArrayType(QualType ElementType, 600577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 601577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt &Size, 60285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 60385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange); 604577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 605577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new incomplete array type given the element type, size 606577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// modifier, and index type qualifiers. 607577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 608577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 609577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildIncompleteArrayType(QualType ElementType, 611577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 61285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 61385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange); 614577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 6151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new variable-length array type given the element type, 616577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// size modifier, size expression, and index type qualifiers. 617577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 618577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 619577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildVariableArrayType(QualType ElementType, 621577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 6229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 623577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 624577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange); 625577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 6261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new dependent-sized array type given the element type, 627577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// size modifier, size expression, and index type qualifiers. 628577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 629577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 630577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildDependentSizedArrayType(QualType ElementType, 632577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 6339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 634577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 635577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange); 636577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 637577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new vector type given the element type and 638577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// number of elements. 639577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 640577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the vector type. 641577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 64282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson QualType RebuildVectorType(QualType ElementType, unsigned NumElements, 643e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::VectorKind VecKind); 6441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 645577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new extended vector type given the element type and 646577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// number of elements. 647577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 648577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the vector type. 649577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 650577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, 651577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc); 6521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new potentially dependently-sized extended vector type 654577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// given the element type and number of elements. 655577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 656577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the vector type. 657577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildDependentSizedExtVectorType(QualType ElementType, 6599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 660577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc); 6611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 662577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new function type. 663577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 664577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the function type. 665577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 666577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildFunctionProtoType(QualType T, 6671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType *ParamTypes, 668577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumParamTypes, 669fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman bool Variadic, unsigned Quals, 670c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind RefQualifier, 671fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman const FunctionType::ExtInfo &Info); 6721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 673a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// \brief Build a new unprototyped function type. 674a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType RebuildFunctionNoProtoType(QualType ResultType); 675a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 676ed97649e9574b9d854fa4d6109c9333ae0993554John McCall /// \brief Rebuild an unresolved typename type, given the decl that 677ed97649e9574b9d854fa4d6109c9333ae0993554John McCall /// the UnresolvedUsingTypenameDecl was transformed to. 678ed97649e9574b9d854fa4d6109c9333ae0993554John McCall QualType RebuildUnresolvedUsingType(Decl *D); 679ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 680577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new typedef type. 681162e1c1b487352434552147967c3dd296ebee2f7Richard Smith QualType RebuildTypedefType(TypedefNameDecl *Typedef) { 682577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeDeclType(Typedef); 683577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 684577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 685577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new class/struct/union type. 686577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildRecordType(RecordDecl *Record) { 687577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeDeclType(Record); 688577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 689577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 690577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new Enum type. 691577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildEnumType(EnumDecl *Enum) { 692577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeDeclType(Enum); 693577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 6947da2431c23ef1ee8acb114e39692246e1801afc2John McCall 6951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new typeof(expr) type. 696577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 697577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the typeof type. 698577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6992a984cad5ac3fdceeff2bd99daa7b90979313475John McCall QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); 700577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 7011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new typeof(type) type. 702577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 703577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, builds a new TypeOfType with the given underlying type. 704577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildTypeOfType(QualType Underlying); 705577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 706ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt /// \brief Build a new unary transform type. 707ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType RebuildUnaryTransformType(QualType BaseType, 708ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType::UTTKind UKind, 709ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt SourceLocation Loc); 710ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 7111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new C++0x decltype type. 712577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 713577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the decltype type. 714577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 7152a984cad5ac3fdceeff2bd99daa7b90979313475John McCall QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); 7161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71734b41d939a1328f484511c6002ba2456db879a29Richard Smith /// \brief Build a new C++0x auto type. 71834b41d939a1328f484511c6002ba2456db879a29Richard Smith /// 71934b41d939a1328f484511c6002ba2456db879a29Richard Smith /// By default, builds a new AutoType with the given deduced type. 72034b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType RebuildAutoType(QualType Deduced) { 72134b41d939a1328f484511c6002ba2456db879a29Richard Smith return SemaRef.Context.getAutoType(Deduced); 72234b41d939a1328f484511c6002ba2456db879a29Richard Smith } 72334b41d939a1328f484511c6002ba2456db879a29Richard Smith 724577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new template specialization type. 725577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 726577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the template 727577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// specialization type. Subclasses may override this routine to provide 728577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// different behavior. 729577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildTemplateSpecializationType(TemplateName Template, 730833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation TemplateLoc, 73167714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor TemplateArgumentListInfo &Args); 7321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 733075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// \brief Build a new parenthesized type. 734075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// 735075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// By default, builds a new ParenType type from the inner type. 736075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// Subclasses may override this routine to provide different behavior. 737075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType RebuildParenType(QualType InnerType) { 738075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return SemaRef.Context.getParenType(InnerType); 739075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 740075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 741577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new qualified name type. 742577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 743465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// By default, builds a new ElaboratedType type from the keyword, 744465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// the nested-name-specifier and the named type. 745465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// Subclasses may override this routine to provide different behavior. 74621e413fe6305a198564d436ac515497716c47844John McCall QualType RebuildElaboratedType(SourceLocation KeywordLoc, 74721e413fe6305a198564d436ac515497716c47844John McCall ElaboratedTypeKeyword Keyword, 7489e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 7499e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualType Named) { 7509e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor return SemaRef.Context.getElaboratedType(Keyword, 7519e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 7529e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor Named); 7531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 754577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 755577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new typename type that refers to a template-id. 756577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 757e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// By default, builds a new DependentNameType type from the 758e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// nested-name-specifier and the given type. Subclasses may override 759e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// this routine to provide different behavior. 76033500955d731c73717af52088b7fc0e7a85681e7John McCall QualType RebuildDependentTemplateSpecializationType( 76194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor ElaboratedTypeKeyword Keyword, 76294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 76394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor const IdentifierInfo *Name, 76494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor SourceLocation NameLoc, 76567714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor TemplateArgumentListInfo &Args) { 76694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Rebuild the template name. 76794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // TODO: avoid TemplateName abstraction 768fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor CXXScopeSpec SS; 769fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SS.Adopt(QualifierLoc); 77094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor TemplateName InstName 771fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0); 77294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 77394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (InstName.isNull()) 77494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return QualType(); 77594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 77694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // If it's still dependent, make a dependent specialization. 77794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (InstName.getAsDependentTemplateName()) 77894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, 77994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 78094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor Name, 78194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor Args); 78294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 78394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Otherwise, make an elaborated type wrapping a non-dependent 78494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // specialization. 78594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualType T = 78694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); 78794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (T.isNull()) return QualType(); 78894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 78994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0) 79094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return T; 79194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 79294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return SemaRef.Context.getElaboratedType(Keyword, 79394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 79494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor T); 79594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor } 79694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 797577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new typename type that refers to an identifier. 798577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 799577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the typename type 800e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// (or elaborated type). Subclasses may override this routine to provide 801577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// different behavior. 802e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, 803e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SourceLocation KeywordLoc, 8042494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 8052494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor const IdentifierInfo *Id, 806e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SourceLocation IdLoc) { 8074033642464e8ba0982f88f34cffad808d247b393Douglas Gregor CXXScopeSpec SS; 8082494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor SS.Adopt(QualifierLoc); 809e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara 8102494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { 8114033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // If the name is still dependent, just build a new dependent name type. 8124033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (!SemaRef.computeDeclContext(SS)) 8132494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor return SemaRef.Context.getDependentNameType(Keyword, 8142494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 8152494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor Id); 8164033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 8174033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 818465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara if (Keyword == ETK_None || Keyword == ETK_Typename) 8192494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, 820e29425bd22fbb9200bbec7b743197b9c6dad3e40Douglas Gregor *Id, IdLoc); 821465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 822465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); 823465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 824e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara // We had a dependent elaborated-type-specifier that has been transformed 8254033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // into a non-dependent elaborated-type-specifier. Find the tag we're 8264033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // referring to. 827e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); 8284033642464e8ba0982f88f34cffad808d247b393Douglas Gregor DeclContext *DC = SemaRef.computeDeclContext(SS, false); 8294033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (!DC) 8304033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 8314033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 8325613876991c80a684595fe8de1f039296a0657ffJohn McCall if (SemaRef.RequireCompleteDeclContext(SS, DC)) 8335613876991c80a684595fe8de1f039296a0657ffJohn McCall return QualType(); 8345613876991c80a684595fe8de1f039296a0657ffJohn McCall 8354033642464e8ba0982f88f34cffad808d247b393Douglas Gregor TagDecl *Tag = 0; 8364033642464e8ba0982f88f34cffad808d247b393Douglas Gregor SemaRef.LookupQualifiedName(Result, DC); 8374033642464e8ba0982f88f34cffad808d247b393Douglas Gregor switch (Result.getResultKind()) { 8384033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::NotFound: 8394033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::NotFoundInCurrentInstantiation: 8404033642464e8ba0982f88f34cffad808d247b393Douglas Gregor break; 841c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8424033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::Found: 8434033642464e8ba0982f88f34cffad808d247b393Douglas Gregor Tag = Result.getAsSingle<TagDecl>(); 8444033642464e8ba0982f88f34cffad808d247b393Douglas Gregor break; 845c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8464033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::FoundOverloaded: 8474033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::FoundUnresolvedValue: 8484033642464e8ba0982f88f34cffad808d247b393Douglas Gregor llvm_unreachable("Tag lookup cannot find non-tags"); 8494033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 850c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8514033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::Ambiguous: 8524033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // Let the LookupResult structure handle ambiguities. 8534033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 8544033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 8554033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 8564033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (!Tag) { 857446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky // Check where the name exists but isn't a tag type and use that to emit 858446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky // better diagnostics. 859446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); 860446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.LookupQualifiedName(Result, DC); 861446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky switch (Result.getResultKind()) { 862446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky case LookupResult::Found: 863446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky case LookupResult::FoundOverloaded: 864446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky case LookupResult::FoundUnresolvedValue: { 8653e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NamedDecl *SomeDecl = Result.getRepresentativeDecl(); 866446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky unsigned Kind = 0; 867446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky if (isa<TypedefDecl>(SomeDecl)) Kind = 1; 868162e1c1b487352434552147967c3dd296ebee2f7Richard Smith else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2; 869162e1c1b487352434552147967c3dd296ebee2f7Richard Smith else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3; 870446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; 871446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); 872446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky break; 8733e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 874446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky default: 875446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky // FIXME: Would be nice to highlight just the source range. 876446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) 877446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky << Kind << Id << DC; 878446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky break; 879446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky } 8804033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 8814033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 882465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 883bbf34c024398e7bae825686dcff4c3b901ec9f89Richard Trieu if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, 884bbf34c024398e7bae825686dcff4c3b901ec9f89Richard Trieu IdLoc, *Id)) { 885e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; 8864033642464e8ba0982f88f34cffad808d247b393Douglas Gregor SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); 8874033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 8884033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 8894033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 8904033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // Build the elaborated-type-specifier type. 8914033642464e8ba0982f88f34cffad808d247b393Douglas Gregor QualType T = SemaRef.Context.getTypeDeclType(Tag); 8922494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor return SemaRef.Context.getElaboratedType(Keyword, 8932494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 8942494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor T); 895dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor } 8961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8972fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// \brief Build a new pack expansion type. 8982fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// 8992fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// By default, builds a new PackExpansionType type from the given pattern. 9002fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// Subclasses may override this routine to provide different behavior. 9012fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor QualType RebuildPackExpansionType(QualType Pattern, 9022fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor SourceRange PatternRange, 903cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor SourceLocation EllipsisLoc, 904cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 905cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, 906cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions); 9072fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor } 9082fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor 909b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman /// \brief Build a new atomic type given its value type. 910b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman /// 911b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman /// By default, performs semantic analysis when building the atomic type. 912b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman /// Subclasses may override this routine to provide different behavior. 913b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); 914b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 915d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// \brief Build a new template name given a nested name specifier, a flag 916d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// indicating whether the "template" keyword was provided, and the template 917d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// that the template name refers to. 918d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// 919d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// By default, builds the new template name directly. Subclasses may override 920d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// this routine to provide different behavior. 921fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName RebuildTemplateName(CXXScopeSpec &SS, 922d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor bool TemplateKW, 923d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TemplateDecl *Template); 924d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor 925d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// \brief Build a new template name given a nested name specifier and the 926d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// name that is referred to as a template. 927d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// 928d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// By default, performs semantic analysis to determine whether the name can 929d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// be resolved to a specific template, then builds the appropriate kind of 930d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// template name. Subclasses may override this routine to provide different 931d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// behavior. 932fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName RebuildTemplateName(CXXScopeSpec &SS, 933fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor const IdentifierInfo &Name, 934fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 93543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 93643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope); 9371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 938ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// \brief Build a new template name given a nested name specifier and the 939ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// overloaded operator name that is referred to as a template. 940ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// 941ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// By default, performs semantic analysis to determine whether the name can 942ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// be resolved to a specific template, then builds the appropriate kind of 943ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// template name. Subclasses may override this routine to provide different 944ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// behavior. 945fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName RebuildTemplateName(CXXScopeSpec &SS, 946ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor OverloadedOperatorKind Operator, 947fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 948ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor QualType ObjectType); 9491aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 9501aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// \brief Build a new template name given a template template parameter pack 9511aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// and the 9521aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// 9531aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// By default, performs semantic analysis to determine whether the name can 9541aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// be resolved to a specific template, then builds the appropriate kind of 9551aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// template name. Subclasses may override this routine to provide different 9561aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// behavior. 9571aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, 9581aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor const TemplateArgument &ArgPack) { 9591aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); 9601aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor } 9611aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 96243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new compound statement. 96343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 96443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 96543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 96660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, 96743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor MultiStmtArg Statements, 96843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation RBraceLoc, 96943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool IsStmtExpr) { 9709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, 97143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor IsStmtExpr); 97243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 97343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 97443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new case statement. 97543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 97643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 97743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 97860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCaseStmt(SourceLocation CaseLoc, 9799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *LHS, 98043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation EllipsisLoc, 9819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *RHS, 98243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation ColonLoc) { 9839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, 98443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor ColonLoc); 98543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 9861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 98743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Attach the body to a new case statement. 98843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 98943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 99043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 99160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { 9929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall getSema().ActOnCaseStmtBody(S, Body); 9939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return S; 99443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 9951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 99643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new default statement. 99743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 99843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 99943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 100060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, 100143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation ColonLoc, 10029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *SubStmt) { 10039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, 100443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /*CurScope=*/0); 100543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 100743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new label statement. 100843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 100943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 101043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 101157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, 101257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner SourceLocation ColonLoc, Stmt *SubStmt) { 101357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); 101443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 101643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new "if" statement. 101743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 101843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 101943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 102060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, 102157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner VarDecl *CondVar, Stmt *Then, 102257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner SourceLocation ElseLoc, Stmt *Else) { 102344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); 102443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 102643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Start building a new switch statement. 102743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 102843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 102943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 103060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, 103157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Expr *Cond, VarDecl *CondVar) { 10329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, 1033d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall CondVar); 103443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 103643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Attach the body to the switch statement. 103743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 103843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 103943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 104060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, 104157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Stmt *Switch, Stmt *Body) { 10429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); 104343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 104443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 104543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new while statement. 104643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 104743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 104843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 104957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, 105057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner VarDecl *CondVar, Stmt *Body) { 10519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); 105243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 105443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new do-while statement. 105543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 105643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 105743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 105860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, 1059ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation WhileLoc, SourceLocation LParenLoc, 1060ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner Expr *Cond, SourceLocation RParenLoc) { 10619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, 10629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond, RParenLoc); 106343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 106443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 106543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new for statement. 106643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 106743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 106843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1069ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, 1070ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner Stmt *Init, Sema::FullExprArg Cond, 1071ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner VarDecl *CondVar, Sema::FullExprArg Inc, 1072ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation RParenLoc, Stmt *Body) { 10739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, 1074ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner CondVar, Inc, RParenLoc, Body); 107543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 107743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new goto statement. 107843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 107943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 108043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1081ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, 1082ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *Label) { 108357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); 108443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 108543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 108643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new indirect goto statement. 108743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 108843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 108943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 109060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, 1091ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation StarLoc, 1092ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner Expr *Target) { 10939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); 109443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 109643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new return statement. 109743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 109843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 109943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1100ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { 11019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnReturnStmt(ReturnLoc, Result); 110243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 11031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 110443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new declaration statement. 110543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 110643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 110743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 110860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, 11091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation StartLoc, 111043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation EndLoc) { 1111406c38e8c1f105acfd438f94dfbc17af817aa4a5Richard Smith Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls); 1112406c38e8c1f105acfd438f94dfbc17af817aa4a5Richard Smith return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); 111343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 11141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1115703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// \brief Build a new inline asm statement. 1116703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// 1117703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// By default, performs semantic analysis to build the new statement. 1118703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// Subclasses may override this routine to provide different behavior. 111960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildAsmStmt(SourceLocation AsmLoc, 1120703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool IsSimple, 1121703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool IsVolatile, 1122703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson unsigned NumOutputs, 1123703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson unsigned NumInputs, 1124ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo **Names, 1125703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson MultiExprArg Constraints, 1126703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson MultiExprArg Exprs, 11279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *AsmString, 1128703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson MultiExprArg Clobbers, 1129703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson SourceLocation RParenLoc, 1130703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool MSAsm) { 1131c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, 1132703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson NumInputs, Names, move(Constraints), 11339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs, AsmString, Clobbers, 1134703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson RParenLoc, MSAsm); 1135703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 11364dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 11374dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// \brief Build a new Objective-C @try statement. 11384dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// 11394dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// By default, performs semantic analysis to build the new statement. 11404dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 114160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, 11429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *TryBody, 11438f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor MultiStmtArg CatchStmts, 11449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Finally) { 11459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts), 11469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Finally); 11474dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 11484dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 1149be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// \brief Rebuild an Objective-C exception declaration. 1150be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// 1151be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// By default, performs semantic analysis to build the new declaration. 1152be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1153be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, 1154be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TypeSourceInfo *TInfo, QualType T) { 1155ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara return getSema().BuildObjCExceptionDecl(TInfo, T, 1156ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getInnerLocStart(), 1157ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getLocation(), 1158ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getIdentifier()); 1159be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 1160c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1161be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// \brief Build a new Objective-C @catch statement. 1162be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// 1163be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// By default, performs semantic analysis to build the new statement. 1164be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// Subclasses may override this routine to provide different behavior. 116560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, 1166be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor SourceLocation RParenLoc, 1167be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *Var, 11689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Body) { 1169be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, 11709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Var, Body); 1171be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 1172c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 11734dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// \brief Build a new Objective-C @finally statement. 11744dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// 11754dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// By default, performs semantic analysis to build the new statement. 11764dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 117760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, 11789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Body) { 11799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); 11804dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 1181c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 11828fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// \brief Build a new Objective-C @throw statement. 1183d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor /// 1184d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor /// By default, performs semantic analysis to build the new statement. 1185d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor /// Subclasses may override this routine to provide different behavior. 118660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, 11879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand) { 11889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); 1189d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor } 1190c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 119107524039dce5c820f111a1b3f772b4261f004b4aJohn McCall /// \brief Rebuild the operand to an Objective-C @synchronized statement. 119207524039dce5c820f111a1b3f772b4261f004b4aJohn McCall /// 119307524039dce5c820f111a1b3f772b4261f004b4aJohn McCall /// By default, performs semantic analysis to build the new statement. 119407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall /// Subclasses may override this routine to provide different behavior. 119507524039dce5c820f111a1b3f772b4261f004b4aJohn McCall ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, 119607524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Expr *object) { 119707524039dce5c820f111a1b3f772b4261f004b4aJohn McCall return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); 119807524039dce5c820f111a1b3f772b4261f004b4aJohn McCall } 119907524039dce5c820f111a1b3f772b4261f004b4aJohn McCall 12008fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// \brief Build a new Objective-C @synchronized statement. 12018fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// 12028fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// By default, performs semantic analysis to build the new statement. 12038fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// Subclasses may override this routine to provide different behavior. 120460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, 120507524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Expr *Object, Stmt *Body) { 120607524039dce5c820f111a1b3f772b4261f004b4aJohn McCall return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); 12078fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor } 1208c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor 1209f85e193739c953358c865005855253af4f68a497John McCall /// \brief Build a new Objective-C @autoreleasepool statement. 1210f85e193739c953358c865005855253af4f68a497John McCall /// 1211f85e193739c953358c865005855253af4f68a497John McCall /// By default, performs semantic analysis to build the new statement. 1212f85e193739c953358c865005855253af4f68a497John McCall /// Subclasses may override this routine to provide different behavior. 1213f85e193739c953358c865005855253af4f68a497John McCall StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, 1214f85e193739c953358c865005855253af4f68a497John McCall Stmt *Body) { 1215f85e193739c953358c865005855253af4f68a497John McCall return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); 1216f85e193739c953358c865005855253af4f68a497John McCall } 1217990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall 1218990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall /// \brief Build the collection operand to a new Objective-C fast 1219990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall /// enumeration statement. 1220990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall /// 1221990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall /// By default, performs semantic analysis to build the new statement. 1222990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall /// Subclasses may override this routine to provide different behavior. 1223990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc, 1224990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall Expr *collection) { 1225990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall return getSema().ActOnObjCForCollectionOperand(forLoc, collection); 1226990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall } 1227f85e193739c953358c865005855253af4f68a497John McCall 1228c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// \brief Build a new Objective-C fast enumeration statement. 1229c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// 1230c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// By default, performs semantic analysis to build the new statement. 1231c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// Subclasses may override this routine to provide different behavior. 123260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, 1233f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall SourceLocation LParenLoc, 1234f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *Element, 1235f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Expr *Collection, 1236f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall SourceLocation RParenLoc, 1237f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *Body) { 1238c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, 12399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Element, 12409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Collection, 1241c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor RParenLoc, 12429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body); 1243c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor } 1244c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 124543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new C++ exception declaration. 124643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 124743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new decaration. 124843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1249ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, 1250a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Declarator, 1251ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation StartLoc, 1252ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation IdLoc, 1253ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara IdentifierInfo *Id) { 1254efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator, 1255efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor StartLoc, IdLoc, Id); 1256efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor if (Var) 1257efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor getSema().CurContext->addDecl(Var); 1258efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor return Var; 125943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 126043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 126143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new C++ catch statement. 126243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 126343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 126443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 126560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, 1266f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall VarDecl *ExceptionDecl, 1267f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *Handler) { 12689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, 12699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Handler)); 127043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 12711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 127243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new C++ try statement. 127343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 127443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 127543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 127660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, 1277f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *TryBlock, 1278f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiStmtArg Handlers) { 12799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers)); 128043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 12811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1282ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// \brief Build a new C++0x range-based for statement. 1283ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// 1284ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// By default, performs semantic analysis to build the new statement. 1285ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// Subclasses may override this routine to provide different behavior. 1286ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, 1287ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith SourceLocation ColonLoc, 1288ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Stmt *Range, Stmt *BeginEnd, 1289ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Expr *Cond, Expr *Inc, 1290ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Stmt *LoopVar, 1291ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith SourceLocation RParenLoc) { 1292ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd, 1293ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Cond, Inc, LoopVar, RParenLoc); 1294ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 1295ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 1296ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor /// \brief Build a new C++0x range-based for statement. 1297ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor /// 1298ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor /// By default, performs semantic analysis to build the new statement. 1299ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1300ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, 1301ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor bool IsIfExists, 1302ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 1303ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor DeclarationNameInfo NameInfo, 1304ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor Stmt *Nested) { 1305ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, 1306ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor QualifierLoc, NameInfo, Nested); 1307ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor } 1308ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 1309ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// \brief Attach body to a C++0x range-based for statement. 1310ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// 1311ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// By default, performs semantic analysis to finish the new statement. 1312ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// Subclasses may override this routine to provide different behavior. 1313ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { 1314ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return getSema().FinishCXXForRangeStmt(ForRange, Body); 1315ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 1316ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 131728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult RebuildSEHTryStmt(bool IsCXXTry, 131828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation TryLoc, 131928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *TryBlock, 132028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Handler) { 132128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler); 132228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 132328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 132428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult RebuildSEHExceptStmt(SourceLocation Loc, 132528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Expr *FilterExpr, 132628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block) { 132728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block); 132828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 132928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 133028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, 133128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block) { 133228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getSema().ActOnSEHFinallyBlock(Loc,Block); 133328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 133428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 1335b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression that references a declaration. 1336b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1337b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1338b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 133960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, 1340f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall LookupResult &R, 1341f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall bool RequiresADL) { 1342f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); 1343f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 1344f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 1345f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 1346f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// \brief Build a new expression that references a declaration. 1347f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// 1348f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// By default, performs semantic analysis to build the new expression. 1349f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// Subclasses may override this routine to provide different behavior. 135040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, 1351f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall ValueDecl *VD, 1352f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall const DeclarationNameInfo &NameInfo, 1353f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TemplateArgumentListInfo *TemplateArgs) { 1354a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor CXXScopeSpec SS; 135540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor SS.Adopt(QualifierLoc); 1356dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 1357dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // FIXME: loses template args. 13582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 13592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); 1360b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 13611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1362b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression in parentheses. 13631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1364b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1365b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 136660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, 1367b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParen) { 13689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnParenExpr(LParen, RParen, SubExpr); 1369b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1370b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1371a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief Build a new pseudo-destructor expression. 13721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1373a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1374a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// Subclasses may override this routine to provide different behavior. 137560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, 1376f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SourceLocation OperatorLoc, 1377f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor bool isArrow, 1378f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor CXXScopeSpec &SS, 1379f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor TypeSourceInfo *ScopeType, 1380f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SourceLocation CCLoc, 1381f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SourceLocation TildeLoc, 1382a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed); 13831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1384b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new unary operator expression. 13851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1386b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1387b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 138860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildUnaryOperator(SourceLocation OpLoc, 13892de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc, 13909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr) { 13919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); 1392b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 13931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 13948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Build a new builtin offsetof expression. 13958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// 13968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// By default, performs semantic analysis to build the new expression. 13978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// Subclasses may override this routine to provide different behavior. 139860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, 13998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *Type, 1400f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::OffsetOfComponent *Components, 14018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComponents, 14028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) { 14038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, 14048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor NumComponents, RParenLoc); 14058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1406c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1407f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne /// \brief Build a new sizeof, alignof or vec_step expression with a 1408f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne /// type argument. 14091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1410b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1411b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1412f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, 1413f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation OpLoc, 1414f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTrait ExprKind, 1415f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceRange R) { 1416f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); 1417b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1418b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1419f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne /// \brief Build a new sizeof, alignof or vec step expression with an 1420f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne /// expression argument. 14211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1422b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1423b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1424f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, 1425f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTrait ExprKind, 1426f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceRange R) { 142760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 1428e72c55b9a11be9f00fa3f66f7ad6b73b2814e963Chandler Carruth = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); 1429b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 1430f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 14311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1432b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return move(Result); 1433b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 14341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1435b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new array subscript expression. 14361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1437b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1438b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 143960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildArraySubscriptExpr(Expr *LHS, 1440b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LBracketLoc, 14419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *RHS, 1442b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RBracketLoc) { 14439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, 14449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LBracketLoc, RHS, 1445b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RBracketLoc); 1446b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1447b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1448b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new call expression. 14491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1450b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1451b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 145260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, 1453b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg Args, 1454e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne SourceLocation RParenLoc, 1455e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne Expr *ExecConfig = 0) { 14569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, 1457e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne move(Args), RParenLoc, ExecConfig); 1458b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1459b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1460b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new member access expression. 14611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1462b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1463b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 146460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, 1465f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall bool isArrow, 146640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 1467f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const DeclarationNameInfo &MemberNameInfo, 1468f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ValueDecl *Member, 1469f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall NamedDecl *FoundDecl, 1470d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *ExplicitTemplateArgs, 1471f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall NamedDecl *FirstQualifierInScope) { 14729138b4e96429cbaae00c52c15c960f72b6645088Richard Smith ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, 14739138b4e96429cbaae00c52c15c960f72b6645088Richard Smith isArrow); 1474d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson if (!Member->getDeclName()) { 1475f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // We have a reference to an unnamed field. This is always the 1476f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // base of an anonymous struct/union member access, i.e. the 1477f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // field is always of record type. 147840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); 1479f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall assert(Member->getType()->isRecordType() && 1480f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall "unnamed member not of record type?"); 14811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14829138b4e96429cbaae00c52c15c960f72b6645088Richard Smith BaseResult = 14839138b4e96429cbaae00c52c15c960f72b6645088Richard Smith getSema().PerformObjectMemberConversion(BaseResult.take(), 1484429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley QualifierLoc.getNestedNameSpecifier(), 1485429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley FoundDecl, Member); 1486429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (BaseResult.isInvalid()) 1487f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 1488429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley Base = BaseResult.take(); 1489f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); 14901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump MemberExpr *ME = 14919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall new (getSema().Context) MemberExpr(Base, isArrow, 14922577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Member, MemberNameInfo, 1493f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall cast<FieldDecl>(Member)->getType(), 1494f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall VK, OK_Ordinary); 1495d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson return getSema().Owned(ME); 1496d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson } 14971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 149883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor CXXScopeSpec SS; 149940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor SS.Adopt(QualifierLoc); 150083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 1501429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley Base = BaseResult.take(); 15029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall QualType BaseType = Base->getType(); 1503aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 15046bb8017bb9e828d118e15e59d71c66bba323c364John McCall // FIXME: this involves duplicating earlier analysis in a lot of 15056bb8017bb9e828d118e15e59d71c66bba323c364John McCall // cases; we should avoid this when possible. 15062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); 15076bb8017bb9e828d118e15e59d71c66bba323c364John McCall R.addDecl(FoundDecl); 1508c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R.resolveKind(); 1509c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 15109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, 1511129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SS, FirstQualifierInScope, 1512c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R, ExplicitTemplateArgs); 1513b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1515b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new binary operator expression. 15161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1517b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1518b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 151960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildBinaryOperator(SourceLocation OpLoc, 15202de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc, 15219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *LHS, Expr *RHS) { 15229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); 1523b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1524b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1525b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new conditional operator expression. 15261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1527b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1528b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 152960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildConditionalOperator(Expr *Cond, 153056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation QuestionLoc, 153156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *LHS, 153256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation ColonLoc, 153356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *RHS) { 15349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, 15359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS, RHS); 1536b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1537b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1538b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C-style cast expression. 15391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1540b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1541b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 154260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, 15439d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1544b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc, 15459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr) { 1546b042fdfc9460e0018276412257e3c3226f9ea96eJohn McCall return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, 15479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr); 1548b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1550b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new compound literal expression. 15511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1552b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1553b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 155460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, 155542f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *TInfo, 1556b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc, 15579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Init) { 155842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, 15599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init); 1560b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1562b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new extended vector element access expression. 15631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1564b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1565b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 156660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildExtVectorElementExpr(Expr *Base, 1567b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 1568b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation AccessorLoc, 1569b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor IdentifierInfo &Accessor) { 1570aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 1571129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall CXXScopeSpec SS; 15722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); 15739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, Base->getType(), 1574129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall OpLoc, /*IsArrow*/ false, 1575129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SS, /*FirstQualifierInScope*/ 0, 15762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 1577129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /* TemplateArgs */ 0); 1578b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1580b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new initializer list expression. 15811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1582b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1583b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 158460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildInitList(SourceLocation LBraceLoc, 1585c8fc90a854b4ccba21c85884676a80334159dd94John McCall MultiExprArg Inits, 1586c8fc90a854b4ccba21c85884676a80334159dd94John McCall SourceLocation RBraceLoc, 1587c8fc90a854b4ccba21c85884676a80334159dd94John McCall QualType ResultTy) { 158860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 1589e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); 1590e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor if (Result.isInvalid() || ResultTy->isDependentType()) 1591e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor return move(Result); 1592c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1593e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor // Patch in the result type we were given, which may have been computed 1594e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor // when the initial InitListExpr was built. 1595e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); 1596e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor ILE->setType(ResultTy); 1597e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor return move(Result); 1598b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1600b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new designated initializer expression. 16011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1602b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1603b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 160460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildDesignatedInitExpr(Designation &Desig, 1605b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg ArrayExprs, 1606b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation EqualOrColonLoc, 1607b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool GNUSyntax, 16089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Init) { 160960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 1610b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, 16119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init); 1612b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 1613f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 16141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1615b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.release(); 1616b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return move(Result); 1617b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1619b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new value-initialized expression. 16201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1621b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds the implicit value initialization without performing 1622b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// any semantic analysis. Subclasses may override this routine to provide 1623b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// different behavior. 162460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildImplicitValueInitExpr(QualType T) { 1625b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); 1626b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1628b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new \c va_arg expression. 16291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1630b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1631b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 163260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, 16339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, TypeSourceInfo *TInfo, 16342cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara SourceLocation RParenLoc) { 16352cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara return getSema().BuildVAArgExpr(BuiltinLoc, 16369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, TInfo, 16372cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara RParenLoc); 1638b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1639b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1640b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression list in parentheses. 16411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1642b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1643b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 164460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildParenListExpr(SourceLocation LParenLoc, 1645b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg SubExprs, 1646b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1647c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, 1648f88f7ab5adaa11d050270ffee6aa871e855f83b8Fariborz Jahanian move(SubExprs)); 1649b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1651b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new address-of-label expression. 16521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 16531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, performs semantic analysis, using the name of the label 1654b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// rather than attempting to map the label statement itself. 1655b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 165660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, 1657ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation LabelLoc, LabelDecl *Label) { 165857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); 1659b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1661b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new GNU statement expression. 16621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1663b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1664b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 166560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildStmtExpr(SourceLocation LParenLoc, 16669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *SubStmt, 1667b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 16689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); 1669b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1671b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new __builtin_choose_expr expression. 1672b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1674b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 167560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, 16769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Cond, Expr *LHS, Expr *RHS, 1677b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1678b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.ActOnChooseExpr(BuiltinLoc, 16799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond, LHS, RHS, 1680b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 1681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1683f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// \brief Build a new generic selection expression. 1684f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// 1685f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// By default, performs semantic analysis to build the new expression. 1686f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// Subclasses may override this routine to provide different behavior. 1687f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, 1688f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation DefaultLoc, 1689f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 1690f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *ControllingExpr, 1691f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **Types, 1692f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr **Exprs, 1693f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs) { 1694f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, 1695f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ControllingExpr, Types, Exprs, 1696f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne NumAssocs); 1697f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 1698f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 1699b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new overloaded operator call expression. 1700b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1701b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1702b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// The semantic analysis provides the behavior of template instantiation, 1703b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// copying with transformations that turn what looks like an overloaded 17041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// operator call into a use of a builtin operator, performing 1705b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// argument-dependent lookup, etc. Subclasses may override this routine to 1706b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// provide different behavior. 170760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, 1708b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 17099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Callee, 17109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *First, 17119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Second); 17121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new C++ "named" cast expression, such as static_cast or 1714b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// reinterpret_cast. 1715b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1716b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, this routine dispatches to one of the more-specific routines 17171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). 1718b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 171960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, 1720b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Stmt::StmtClass Class, 1721b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 17229d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1723b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1724b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 17259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1726b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1727b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor switch (Class) { 1728b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXStaticCastExprClass: 17299d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, 17301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 1732b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1733b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXDynamicCastExprClass: 17349d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, 17351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 17371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1738b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXReinterpretCastExprClass: 17399d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, 17401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, 1742b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 17431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1744b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXConstCastExprClass: 17459d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, 17461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 17481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1749b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor default: 1750b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Invalid C++ named cast"); 1751b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1753f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 1754b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1756b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ static_cast expression. 1757b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1758b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1759b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 176060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, 1761b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 17629d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1763b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1764b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 17659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1766b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1767c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, 17689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1769c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1770c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1771b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1772b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1773b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ dynamic_cast expression. 1774b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1775b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1776b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 177760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, 1778b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 17799d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1780b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1781b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 17829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1783b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1784c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, 17859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1786c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1787c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1788b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1789b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1790b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ reinterpret_cast expression. 1791b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1792b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1793b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 179460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, 1795b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 17969d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1797b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1798b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 17999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1800b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1801c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, 18029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1803c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1804c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1805b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1806b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1807b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ const_cast expression. 1808b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1809b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1810b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 181160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, 1812b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 18139d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1814b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1815b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 18169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1817b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1818c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, 18199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1820c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1821c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1822b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1824b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ functional-style cast expression. 1825b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1826b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1827b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1828ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, 1829ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 1830ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor Expr *Sub, 1831ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 1832ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, 1833f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiExprArg(&Sub, 1), 1834b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 1835b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1837b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ typeid(type) expression. 1838b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1839b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1840b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 184160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, 184257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor SourceLocation TypeidLoc, 184357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TypeSourceInfo *Operand, 1844b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1845c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, 184657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor RParenLoc); 1847b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 184901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 1850b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ typeid(expr) expression. 1851b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1852b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1853b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 185460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, 185557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor SourceLocation TypeidLoc, 18569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand, 1857b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 18589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, 185957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor RParenLoc); 18601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 18611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 186201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Build a new C++ __uuidof(type) expression. 186301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// 186401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// By default, performs semantic analysis to build the new expression. 186501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// Subclasses may override this routine to provide different behavior. 186601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, 186701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation TypeidLoc, 186801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TypeSourceInfo *Operand, 186901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation RParenLoc) { 187001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, 187101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet RParenLoc); 187201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 187301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 187401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Build a new C++ __uuidof(expr) expression. 187501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// 187601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// By default, performs semantic analysis to build the new expression. 187701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// Subclasses may override this routine to provide different behavior. 187801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, 187901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation TypeidLoc, 188001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Expr *Operand, 188101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation RParenLoc) { 188201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, 188301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet RParenLoc); 188401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 188501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 1886b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "this" expression. 1887b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1888b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds a new "this" expression without performing any 18891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// semantic analysis. Subclasses may override this routine to provide 1890b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// different behavior. 189160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, 1892ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor QualType ThisType, 1893ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor bool isImplicit) { 1894b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman getSema().CheckCXXThisCapture(ThisLoc); 1895b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getSema().Owned( 1896828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, 1897828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor isImplicit)); 1898b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1899b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1900b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ throw expression. 1901b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1902b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1903b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1904bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, 1905bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor bool IsThrownVariableInScope) { 1906bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); 1907b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1908b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1909b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ default-argument expression. 1910b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1911b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds a new default-argument expression, which does not 1912b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// require any semantic analysis. Subclasses may override this routine to 1913b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// provide different behavior. 191460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, 1915036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor ParmVarDecl *Param) { 1916036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, 1917036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor Param)); 1918b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1919b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1920b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ zero-initialization expression. 1921b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1922b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1923b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1924ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, 1925ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 1926ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 1927ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, 19281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump MultiExprArg(getSema(), 0, 0), 1929ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor RParenLoc); 1930b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 19311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1932b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "new" expression. 1933b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1934b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1935b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 193660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, 19371bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor bool UseGlobal, 19381bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation PlacementLParen, 19391bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor MultiExprArg PlacementArgs, 19401bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation PlacementRParen, 19411bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceRange TypeIdParens, 19421bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor QualType AllocatedType, 19431bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *AllocatedTypeInfo, 19441bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor Expr *ArraySize, 19451bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation ConstructorLParen, 19461bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor MultiExprArg ConstructorArgs, 19471bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation ConstructorRParen) { 19481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getSema().BuildCXXNew(StartLoc, UseGlobal, 1949b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor PlacementLParen, 1950b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(PlacementArgs), 1951b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor PlacementRParen, 19524bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor TypeIdParens, 19531bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocatedType, 19541bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocatedTypeInfo, 19559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ArraySize, 1956b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ConstructorLParen, 1957b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(ConstructorArgs), 1958b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ConstructorRParen); 1959b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 19601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1961b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "delete" expression. 1962b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1963b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1964b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 196560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, 1966b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool IsGlobalDelete, 1967b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool IsArrayForm, 19689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand) { 1969b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, 19709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Operand); 1971b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 19721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1973b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new unary type trait expression. 1974b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1975b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1976b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 197760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, 19783d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor SourceLocation StartLoc, 19793d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *T, 19803d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor SourceLocation RParenLoc) { 19813d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); 1982b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1983b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 19846ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// \brief Build a new binary type trait expression. 19856ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// 19866ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// By default, performs semantic analysis to build the new expression. 19876ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// Subclasses may override this routine to provide different behavior. 19886ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, 19896ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation StartLoc, 19906ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *LhsT, 19916ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *RhsT, 19926ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation RParenLoc) { 19936ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); 19946ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 19956ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 199621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// \brief Build a new array type trait expression. 199721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// 199821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// By default, performs semantic analysis to build the new expression. 199921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// Subclasses may override this routine to provide different behavior. 200021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, 200121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SourceLocation StartLoc, 200221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *TSInfo, 200321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Expr *DimExpr, 200421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SourceLocation RParenLoc) { 200521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); 200621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 200721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 2008552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// \brief Build a new expression trait expression. 2009552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// 2010552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// By default, performs semantic analysis to build the new expression. 2011552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// Subclasses may override this routine to provide different behavior. 2012552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExprResult RebuildExpressionTrait(ExpressionTrait Trait, 2013552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation StartLoc, 2014552622067dc45013d240f73952fece703f5e63bdJohn Wiegley Expr *Queried, 2015552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation RParenLoc) { 2016552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); 2017552622067dc45013d240f73952fece703f5e63bdJohn Wiegley } 2018552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 20191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new (previously unresolved) declaration reference 2020b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// expression. 2021b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2022b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2023b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 202400cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor ExprResult RebuildDependentScopeDeclRefExpr( 202500cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 20262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2027f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall const TemplateArgumentListInfo *TemplateArgs) { 2028b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXScopeSpec SS; 202900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor SS.Adopt(QualifierLoc); 2030f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 2031f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (TemplateArgs) 20322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo, 2033f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall *TemplateArgs); 2034f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 20352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo); 2036b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2037b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2038b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new template-id expression. 2039b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2040b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2041b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 204260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, 2043f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall LookupResult &R, 2044f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall bool RequiresADL, 2045d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo &TemplateArgs) { 2046f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); 2047b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2048b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2049b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 2050b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2051b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2052b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 205360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXConstructExpr(QualType T, 20547cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara SourceLocation Loc, 20557cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara CXXConstructorDecl *Constructor, 20567cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool IsElidable, 20577cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara MultiExprArg Args, 20587cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates, 20597cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool RequiresZeroInit, 2060428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth CXXConstructExpr::ConstructionKind ConstructKind, 20617cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara SourceRange ParenRange) { 2062ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> ConvertedArgs(SemaRef); 2063c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, 20644411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor ConvertedArgs)) 2065f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2066c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 20674411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, 20688c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor move_arg(ConvertedArgs), 20697cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HadMultipleCandidates, 2070428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth RequiresZeroInit, ConstructKind, 2071428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth ParenRange); 2072b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2073b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2074b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 2075b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2076b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2077b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 2078ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, 2079ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 2080ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor MultiExprArg Args, 2081ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 2082ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, 2083b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LParenLoc, 2084b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(Args), 2085b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 2086b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2087b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2088b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 2089b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2090b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2091b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 2092ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, 2093ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 2094ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor MultiExprArg Args, 2095ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 2096ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, 2097b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LParenLoc, 2098b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(Args), 2099b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 2100b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 21011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2102b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new member reference expression. 2103b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2104b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2105b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 210660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, 21077c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualType BaseType, 21087c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor bool IsArrow, 21097c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor SourceLocation OperatorLoc, 21107c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2111129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall NamedDecl *FirstQualifierInScope, 21122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &MemberNameInfo, 2113129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall const TemplateArgumentListInfo *TemplateArgs) { 2114b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXScopeSpec SS; 21157c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor SS.Adopt(QualifierLoc); 21161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, 2118aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OperatorLoc, IsArrow, 2119129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SS, FirstQualifierInScope, 21202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberNameInfo, 21212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TemplateArgs); 2122b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2123b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2124129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Build a new member reference expression. 21253b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// 21263b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// By default, performs semantic analysis to build the new expression. 21273b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// Subclasses may override this routine to provide different behavior. 21289138b4e96429cbaae00c52c15c960f72b6645088Richard Smith ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, 21299138b4e96429cbaae00c52c15c960f72b6645088Richard Smith SourceLocation OperatorLoc, 21309138b4e96429cbaae00c52c15c960f72b6645088Richard Smith bool IsArrow, 21319138b4e96429cbaae00c52c15c960f72b6645088Richard Smith NestedNameSpecifierLoc QualifierLoc, 21329138b4e96429cbaae00c52c15c960f72b6645088Richard Smith NamedDecl *FirstQualifierInScope, 21339138b4e96429cbaae00c52c15c960f72b6645088Richard Smith LookupResult &R, 2134129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall const TemplateArgumentListInfo *TemplateArgs) { 21353b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor CXXScopeSpec SS; 21364c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor SS.Adopt(QualifierLoc); 21371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, 2139aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OperatorLoc, IsArrow, 2140c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall SS, FirstQualifierInScope, 2141c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R, TemplateArgs); 21423b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 21431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21442e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// \brief Build a new noexcept expression. 21452e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// 21462e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// By default, performs semantic analysis to build the new expression. 21472e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// Subclasses may override this routine to provide different behavior. 21482e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { 21492e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); 21502e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl } 21512e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 2152ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Build a new expression to compute the length of a parameter pack. 2153ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, 2154ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation PackLoc, 2155ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation RParenLoc, 2156089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor llvm::Optional<unsigned> Length) { 2157089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor if (Length) 2158089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), 2159089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor OperatorLoc, Pack, PackLoc, 2160089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor RParenLoc, *Length); 2161089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor 2162ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), 2163ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor OperatorLoc, Pack, PackLoc, 2164089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor RParenLoc); 2165ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor } 2166ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 2167b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new Objective-C @encode expression. 2168b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2169b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2170b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 217160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, 217281d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *EncodeTypeInfo, 2173b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 217481d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, 2175b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc)); 21761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 2177b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 217892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /// \brief Build a new Objective-C class message. 217960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, 218092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Selector Sel, 2181207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelectorLocs, 218292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ObjCMethodDecl *Method, 2183c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation LBracLoc, 218492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor MultiExprArg Args, 218592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor SourceLocation RBracLoc) { 218692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return SemaRef.BuildClassMessage(ReceiverTypeInfo, 218792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ReceiverTypeInfo->getType(), 218892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /*SuperLoc=*/SourceLocation(), 2189207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Sel, Method, LBracLoc, SelectorLocs, 2190f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis RBracLoc, move(Args)); 219192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 219292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 219392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /// \brief Build a new Objective-C instance message. 219460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCMessageExpr(Expr *Receiver, 219592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Selector Sel, 2196207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelectorLocs, 219792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ObjCMethodDecl *Method, 2198c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation LBracLoc, 219992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor MultiExprArg Args, 220092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor SourceLocation RBracLoc) { 22019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildInstanceMessage(Receiver, 22029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Receiver->getType(), 220392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /*SuperLoc=*/SourceLocation(), 2204207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Sel, Method, LBracLoc, SelectorLocs, 2205f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis RBracLoc, move(Args)); 220692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 220792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 2208f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// \brief Build a new Objective-C ivar reference expression. 2209f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// 2210f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// By default, performs semantic analysis to build the new expression. 2211f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// Subclasses may override this routine to provide different behavior. 221260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, 2213f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor SourceLocation IvarLoc, 2214f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor bool IsArrow, bool IsFreeIvar) { 2215f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // FIXME: We lose track of the IsFreeIvar bit. 2216f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor CXXScopeSpec SS; 2217429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Base = getSema().Owned(BaseArg); 2218f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, 2219f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Sema::LookupMemberName); 222060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2221f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FIME:*/IvarLoc, 2222d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, 2223ad00b7705f9bbee81beeac428e7c6587734ab5a6John McCall false); 2224429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Result.isInvalid() || Base.isInvalid()) 2225f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2226c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2227f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Result.get()) 2228f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor return move(Result); 2229c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2230429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), 2231c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /*FIXME:*/IvarLoc, IsArrow, SS, 2232f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FirstQualifierInScope=*/0, 2233c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt R, 2234f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*TemplateArgs=*/0); 2235f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor } 2236e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor 2237e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// \brief Build a new Objective-C property reference expression. 2238e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// 2239e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2240e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 224160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, 22423c3b7f90a863af43fa63043d396553ecf205351cJohn McCall ObjCPropertyDecl *Property, 22433c3b7f90a863af43fa63043d396553ecf205351cJohn McCall SourceLocation PropertyLoc) { 2244e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor CXXScopeSpec SS; 2245429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Base = getSema().Owned(BaseArg); 2246e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, 2247e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor Sema::LookupMemberName); 2248e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor bool IsArrow = false; 224960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2250e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*FIME:*/PropertyLoc, 2251d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, false); 2252429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Result.isInvalid() || Base.isInvalid()) 2253f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2254c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2255e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (Result.get()) 2256e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor return move(Result); 2257c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2258429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), 2259c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /*FIXME:*/PropertyLoc, IsArrow, 2260c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SS, 2261e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*FirstQualifierInScope=*/0, 2262c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt R, 2263e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*TemplateArgs=*/0); 2264e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor } 2265c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 226612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// \brief Build a new Objective-C property reference expression. 22679cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor /// 22689cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor /// By default, performs semantic analysis to build the new expression. 226912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// Subclasses may override this routine to provide different behavior. 227012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, 227112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *Getter, 227212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *Setter, 227312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation PropertyLoc) { 227412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // Since these expressions can only be value-dependent, we do not 227512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // need to perform semantic analysis again. 227612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return Owned( 227712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, 227812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall VK_LValue, OK_ObjCProperty, 227912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall PropertyLoc, Base)); 22809cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor } 22819cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor 2282f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// \brief Build a new Objective-C "isa" expression. 2283f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// 2284f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// By default, performs semantic analysis to build the new expression. 2285f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// Subclasses may override this routine to provide different behavior. 228660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, 2287f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor bool IsArrow) { 2288f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor CXXScopeSpec SS; 2289429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Base = getSema().Owned(BaseArg); 2290f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, 2291f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Sema::LookupMemberName); 229260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2293f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FIME:*/IsaLoc, 2294d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, false); 2295429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Result.isInvalid() || Base.isInvalid()) 2296f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2297c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2298f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Result.get()) 2299f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor return move(Result); 2300c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2301429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), 2302c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /*FIXME:*/IsaLoc, IsArrow, SS, 2303f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FirstQualifierInScope=*/0, 2304c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt R, 2305f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*TemplateArgs=*/0); 2306f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor } 2307c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2308b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new shuffle vector expression. 2309b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2310b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2311b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 231260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, 2313f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall MultiExprArg SubExprs, 2314f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation RParenLoc) { 2315b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Find the declaration for __builtin_shufflevector 23161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const IdentifierInfo &Name 2317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.Context.Idents.get("__builtin_shufflevector"); 2318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); 2319b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); 2320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); 23211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2322b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Build a reference to the __builtin_shufflevector builtin 2323b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); 2324429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Callee 2325429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), 2326429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley VK_LValue, BuiltinLoc)); 2327429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley Callee = SemaRef.UsualUnaryConversions(Callee.take()); 2328429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Callee.isInvalid()) 2329429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return ExprError(); 23301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Build the CallExpr 2332b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor unsigned NumSubExprs = SubExprs.size(); 2333b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Expr **Subs = (Expr **)SubExprs.release(); 2334429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult TheCall = SemaRef.Owned( 2335429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(), 2336b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Subs, NumSubExprs, 23375291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor Builtin->getCallResultType(), 2338f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr::getValueKindForType(Builtin->getResultType()), 2339429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley RParenLoc)); 23401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2341b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Type-check the __builtin_shufflevector expression. 2342429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take())); 2343b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 234443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 23458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \brief Build a new template argument pack expansion. 23468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 23478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// By default, performs semantic analysis to build a new pack expansion 23488491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// for a template argument. Subclasses may override this routine to provide 23498491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// different behavior. 23508491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, 2351cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor SourceLocation EllipsisLoc, 2352cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 23538491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor switch (Pattern.getArgument().getKind()) { 23547a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor case TemplateArgument::Expression: { 23557a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor ExprResult Result 235667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor = getSema().CheckPackExpansion(Pattern.getSourceExpression(), 235767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor EllipsisLoc, NumExpansions); 23587a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor if (Result.isInvalid()) 23597a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor return TemplateArgumentLoc(); 23607a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor 23617a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor return TemplateArgumentLoc(Result.get(), Result.get()); 23627a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor } 2363dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 23648491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Template: 2365a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor return TemplateArgumentLoc(TemplateArgument( 2366a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor Pattern.getArgument().getAsTemplate(), 23672be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor NumExpansions), 2368b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Pattern.getTemplateQualifierLoc(), 2369a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor Pattern.getTemplateNameLoc(), 2370a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor EllipsisLoc); 23718491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 23728491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Null: 23738491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Integral: 23748491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Declaration: 23758491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Pack: 2376a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 23778491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor llvm_unreachable("Pack expansion pattern has no parameter packs"); 23788491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 23798491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Type: 23808491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (TypeSourceInfo *Expansion 23818491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), 2382cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor EllipsisLoc, 2383cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions)) 23848491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), 23858491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Expansion); 23868491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor break; 23878491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 23888491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 23898491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return TemplateArgumentLoc(); 23908491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 23918491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 2392dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// \brief Build a new expression pack expansion. 2393dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// 2394dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// By default, performs semantic analysis to build a new pack expansion 2395dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// for an expression. Subclasses may override this routine to provide 2396dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// different behavior. 239767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, 239867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> NumExpansions) { 239967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); 2400dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2401dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 2402dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman /// \brief Build a new atomic operation expression. 2403dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman /// 2404dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman /// By default, performs semantic analysis to build the new expression. 2405dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman /// Subclasses may override this routine to provide different behavior. 2406dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, 2407dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman MultiExprArg SubExprs, 2408dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman QualType RetTy, 2409dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman AtomicExpr::AtomicOp Op, 2410dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman SourceLocation RParenLoc) { 2411dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman // Just create the expression; there is not any interesting semantic 2412dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman // analysis here because we can't actually build an AtomicExpr until 2413dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman // we are sure it is semantically sound. 2414dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman unsigned NumSubExprs = SubExprs.size(); 2415dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman Expr **Subs = (Expr **)SubExprs.release(); 2416dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs, 2417dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman NumSubExprs, RetTy, Op, 2418dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman RParenLoc); 2419dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman } 2420dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 242143fed0de4f5bc189e45562491f83d5193eb8dac0John McCallprivate: 2422c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TypeLoc TransformTypeInObjectScope(TypeLoc TL, 2423c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType, 2424c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *FirstQualifierInScope, 2425c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor CXXScopeSpec &SS); 2426b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 2427b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, 2428b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor QualType ObjectType, 2429b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor NamedDecl *FirstQualifierInScope, 2430b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor CXXScopeSpec &SS); 2431577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}; 2432b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 243343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 243460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { 243543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!S) 243643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return SemaRef.Owned(S); 24371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 243843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor switch (S->getStmtClass()) { 243943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor case Stmt::NoStmtClass: break; 24401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 244143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform individual statement nodes 244243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) \ 244343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); 244463c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define ABSTRACT_STMT(Node) 244543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) 24464bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 24471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 244843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform expressions by calling TransformExpr. 244943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) 24507381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 245143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) case Stmt::Node##Class: 24524bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 245343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor { 245460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); 245543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (E.isInvalid()) 2456f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 24571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take())); 245943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 24601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 24611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24623fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 246343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 24641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2466670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregortemplate<typename Derived> 246760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { 2468b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!E) 2469b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.Owned(E); 2470b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2471b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor switch (E->getStmtClass()) { 2472b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::NoStmtClass: break; 2473b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define STMT(Node, Parent) case Stmt::Node##Class: break; 24747381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 2475b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent) \ 2476454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); 24774bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 24781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 24791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24803fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 2481657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor} 2482657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor 2483657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregortemplate<typename Derived> 2484aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorbool TreeTransform<Derived>::TransformExprs(Expr **Inputs, 2485aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor unsigned NumInputs, 2486aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool IsCall, 2487686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<Expr *> &Outputs, 2488aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool *ArgChanged) { 2489aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor for (unsigned I = 0; I != NumInputs; ++I) { 2490aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor // If requested, drop call arguments that need to be dropped. 2491aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (IsCall && getDerived().DropCallArgument(Inputs[I])) { 2492aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (ArgChanged) 2493aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor *ArgChanged = true; 2494aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2495aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor break; 2496aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 2497aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2498dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { 2499dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Expr *Pattern = Expansion->getPattern(); 2500dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2501686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<UnexpandedParameterPack, 2> Unexpanded; 2502dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 2503dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 2504dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2505dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // Determine whether the set of unexpanded parameter packs can and should 2506dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // be expanded. 2507dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor bool Expand = true; 2508d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 250967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> OrigNumExpansions 251067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor = Expansion->getNumExpansions(); 251167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; 2512dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), 2513dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Pattern->getSourceRange(), 2514a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 2515d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Expand, RetainExpansion, 2516d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) 2517dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2518dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2519dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (!Expand) { 2520dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // The transform has determined that we should perform a simple 2521dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // transformation on the pack expansion, producing another pack 2522dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // expansion. 2523dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 2524dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult OutPattern = getDerived().TransformExpr(Pattern); 2525dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (OutPattern.isInvalid()) 2526dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2527dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2528dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), 252967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor Expansion->getEllipsisLoc(), 253067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor NumExpansions); 2531dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (Out.isInvalid()) 2532dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2533dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2534dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (ArgChanged) 2535dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor *ArgChanged = true; 2536dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Outputs.push_back(Out.get()); 2537dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor continue; 2538dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2539c8fc90a854b4ccba21c85884676a80334159dd94John McCall 2540c8fc90a854b4ccba21c85884676a80334159dd94John McCall // Record right away that the argument was changed. This needs 2541c8fc90a854b4ccba21c85884676a80334159dd94John McCall // to happen even if the array expands to nothing. 2542c8fc90a854b4ccba21c85884676a80334159dd94John McCall if (ArgChanged) *ArgChanged = true; 2543dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2544dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // The transform has determined that we should perform an elementwise 2545dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // expansion of the pattern. Do so. 2546cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 2547dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 2548dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult Out = getDerived().TransformExpr(Pattern); 2549dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (Out.isInvalid()) 2550dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2551dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 255277d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.get()->containsUnexpandedParameterPack()) { 255367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), 255467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor OrigNumExpansions); 255577d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.isInvalid()) 255677d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor return true; 255777d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor } 255877d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor 2559dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Outputs.push_back(Out.get()); 2560dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2561dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2562dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor continue; 2563dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2564dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2565aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor ExprResult Result = getDerived().TransformExpr(Inputs[I]); 2566aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (Result.isInvalid()) 2567aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return true; 2568aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2569aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (Result.get() != Inputs[I] && ArgChanged) 2570aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor *ArgChanged = true; 2571aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2572aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Outputs.push_back(Result.get()); 2573aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 2574aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2575aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return false; 2576aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor} 2577aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2578aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregortemplate<typename Derived> 2579c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorNestedNameSpecifierLoc 2580c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorTreeTransform<Derived>::TransformNestedNameSpecifierLoc( 2581c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc NNS, 2582c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType, 2583c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *FirstQualifierInScope) { 2584686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; 2585c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; 2586c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Qualifier = Qualifier.getPrefix()) 2587c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Qualifiers.push_back(Qualifier); 2588c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2589c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor CXXScopeSpec SS; 2590c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor while (!Qualifiers.empty()) { 2591c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); 2592c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); 2593c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2594c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor switch (QNNS->getKind()) { 2595c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::Identifier: 2596c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0, 2597c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor *QNNS->getAsIdentifier(), 2598c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalBeginLoc(), 2599c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalEndLoc(), 2600c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor ObjectType, false, SS, 2601c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor FirstQualifierInScope, false)) 2602c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(); 2603c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2604c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2605c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2606c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::Namespace: { 2607c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamespaceDecl *NS 2608c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast_or_null<NamespaceDecl>( 2609c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor getDerived().TransformDecl( 2610c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalBeginLoc(), 2611c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QNNS->getAsNamespace())); 2612c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); 2613c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2614c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 2615c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2616c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::NamespaceAlias: { 2617c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamespaceAliasDecl *Alias 2618c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast_or_null<NamespaceAliasDecl>( 2619c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor getDerived().TransformDecl(Q.getLocalBeginLoc(), 2620c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QNNS->getAsNamespaceAlias())); 2621c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), 2622c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalEndLoc()); 2623c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2624c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 2625c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2626c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::Global: 2627c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // There is no meaningful transformation that one could perform on the 2628c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // global scope. 2629c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); 2630c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2631c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2632c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::TypeSpecWithTemplate: 2633c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::TypeSpec: { 2634c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, 2635c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor FirstQualifierInScope, SS); 2636c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2637c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (!TL) 2638c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(); 2639c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2640c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || 2641c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor (SemaRef.getLangOptions().CPlusPlus0x && 2642c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TL.getType()->isEnumeralType())) { 2643c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor assert(!TL.getType().hasLocalQualifiers() && 2644c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor "Can't get cv-qualifiers here"); 264595aafb2453e1fecec8dcfd9e125cd78277f45859Richard Smith if (TL.getType()->isEnumeralType()) 264695aafb2453e1fecec8dcfd9e125cd78277f45859Richard Smith SemaRef.Diag(TL.getBeginLoc(), 264795aafb2453e1fecec8dcfd9e125cd78277f45859Richard Smith diag::warn_cxx98_compat_enum_nested_name_spec); 2648c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, 2649c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalEndLoc()); 2650c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2651c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 265200c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu // If the nested-name-specifier is an invalid type def, don't emit an 265300c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu // error because a previous error should have already been emitted. 265400c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL); 265500c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) { 265600c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) 265700c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu << TL.getType() << SS.getRange(); 265800c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu } 2659c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(); 2660c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 26617c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor } 2662c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 26637c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor // The qualifier-in-scope and object type only apply to the leftmost entity. 2664c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor FirstQualifierInScope = 0; 26657c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor ObjectType = QualType(); 2666c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 2667c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2668c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // Don't rebuild the nested-name-specifier if we don't have to. 2669c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && 2670c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor !getDerived().AlwaysRebuild()) 2671c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NNS; 2672c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2673c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // If we can re-use the source-location data from the original 2674c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // nested-name-specifier, do so. 2675c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (SS.location_size() == NNS.getDataLength() && 2676c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) 2677c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); 2678c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2679c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // Allocate new nested-name-specifier location information. 2680c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return SS.getWithLocInContext(SemaRef.Context); 2681c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor} 2682c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2683c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived> 26842577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclarationNameInfo 26852577743c5650c646fb705df01403707e94f2df04Abramo BagnaraTreeTransform<Derived> 268643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { 26872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName Name = NameInfo.getName(); 268881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor if (!Name) 26892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(); 269081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor 269181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor switch (Name.getNameKind()) { 269281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::Identifier: 269381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCZeroArgSelector: 269481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCOneArgSelector: 269581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCMultiArgSelector: 269681499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXOperatorName: 26973e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt case DeclarationName::CXXLiteralOperatorName: 269881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXUsingDirective: 26992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return NameInfo; 27001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 270181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXConstructorName: 270281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXDestructorName: 270381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXConversionFunctionName: { 27042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TypeSourceInfo *NewTInfo; 27052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara CanQualType NewCanTy; 27062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { 270743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NewTInfo = getDerived().TransformType(OldTInfo); 270843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (!NewTInfo) 270943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return DeclarationNameInfo(); 271043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); 27112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 27122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara else { 27132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewTInfo = 0; 27142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); 271543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType NewT = getDerived().TransformType(Name.getCXXNameType()); 27162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (NewT.isNull()) 27172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(); 27182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewCanTy = SemaRef.Context.getCanonicalType(NewT); 27192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 27201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName NewName 27222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), 27232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewCanTy); 27242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NewNameInfo(NameInfo); 27252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewNameInfo.setName(NewName); 27262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewNameInfo.setNamedTypeInfo(NewTInfo); 27272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return NewNameInfo; 272881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor } 27291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 27301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2731b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unknown name kind."); 273281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor} 273381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor 273481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregortemplate<typename Derived> 27351eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 2736fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, 2737fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName Name, 2738fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 2739fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor QualType ObjectType, 2740fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor NamedDecl *FirstQualifierInScope) { 2741fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { 2742fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateDecl *Template = QTN->getTemplateDecl(); 2743fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor assert(Template && "qualified template name must refer to a template"); 2744fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2745fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateDecl *TransTemplate 2746fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, 2747fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor Template)); 2748fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!TransTemplate) 2749fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 2750fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2751fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2752fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SS.getScopeRep() == QTN->getQualifier() && 2753fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransTemplate == Template) 2754fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 2755fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2756fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), 2757fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransTemplate); 2758fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2759fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2760fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { 2761fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (SS.getScopeRep()) { 2762fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor // These apply to the scope specifier, not the template. 2763fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType = QualType(); 2764fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor FirstQualifierInScope = 0; 2765fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2766fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2767fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2768fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SS.getScopeRep() == DTN->getQualifier() && 2769fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType.isNull()) 2770fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 2771fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2772fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (DTN->isIdentifier()) { 2773fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(SS, 2774fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor *DTN->getIdentifier(), 2775fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor NameLoc, 2776fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType, 2777fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor FirstQualifierInScope); 2778fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2779fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2780fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, 2781fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType); 2782fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2783fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2784fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (TemplateDecl *Template = Name.getAsTemplateDecl()) { 2785fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateDecl *TransTemplate 2786fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, 2787fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor Template)); 2788fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!TransTemplate) 2789fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 2790fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2791fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2792fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransTemplate == Template) 2793fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 2794fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2795fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(TransTemplate); 2796fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2797fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2798fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (SubstTemplateTemplateParmPackStorage *SubstPack 2799fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = Name.getAsSubstTemplateTemplateParmPack()) { 2800fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateTemplateParmDecl *TransParam 2801fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = cast_or_null<TemplateTemplateParmDecl>( 2802fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); 2803fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!TransParam) 2804fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 2805fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2806fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2807fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransParam == SubstPack->getParameterPack()) 2808fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 2809fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2810fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(TransParam, 2811fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SubstPack->getArgumentPack()); 2812fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2813fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2814fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor // These should be getting filtered out before they reach the AST. 2815fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor llvm_unreachable("overloaded function decl survived to here"); 2816fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 2817fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor} 2818fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2819fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregortemplate<typename Derived> 2820833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallvoid TreeTransform<Derived>::InventTemplateArgumentLoc( 2821833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgument &Arg, 2822833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &Output) { 2823833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation Loc = getDerived().getBaseLocation(); 2824670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor switch (Arg.getKind()) { 2825670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Null: 28269f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin llvm_unreachable("null template argument in TreeTransform"); 2827833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2828833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2829833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Type: 2830833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(Arg, 2831a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); 2832c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2833833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2834833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2835788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: 2836b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor case TemplateArgument::TemplateExpansion: { 2837b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor NestedNameSpecifierLocBuilder Builder; 2838b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor TemplateName Template = Arg.getAsTemplate(); 2839b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) 2840b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); 2841b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) 2842b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); 2843b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor 2844b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (Arg.getKind() == TemplateArgument::Template) 2845b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Output = TemplateArgumentLoc(Arg, 2846b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.getWithLocInContext(SemaRef.Context), 2847b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Loc); 2848b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor else 2849b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Output = TemplateArgumentLoc(Arg, 2850b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.getWithLocInContext(SemaRef.Context), 2851b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Loc, Loc); 2852b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor 2853a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor break; 2854b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor } 2855a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 2856833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Expression: 2857833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); 2858833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2859833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2860833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Declaration: 2861670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Integral: 2862833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Pack: 2863828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); 2864833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2865833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 2866833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 2867833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2868833ca991c1bfc967f0995974ca86f66ba1f666b5John McCalltemplate<typename Derived> 2869833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TreeTransform<Derived>::TransformTemplateArgument( 2870833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc &Input, 2871833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &Output) { 2872833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgument &Arg = Input.getArgument(); 2873833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall switch (Arg.getKind()) { 2874833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Null: 2875833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Integral: 2876833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = Input; 2877833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 28781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2879670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Type: { 2880a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *DI = Input.getTypeSourceInfo(); 2881833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (DI == NULL) 2882a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall DI = InventTypeSourceInfo(Input.getArgument().getAsType()); 2883833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2884833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall DI = getDerived().TransformType(DI); 2885833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!DI) return true; 2886833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2887833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); 2888833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2889670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 28901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2891670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Declaration: { 2892833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: we should never have to transform one of these. 2893972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor DeclarationName Name; 2894972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) 2895972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor Name = ND->getDeclName(); 2896788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor TemporaryBase Rebase(*this, Input.getLocation(), Name); 28977c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); 2898833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!D) return true; 2899833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2900828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Expr *SourceExpr = Input.getSourceDeclExpression(); 2901828bff2079b6a91ecd7ed5b842c59527d7682789John McCall if (SourceExpr) { 2902828bff2079b6a91ecd7ed5b842c59527d7682789John McCall EnterExpressionEvaluationContext Unevaluated(getSema(), 2903f6702a3927147655206ae729a84339c4fda4c651Richard Smith Sema::ConstantEvaluated); 290460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(SourceExpr); 29059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SourceExpr = (E.isInvalid() ? 0 : E.take()); 2906828bff2079b6a91ecd7ed5b842c59527d7682789John McCall } 2907828bff2079b6a91ecd7ed5b842c59527d7682789John McCall 2908828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); 2909833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2910670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 29111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2912788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: { 2913b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); 2914b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (QualifierLoc) { 2915b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); 2916b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (!QualifierLoc) 2917b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor return true; 2918b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor } 2919b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor 29201d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor CXXScopeSpec SS; 29211d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor SS.Adopt(QualifierLoc); 2922788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor TemplateName Template 29231d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), 29241d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor Input.getTemplateNameLoc()); 2925788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor if (Template.isNull()) 2926788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return true; 2927c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2928b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, 2929788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor Input.getTemplateNameLoc()); 2930788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return false; 2931788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor } 2932a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 2933a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 2934a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor llvm_unreachable("Caller should expand pack expansions"); 2935a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 2936670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Expression: { 2937f6702a3927147655206ae729a84339c4fda4c651Richard Smith // Template argument expressions are constant expressions. 29381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EnterExpressionEvaluationContext Unevaluated(getSema(), 2939f6702a3927147655206ae729a84339c4fda4c651Richard Smith Sema::ConstantEvaluated); 29401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2941833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Expr *InputExpr = Input.getSourceExpression(); 2942833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); 2943833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2944223de2497fdaacf3a6b0a123c12265ca837abf19Chris Lattner ExprResult E = getDerived().TransformExpr(InputExpr); 2945833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (E.isInvalid()) return true; 29469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); 2947833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2948670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 29491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2950670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Pack: { 2951686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<TemplateArgument, 4> TransformedArgs; 2952670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor TransformedArgs.reserve(Arg.pack_size()); 29531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (TemplateArgument::pack_iterator A = Arg.pack_begin(), 2954670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor AEnd = Arg.pack_end(); 2955670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor A != AEnd; ++A) { 29561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2957833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: preserve source information here when we start 2958833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // caring about parameter packs. 2959833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2960828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TemplateArgumentLoc InputArg; 2961828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TemplateArgumentLoc OutputArg; 2962828bff2079b6a91ecd7ed5b842c59527d7682789John McCall getDerived().InventTemplateArgumentLoc(*A, InputArg); 2963828bff2079b6a91ecd7ed5b842c59527d7682789John McCall if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) 2964833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 2965833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2966828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TransformedArgs.push_back(OutputArg.getArgument()); 2967670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 2968910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor 2969910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TemplateArgument *TransformedArgsPtr 2970910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor = new (getSema().Context) TemplateArgument[TransformedArgs.size()]; 2971910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor std::copy(TransformedArgs.begin(), TransformedArgs.end(), 2972910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TransformedArgsPtr); 2973910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr, 2974910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TransformedArgs.size()), 2975910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor Input.getLocInfo()); 2976833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2977670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 2978670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 29791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2980670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Work around bogus GCC warning 2981833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 2982670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor} 2983670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor 29847ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// \brief Iterator adaptor that invents template argument location information 29857ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// for each of the template arguments in its underlying iterator. 29867ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename Derived, typename InputIterator> 29877ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorclass TemplateArgumentLocInventIterator { 29887ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TreeTransform<Derived> &Self; 29897ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Iter; 29907ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29917ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorpublic: 29927ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc value_type; 29937ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc reference; 29947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef typename std::iterator_traits<InputIterator>::difference_type 29957ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor difference_type; 29967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef std::input_iterator_tag iterator_category; 29977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 29987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class pointer { 29997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Arg; 3000fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 30017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 30027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } 30037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLoc *operator->() const { return &Arg; } 30057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 30067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator() { } 30087ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30097ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, 30107ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Iter) 30117ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor : Self(Self), Iter(Iter) { } 30127ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator &operator++() { 30147ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++Iter; 30157ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return *this; 3016fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor } 3017fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 30187ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator operator++(int) { 30197ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator Old(*this); 30207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++(*this); 30217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Old; 30227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 30237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor reference operator*() const { 30257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Result; 30267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor Self.InventTemplateArgumentLoc(*Iter, Result); 30277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Result; 30287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 30297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor pointer operator->() const { return pointer(**this); } 30317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator==(const TemplateArgumentLocInventIterator &X, 30337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLocInventIterator &Y) { 30347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Iter == Y.Iter; 30357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 3036fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 30377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator!=(const TemplateArgumentLocInventIterator &X, 30387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLocInventIterator &Y) { 30397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Iter != Y.Iter; 30407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 30417ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor}; 30427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30437f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregortemplate<typename Derived> 30447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename InputIterator> 30457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorbool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, 30467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Last, 30477f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor TemplateArgumentListInfo &Outputs) { 30487ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor for (; First != Last; ++First) { 30497f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor TemplateArgumentLoc Out; 30507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc In = *First; 30518491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30528491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (In.getArgument().getKind() == TemplateArgument::Pack) { 30538491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // Unpack argument packs, which we translate them into separate 30548491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // arguments. 30557ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // FIXME: We could do much better if we could guarantee that the 30567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // TemplateArgumentLocInfo for the pack expansion would be usable for 30577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // all of the template arguments in the argument pack. 30587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLocInventIterator<Derived, 30597ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgument::pack_iterator> 30607ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor PackLocIterator; 30617ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor if (TransformTemplateArguments(PackLocIterator(*this, 30627ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor In.getArgument().pack_begin()), 30637ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor PackLocIterator(*this, 30647ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor In.getArgument().pack_end()), 30657ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor Outputs)) 30667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return true; 30678491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30688491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 30698491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 30708491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30718491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (In.getArgument().isPackExpansion()) { 30728491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // We have a pack expansion, for which we will be substituting into 30738491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // the pattern. 30748491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor SourceLocation Ellipsis; 3075cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> OrigNumExpansions; 30768491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc Pattern 3077cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions, 3078cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor getSema().Context); 30798491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 3080686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<UnexpandedParameterPack, 2> Unexpanded; 30818491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 30828491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 30838491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30848491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // Determine whether the set of unexpanded parameter packs can and should 30858491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // be expanded. 30868491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor bool Expand = true; 3087d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 3088cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; 30898491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TryExpandParameterPacks(Ellipsis, 30908491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Pattern.getSourceRange(), 3091a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 3092d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Expand, 3093d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor RetainExpansion, 3094d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) 30958491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 30968491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30978491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (!Expand) { 30988491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The transform has determined that we should perform a simple 30998491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // transformation on the pack expansion, producing another pack 31008491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // expansion. 31018491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc OutPattern; 31028491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 31038491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) 31048491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 31058491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 3106cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, 3107cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions); 31088491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (Out.getArgument().isNull()) 31098491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 31108491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 31118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Outputs.addArgument(Out); 31128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 31138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 31148491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 31158491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The transform has determined that we should perform an elementwise 31168491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // expansion of the pattern. Do so. 3117cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 31188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 31198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 31208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, Out)) 31218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 31228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 312377d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.getArgument().containsUnexpandedParameterPack()) { 3124cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Out = getDerived().RebuildPackExpansion(Out, Ellipsis, 3125cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor OrigNumExpansions); 312677d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.getArgument().isNull()) 312777d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor return true; 312877d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor } 312977d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor 31308491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Outputs.addArgument(Out); 31318491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 31328491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 31333cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 31343cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // forgetting the partially-substituted parameter pack. 31353cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (RetainExpansion) { 31363cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 31373cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 31383cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, Out)) 31393cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor return true; 31403cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 3141cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Out = getDerived().RebuildPackExpansion(Out, Ellipsis, 3142cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor OrigNumExpansions); 31433cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (Out.getArgument().isNull()) 31443cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor return true; 31453cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 31463cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor Outputs.addArgument(Out); 31473cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor } 3148d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 31498491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 31508491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 31518491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 31528491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The simple case: 31538491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(In, Out)) 31547f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return true; 31557f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 31567f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor Outputs.addArgument(Out); 31577f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor } 31587f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 31597f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return false; 31607f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 31617f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor} 31627f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 3163577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 3164577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// Type transformation 3165577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 3166577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3167577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 316843fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::TransformType(QualType T) { 3169577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (getDerived().AlreadyTransformed(T)) 3170577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return T; 31711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3172a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Temporary workaround. All of these transformations should 3173a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // eventually turn into transformations on TypeLocs. 3174c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, 3175c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor getDerived().getBaseLocation()); 3176c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 317743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeSourceInfo *NewDI = getDerived().TransformType(DI); 31781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3179a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (!NewDI) 3180a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 31811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3182a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return NewDI->getType(); 3183577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 31841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3185577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 318643fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { 3187f6702a3927147655206ae729a84339c4fda4c651Richard Smith // Refine the base location to the type's location. 3188f6702a3927147655206ae729a84339c4fda4c651Richard Smith TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), 3189f6702a3927147655206ae729a84339c4fda4c651Richard Smith getDerived().getBaseEntity()); 3190a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlreadyTransformed(DI->getType())) 3191a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return DI; 31921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3193a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder TLB; 31941bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 3195a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLoc TL = DI->getTypeLoc(); 3196a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TLB.reserve(TL.getFullDataSize()); 31971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 319843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result = getDerived().TransformType(TLB, TL); 3199a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3200a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return 0; 32011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3202a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall return TLB.getTypeSourceInfo(SemaRef.Context, Result); 3203577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 32041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3206a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 320743fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { 3208a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall switch (T.getTypeLocClass()) { 3209a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT) 3210a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT) \ 3211a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall case TypeLoc::CLASS: \ 321243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); 3213a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def" 3214a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3215577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 32169f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin llvm_unreachable("unhandled type loc!"); 3217a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3218577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 32191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3220a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// FIXME: By default, this routine adds type qualifiers only to types 3221a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that can have qualifiers, and silently suppresses those qualifiers 3222a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that are not permitted (e.g., qualifiers on reference or function 3223a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// types). This is the right thing for template instantiation, but 3224a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// probably not for other clients. 32251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 32261eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3227a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, 322843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualifiedTypeLoc T) { 3229a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor Qualifiers Quals = T.getType().getLocalQualifiers(); 3230a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 323143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); 3232a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3233577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 32341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3235a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Silently suppress qualifiers if the result type can't be qualified. 3236a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: this is the right thing for template instantiation, but 3237a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // probably not for other clients. 3238a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result->isFunctionType() || Result->isReferenceType()) 3239a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 32401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3241f85e193739c953358c865005855253af4f68a497John McCall // Suppress Objective-C lifetime qualifiers if they don't make sense for the 3242e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // resulting type. 3243e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor if (Quals.hasObjCLifetime()) { 3244e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor if (!Result->isObjCLifetimeType() && !Result->isDependentType()) 3245e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Quals.removeObjCLifetime(); 32464020caec546d221170072d2388b57d151cb26111Douglas Gregor else if (Result.getObjCLifetime()) { 3247e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // Objective-C ARC: 3248e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // A lifetime qualifier applied to a substituted template parameter 3249e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // overrides the lifetime qualifier from the template argument. 3250e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor if (const SubstTemplateTypeParmType *SubstTypeParam 3251e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor = dyn_cast<SubstTemplateTypeParmType>(Result)) { 3252e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor QualType Replacement = SubstTypeParam->getReplacementType(); 3253e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Qualifiers Qs = Replacement.getQualifiers(); 3254e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Qs.removeObjCLifetime(); 3255e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Replacement 3256e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), 3257e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Qs); 3258e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Result = SemaRef.Context.getSubstTemplateTypeParmType( 3259e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor SubstTypeParam->getReplacedParameter(), 3260e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Replacement); 3261e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor TLB.TypeWasModifiedSafely(Result); 3262e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } else { 32634020caec546d221170072d2388b57d151cb26111Douglas Gregor // Otherwise, complain about the addition of a qualifier to an 32644020caec546d221170072d2388b57d151cb26111Douglas Gregor // already-qualified type. 32654020caec546d221170072d2388b57d151cb26111Douglas Gregor SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange(); 3266b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant) 32674020caec546d221170072d2388b57d151cb26111Douglas Gregor << Result << R; 32684020caec546d221170072d2388b57d151cb26111Douglas Gregor 3269e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Quals.removeObjCLifetime(); 3270e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } 3271e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } 3272e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } 32732865474261a608c7873b87ba4af110d17907896dJohn McCall if (!Quals.empty()) { 32742865474261a608c7873b87ba4af110d17907896dJohn McCall Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); 32752865474261a608c7873b87ba4af110d17907896dJohn McCall TLB.push<QualifiedTypeLoc>(Result); 32762865474261a608c7873b87ba4af110d17907896dJohn McCall // No location information to preserve. 32772865474261a608c7873b87ba4af110d17907896dJohn McCall } 3278a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3279a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3280a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 3281a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 328243fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived> 3283b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTypeLoc 3284b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, 328543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 328643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *UnqualLookup, 3287b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor CXXScopeSpec &SS) { 3288b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor QualType T = TL.getType(); 328943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (getDerived().AlreadyTransformed(T)) 3290b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TL; 3291b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 329243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeLocBuilder TLB; 329343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result; 3294b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 329543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (isa<TemplateSpecializationType>(T)) { 3296b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TemplateSpecializationTypeLoc SpecTL 3297b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = cast<TemplateSpecializationTypeLoc>(TL); 3298b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 329943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template = 3300b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor getDerived().TransformTemplateName(SS, 3301b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL.getTypePtr()->getTemplateName(), 3302b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL.getTemplateNameLoc(), 330343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType, UnqualLookup); 3304b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor if (Template.isNull()) 3305b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TypeLoc(); 3306b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 3307b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, 3308b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Template); 330943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } else if (isa<DependentTemplateSpecializationType>(T)) { 3310b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor DependentTemplateSpecializationTypeLoc SpecTL 3311b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = cast<DependentTemplateSpecializationTypeLoc>(TL); 3312a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 3313b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TemplateName Template 3314b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = getDerived().RebuildTemplateName(SS, 3315b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor *SpecTL.getTypePtr()->getIdentifier(), 3316b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL.getNameLoc(), 3317b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor ObjectType, UnqualLookup); 3318a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (Template.isNull()) 3319b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TypeLoc(); 3320b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 3321b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Result = getDerived().TransformDependentTemplateSpecializationType(TLB, 3322b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL, 3323087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor Template, 3324087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor SS); 332543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } else { 332643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // Nothing special needs to be done for these. 3327b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Result = getDerived().TransformType(TLB, TL); 332843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } 3329b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 3330b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor if (Result.isNull()) 3331b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TypeLoc(); 3332b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 3333b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc(); 333443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall} 333543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 3336c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived> 3337b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTypeSourceInfo * 3338b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, 3339c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType, 3340c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *UnqualLookup, 3341c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor CXXScopeSpec &SS) { 3342c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // FIXME: Painfully copy-paste from the above! 3343c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3344b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor QualType T = TSInfo->getType(); 3345c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (getDerived().AlreadyTransformed(T)) 3346b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TSInfo; 3347c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3348c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TypeLocBuilder TLB; 3349c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType Result; 3350c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3351b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TypeLoc TL = TSInfo->getTypeLoc(); 3352c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (isa<TemplateSpecializationType>(T)) { 3353c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TemplateSpecializationTypeLoc SpecTL 3354c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast<TemplateSpecializationTypeLoc>(TL); 3355c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3356b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TemplateName Template 3357b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = getDerived().TransformTemplateName(SS, 3358fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SpecTL.getTypePtr()->getTemplateName(), 3359fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SpecTL.getTemplateNameLoc(), 3360c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor ObjectType, UnqualLookup); 3361c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (Template.isNull()) 3362b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return 0; 3363c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3364c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, 3365c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Template); 3366c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } else if (isa<DependentTemplateSpecializationType>(T)) { 3367c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor DependentTemplateSpecializationTypeLoc SpecTL 3368c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast<DependentTemplateSpecializationTypeLoc>(TL); 3369c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3370a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateName Template 3371fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = getDerived().RebuildTemplateName(SS, 33727c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor *SpecTL.getTypePtr()->getIdentifier(), 3373fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SpecTL.getNameLoc(), 33747c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor ObjectType, UnqualLookup); 3375a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (Template.isNull()) 3376b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return 0; 3377a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 3378c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Result = getDerived().TransformDependentTemplateSpecializationType(TLB, 3379a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor SpecTL, 3380087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor Template, 3381087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor SS); 3382c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } else { 3383c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // Nothing special needs to be done for these. 3384c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Result = getDerived().TransformType(TLB, TL); 3385c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 3386c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3387c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (Result.isNull()) 3388b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return 0; 3389c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3390b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TLB.getTypeSourceInfo(SemaRef.Context, Result); 3391c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor} 3392c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3393a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate <class TyLoc> static inline 3394a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { 3395a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TyLoc NewT = TLB.push<TyLoc>(T.getType()); 3396a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewT.setNameLoc(T.getNameLoc()); 3397a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return T.getType(); 3398a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 3399a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3400a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3401a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, 340243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall BuiltinTypeLoc T) { 3403ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); 3404ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor NewT.setBuiltinLoc(T.getBuiltinLoc()); 3405ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor if (T.needsExtraLocalData()) 3406ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); 3407ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return T.getType(); 3408577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3409577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 34101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3411a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, 341243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ComplexTypeLoc T) { 3413a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: recurse? 3414a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return TransformTypeSpecType(TLB, T); 3415a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 34161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3417a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3418a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, 341943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall PointerTypeLoc TL) { 3420c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt QualType PointeeType 3421c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt = getDerived().TransformType(TLB, TL.getPointeeLoc()); 342292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (PointeeType.isNull()) 342392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return QualType(); 342492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 342592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor QualType Result = TL.getType(); 3426c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (PointeeType->getAs<ObjCObjectType>()) { 342792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // A dependent pointer type 'T *' has is being transformed such 342892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // that an Objective-C class type is being replaced for 'T'. The 342992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // resulting pointer type is an ObjCObjectPointerType, not a 343092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // PointerType. 3431c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); 3432c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3433c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); 3434c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall NewT.setStarLoc(TL.getStarLoc()); 343592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return Result; 343692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 343743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 343892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (getDerived().AlwaysRebuild() || 343992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor PointeeType != TL.getPointeeLoc().getType()) { 344092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); 344192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (Result.isNull()) 344292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return QualType(); 344392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 3444f85e193739c953358c865005855253af4f68a497John McCall 3445f85e193739c953358c865005855253af4f68a497John McCall // Objective-C ARC can add lifetime qualifiers to the type that we're 3446f85e193739c953358c865005855253af4f68a497John McCall // pointing to. 3447f85e193739c953358c865005855253af4f68a497John McCall TLB.TypeWasModifiedSafely(Result->getPointeeType()); 3448f85e193739c953358c865005855253af4f68a497John McCall 344992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); 345092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor NewT.setSigilLoc(TL.getSigilLoc()); 3451c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return Result; 3452577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3453577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 34541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 34551eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3456a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, 345743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall BlockPointerTypeLoc TL) { 3458db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor QualType PointeeType 3459c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt = getDerived().TransformType(TLB, TL.getPointeeLoc()); 3460c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (PointeeType.isNull()) 3461c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return QualType(); 3462c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3463c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt QualType Result = TL.getType(); 3464c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (getDerived().AlwaysRebuild() || 3465c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt PointeeType != TL.getPointeeLoc().getType()) { 3466c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Result = getDerived().RebuildBlockPointerType(PointeeType, 3467db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor TL.getSigilLoc()); 3468db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor if (Result.isNull()) 3469db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor return QualType(); 3470db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor } 3471db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor 347239968adc66ab02275d2f561e372a20ae454bd4e7Douglas Gregor BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); 3473db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor NewT.setSigilLoc(TL.getSigilLoc()); 3474db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor return Result; 3475a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 34761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 347785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// Transforms a reference type. Note that somewhat paradoxically we 347885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// don't care whether the type itself is an l-value type or an r-value 347985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// type; we only care if the type was *written* as an l-value type 348085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// or an r-value type. 348185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCalltemplate<typename Derived> 348285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType 348385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, 348443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ReferenceTypeLoc TL) { 348585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall const ReferenceType *T = TL.getTypePtr(); 348685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 348785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall // Note that this works with the pointee-as-written. 348885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 348985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (PointeeType.isNull()) 349085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return QualType(); 349185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 349285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType Result = TL.getType(); 349385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (getDerived().AlwaysRebuild() || 349485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall PointeeType != T->getPointeeTypeAsWritten()) { 349585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Result = getDerived().RebuildReferenceType(PointeeType, 349685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->isSpelledAsLValue(), 349785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getSigilLoc()); 349885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (Result.isNull()) 349985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return QualType(); 350085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall } 350185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 3502f85e193739c953358c865005855253af4f68a497John McCall // Objective-C ARC can add lifetime qualifiers to the type that we're 3503f85e193739c953358c865005855253af4f68a497John McCall // referring to. 3504f85e193739c953358c865005855253af4f68a497John McCall TLB.TypeWasModifiedSafely( 3505f85e193739c953358c865005855253af4f68a497John McCall Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); 3506f85e193739c953358c865005855253af4f68a497John McCall 350785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall // r-value references can be rebuilt as l-value references. 350885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall ReferenceTypeLoc NewTL; 350985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (isa<LValueReferenceType>(Result)) 351085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL = TLB.push<LValueReferenceTypeLoc>(Result); 351185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall else 351285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL = TLB.push<RValueReferenceTypeLoc>(Result); 351385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL.setSigilLoc(TL.getSigilLoc()); 351485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 351585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return Result; 351685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall} 351785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 3518a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3519a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3520a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, 352143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall LValueReferenceTypeLoc TL) { 352243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TransformReferenceType(TLB, TL); 3523a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 35241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3525a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3526a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3527a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, 352843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall RValueReferenceTypeLoc TL) { 352943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TransformReferenceType(TLB, TL); 3530577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 35311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3532577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 35331eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3534a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, 353543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall MemberPointerTypeLoc TL) { 3536a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 3537577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (PointeeType.isNull()) 3538577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 35391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3540b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); 3541b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara TypeSourceInfo* NewClsTInfo = 0; 3542b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (OldClsTInfo) { 3543b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsTInfo = getDerived().TransformType(OldClsTInfo); 3544b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (!NewClsTInfo) 3545b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara return QualType(); 3546b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara } 3547b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara 3548b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara const MemberPointerType *T = TL.getTypePtr(); 3549b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara QualType OldClsType = QualType(T->getClass(), 0); 3550b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara QualType NewClsType; 3551b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (NewClsTInfo) 3552b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsType = NewClsTInfo->getType(); 3553b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara else { 3554b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsType = getDerived().TransformType(OldClsType); 3555b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (NewClsType.isNull()) 3556b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara return QualType(); 3557b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara } 35581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3559a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3560a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3561a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall PointeeType != T->getPointeeType() || 3562b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsType != OldClsType) { 3563b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, 356485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getStarLoc()); 3565a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3566a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3567a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3568577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3569a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); 3570a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSigilLoc(TL.getSigilLoc()); 3571b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewTL.setClassTInfo(NewClsTInfo); 3572a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3573a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3574577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3575577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 35761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 35771eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3578a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, 357943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ConstantArrayTypeLoc TL) { 3580f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const ConstantArrayType *T = TL.getTypePtr(); 3581a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3582577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3583577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 35841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3585a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3586a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3587a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3588a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildConstantArrayType(ElementType, 3589a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 3590a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSize(), 359185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->getIndexTypeCVRQualifiers(), 359285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3593a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3594a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3595a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3596c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3597a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); 3598a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3599a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 36001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3601a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Expr *Size = TL.getSizeExpr(); 3602a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Size) { 3603f6702a3927147655206ae729a84339c4fda4c651Richard Smith EnterExpressionEvaluationContext Unevaluated(SemaRef, 3604f6702a3927147655206ae729a84339c4fda4c651Richard Smith Sema::ConstantEvaluated); 3605a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); 3606a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3607a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(Size); 3608a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3609a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3610577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 36111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3612577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 3613577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformIncompleteArrayType( 3614a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 361543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall IncompleteArrayTypeLoc TL) { 3616f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const IncompleteArrayType *T = TL.getTypePtr(); 3617a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3618577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3619577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3621a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3622a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3623a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3624a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildIncompleteArrayType(ElementType, 3625a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 362685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->getIndexTypeCVRQualifiers(), 362785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3628a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3629a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3630a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3631c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3632a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); 3633a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3634a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 3635a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(0); 3636577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3637a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3638577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 36391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3640577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 3641a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3642a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, 364343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall VariableArrayTypeLoc TL) { 3644f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const VariableArrayType *T = TL.getTypePtr(); 3645a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3646577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3647577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 364960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SizeResult 3650a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall = getDerived().TransformExpr(T->getSizeExpr()); 3651a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (SizeResult.isInvalid()) 3652577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Size = SizeResult.take(); 3655a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3656a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3657a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3658a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType() || 3659a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Size != T->getSizeExpr()) { 3660a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildVariableArrayType(ElementType, 3661a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 36629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Size, 3663a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getIndexTypeCVRQualifiers(), 366485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3665a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3666a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3667577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 3668c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3669a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); 3670a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3671a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 3672a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(Size); 36731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3674a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3675577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 36761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3678a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3679a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, 368043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentSizedArrayTypeLoc TL) { 3681f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentSizedArrayType *T = TL.getTypePtr(); 3682a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3683577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3684577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3686f6702a3927147655206ae729a84339c4fda4c651Richard Smith // Array bounds are constant expressions. 3687f6702a3927147655206ae729a84339c4fda4c651Richard Smith EnterExpressionEvaluationContext Unevaluated(SemaRef, 3688f6702a3927147655206ae729a84339c4fda4c651Richard Smith Sema::ConstantEvaluated); 36891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36903b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Prefer the expression from the TypeLoc; the other may have been uniqued. 36913b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Expr *origSize = TL.getSizeExpr(); 36923b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!origSize) origSize = T->getSizeExpr(); 36933b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 36943b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExprResult sizeResult 36953b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall = getDerived().TransformExpr(origSize); 36963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (sizeResult.isInvalid()) 3697577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Expr *size = sizeResult.get(); 3700a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3701a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3702a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3703a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType() || 37043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall size != origSize) { 3705a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildDependentSizedArrayType(ElementType, 3706a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 37073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall size, 3708a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getIndexTypeCVRQualifiers(), 370985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3710a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3711a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3712577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 37131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3714a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // We might have any sort of array type now, but fortunately they 3715a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // all have the same location layout. 3716a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); 3717a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3718a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 37193b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall NewTL.setSizeExpr(size); 3720a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3721a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3722577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 37231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3725577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( 3726a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 372743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentSizedExtVectorTypeLoc TL) { 3728f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentSizedExtVectorType *T = TL.getTypePtr(); 3729a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3730a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: ext vector locs should be nested 3731577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3732577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3733577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 37341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3735f6702a3927147655206ae729a84339c4fda4c651Richard Smith // Vector sizes are constant expressions. 3736f6702a3927147655206ae729a84339c4fda4c651Richard Smith EnterExpressionEvaluationContext Unevaluated(SemaRef, 3737f6702a3927147655206ae729a84339c4fda4c651Richard Smith Sema::ConstantEvaluated); 3738670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor 373960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); 3740577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (Size.isInvalid()) 3741577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 37421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3743a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3744a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3745eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall ElementType != T->getElementType() || 3746eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall Size.get() != T->getSizeExpr()) { 3747a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, 37489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Size.take(), 3749577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor T->getAttributeLoc()); 3750a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3751a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3752a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3753a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3754a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Result might be dependent or not. 3755a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (isa<DependentSizedExtVectorType>(Result)) { 3756a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall DependentSizedExtVectorTypeLoc NewTL 3757a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall = TLB.push<DependentSizedExtVectorTypeLoc>(Result); 3758a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 3759a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } else { 3760a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); 3761a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 3762a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3763a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3764a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3765577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 37661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3768a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, 376943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall VectorTypeLoc TL) { 3770f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const VectorType *T = TL.getTypePtr(); 3771577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3772577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3773577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 3774577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3775a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3776a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3777a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 377882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), 3779e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson T->getVectorKind()); 3780a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3781a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3782a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3783c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3784a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); 3785a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 37861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3787a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3788577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 37891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3791a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, 379243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ExtVectorTypeLoc TL) { 3793f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const VectorType *T = TL.getTypePtr(); 3794577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3795577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3796577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 37971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3798a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3799a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3800a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3801a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildExtVectorType(ElementType, 3802a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getNumElements(), 3803a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /*FIXME*/ SourceLocation()); 3804a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3805a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3806a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3807c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3808a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); 3809a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 38101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3811a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3812577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3813577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 38141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 381521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallParmVarDecl * 38166a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas GregorTreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm, 3817fb44de956f27875def889482b5393475060392afJohn McCall int indexAdjustment, 3818d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor llvm::Optional<unsigned> NumExpansions, 3819d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor bool ExpectParameterPack) { 382021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); 38216a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeSourceInfo *NewDI = 0; 38226a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 38236a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { 38246a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor // If we're substituting into a pack expansion type and we know the 3825d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor // length we want to expand to, just substitute for the pattern. 38266a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeLoc OldTL = OldDI->getTypeLoc(); 38276a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL); 38286a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 38296a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeLocBuilder TLB; 38306a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeLoc NewTL = OldDI->getTypeLoc(); 38316a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TLB.reserve(NewTL.getFullDataSize()); 38326a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 38336a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor QualType Result = getDerived().TransformType(TLB, 38346a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OldExpansionTL.getPatternLoc()); 38356a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor if (Result.isNull()) 38366a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor return 0; 38376a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 38386a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor Result = RebuildPackExpansionType(Result, 38396a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OldExpansionTL.getPatternLoc().getSourceRange(), 38406a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OldExpansionTL.getEllipsisLoc(), 38416a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NumExpansions); 38426a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor if (Result.isNull()) 38436a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor return 0; 38446a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 38456a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor PackExpansionTypeLoc NewExpansionTL 38466a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = TLB.push<PackExpansionTypeLoc>(Result); 38476a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); 38486a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); 38496a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor } else 38506a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NewDI = getDerived().TransformType(OldDI); 385121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall if (!NewDI) 385221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return 0; 385321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 3854fb44de956f27875def889482b5393475060392afJohn McCall if (NewDI == OldDI && indexAdjustment == 0) 385521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return OldParm; 3856fb44de956f27875def889482b5393475060392afJohn McCall 3857fb44de956f27875def889482b5393475060392afJohn McCall ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, 3858fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getDeclContext(), 3859fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getInnerLocStart(), 3860fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getLocation(), 3861fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getIdentifier(), 3862fb44de956f27875def889482b5393475060392afJohn McCall NewDI->getType(), 3863fb44de956f27875def889482b5393475060392afJohn McCall NewDI, 3864fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getStorageClass(), 3865fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getStorageClassAsWritten(), 3866fb44de956f27875def889482b5393475060392afJohn McCall /* DefArg */ NULL); 3867fb44de956f27875def889482b5393475060392afJohn McCall newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), 3868fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getFunctionScopeIndex() + indexAdjustment); 3869fb44de956f27875def889482b5393475060392afJohn McCall return newParm; 387021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall} 387121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 387221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived> 387321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallbool TreeTransform<Derived>:: 3874a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TransformFunctionTypeParams(SourceLocation Loc, 3875a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParmVarDecl **Params, unsigned NumParams, 3876a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor const QualType *ParamTypes, 3877686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<QualType> &OutParamTypes, 3878686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<ParmVarDecl*> *PVars) { 3879fb44de956f27875def889482b5393475060392afJohn McCall int indexAdjustment = 0; 3880fb44de956f27875def889482b5393475060392afJohn McCall 3881a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor for (unsigned i = 0; i != NumParams; ++i) { 3882a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (ParmVarDecl *OldParm = Params[i]) { 3883fb44de956f27875def889482b5393475060392afJohn McCall assert(OldParm->getFunctionScopeIndex() == i); 3884fb44de956f27875def889482b5393475060392afJohn McCall 38856a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor llvm::Optional<unsigned> NumExpansions; 3886406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor ParmVarDecl *NewParm = 0; 3887603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (OldParm->isParameterPack()) { 3888603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We have a function parameter pack that may need to be expanded. 3889686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<UnexpandedParameterPack, 2> Unexpanded; 3890603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3891603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Find the parameter packs that could be expanded. 3892c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); 3893c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL); 3894c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor TypeLoc Pattern = ExpansionTL.getPatternLoc(); 3895c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); 3896406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); 3897406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor 3898603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Determine whether we should expand the parameter packs. 3899603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor bool ShouldExpand = false; 3900d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 39016a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor llvm::Optional<unsigned> OrigNumExpansions 39026a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = ExpansionTL.getTypePtr()->getNumExpansions(); 39036a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NumExpansions = OrigNumExpansions; 3904c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), 3905c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor Pattern.getSourceRange(), 3906a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 3907d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ShouldExpand, 3908d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor RetainExpansion, 3909d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) { 3910603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 3911603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3912603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3913603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (ShouldExpand) { 3914603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Expand the function parameter pack into multiple, separate 3915603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // parameters. 391612c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor getDerived().ExpandingFunctionParameterPack(OldParm); 3917cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 3918603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 3919603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor ParmVarDecl *NewParm 39206a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = getDerived().TransformFunctionTypeParam(OldParm, 3921fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment++, 3922d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor OrigNumExpansions, 3923d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor /*ExpectParameterPack=*/false); 3924603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (!NewParm) 3925603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 3926603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3927a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewParm->getType()); 3928a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 3929a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(NewParm); 3930603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3931d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 3932d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 3933d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor // forgetting the partially-substituted parameter pack. 3934d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (RetainExpansion) { 3935d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 3936d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ParmVarDecl *NewParm 39376a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = getDerived().TransformFunctionTypeParam(OldParm, 3938fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment++, 3939d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor OrigNumExpansions, 3940d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor /*ExpectParameterPack=*/false); 3941d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (!NewParm) 3942d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor return true; 3943d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 3944d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor OutParamTypes.push_back(NewParm->getType()); 3945d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (PVars) 3946d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor PVars->push_back(NewParm); 3947d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor } 3948d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 3949fb44de956f27875def889482b5393475060392afJohn McCall // The next parameter should have the same adjustment as the 3950fb44de956f27875def889482b5393475060392afJohn McCall // last thing we pushed, but we post-incremented indexAdjustment 3951fb44de956f27875def889482b5393475060392afJohn McCall // on every push. Also, if we push nothing, the adjustment should 3952fb44de956f27875def889482b5393475060392afJohn McCall // go down by one. 3953fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment--; 3954fb44de956f27875def889482b5393475060392afJohn McCall 3955603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We're done with the pack expansion. 3956603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor continue; 3957603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3958603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3959603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We'll substitute the parameter now without expanding the pack 3960603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // expansion. 3961406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 3962406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewParm = getDerived().TransformFunctionTypeParam(OldParm, 3963fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment, 3964d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor NumExpansions, 3965d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor /*ExpectParameterPack=*/true); 3966406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor } else { 3967406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewParm = getDerived().TransformFunctionTypeParam(OldParm, 3968fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment, 3969d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor llvm::Optional<unsigned>(), 3970d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor /*ExpectParameterPack=*/false); 3971603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3972406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor 397321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall if (!NewParm) 397421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return true; 3975603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3976a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewParm->getType()); 3977a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 3978a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(NewParm); 3979603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor continue; 3980603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3981a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3982a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Deal with the possibility that we don't have a parameter 3983a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // declaration for this parameter. 3984a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor QualType OldType = ParamTypes[i]; 3985603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor bool IsPackExpansion = false; 3986cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions; 3987406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor QualType NewType; 3988603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (const PackExpansionType *Expansion 3989603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor = dyn_cast<PackExpansionType>(OldType)) { 3990603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We have a function parameter pack that may need to be expanded. 3991603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor QualType Pattern = Expansion->getPattern(); 3992686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<UnexpandedParameterPack, 2> Unexpanded; 3993603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 3994603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3995603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Determine whether we should expand the parameter packs. 3996603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor bool ShouldExpand = false; 3997d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 3998a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), 3999a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 4000d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ShouldExpand, 4001d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor RetainExpansion, 4002d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) { 400321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return true; 4004603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4005603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4006603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (ShouldExpand) { 4007603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Expand the function parameter pack into multiple, separate 4008603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // parameters. 4009cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 4010603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 4011603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor QualType NewType = getDerived().TransformType(Pattern); 4012603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (NewType.isNull()) 4013603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 4014603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4015a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewType); 4016a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 4017a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(0); 4018603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4019603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4020603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We're done with the pack expansion. 4021603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor continue; 4022603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4023603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 40243cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 40253cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // forgetting the partially-substituted parameter pack. 40263cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (RetainExpansion) { 40273cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 40283cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor QualType NewType = getDerived().TransformType(Pattern); 40293cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (NewType.isNull()) 40303cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor return true; 40313cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 40323cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor OutParamTypes.push_back(NewType); 40333cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (PVars) 40343cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor PVars->push_back(0); 40353cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor } 4036d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 4037603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We'll substitute the parameter now without expanding the pack 4038603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // expansion. 4039603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor OldType = Expansion->getPattern(); 4040603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor IsPackExpansion = true; 4041406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 4042406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewType = getDerived().TransformType(OldType); 4043406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor } else { 4044406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewType = getDerived().TransformType(OldType); 4045a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4046603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4047603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (NewType.isNull()) 4048603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 40491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4050603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (IsPackExpansion) 4051cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NewType = getSema().Context.getPackExpansionType(NewType, 4052cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions); 4053603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4054a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewType); 4055a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 4056a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(0); 4057577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 40581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4059fb44de956f27875def889482b5393475060392afJohn McCall#ifndef NDEBUG 4060fb44de956f27875def889482b5393475060392afJohn McCall if (PVars) { 4061fb44de956f27875def889482b5393475060392afJohn McCall for (unsigned i = 0, e = PVars->size(); i != e; ++i) 4062fb44de956f27875def889482b5393475060392afJohn McCall if (ParmVarDecl *parm = (*PVars)[i]) 4063fb44de956f27875def889482b5393475060392afJohn McCall assert(parm->getFunctionScopeIndex() == i); 4064603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4065fb44de956f27875def889482b5393475060392afJohn McCall#endif 4066fb44de956f27875def889482b5393475060392afJohn McCall 4067fb44de956f27875def889482b5393475060392afJohn McCall return false; 4068fb44de956f27875def889482b5393475060392afJohn McCall} 406921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 407021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived> 407121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallQualType 407221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallTreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, 407343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FunctionProtoTypeLoc TL) { 40747e010a04fef171049291d8cb3047f118566da090Douglas Gregor // Transform the parameters and return type. 40757e010a04fef171049291d8cb3047f118566da090Douglas Gregor // 40767e010a04fef171049291d8cb3047f118566da090Douglas Gregor // We instantiate in source order, with the return type first followed by 40777e010a04fef171049291d8cb3047f118566da090Douglas Gregor // the parameters, because users tend to expect this (even if they shouldn't 40787e010a04fef171049291d8cb3047f118566da090Douglas Gregor // rely on it!). 40797e010a04fef171049291d8cb3047f118566da090Douglas Gregor // 4080dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // When the function has a trailing return type, we instantiate the 4081dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // parameters before the return type, since the return type can then refer 4082dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // to the parameters themselves (via decltype, sizeof, etc.). 4083dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // 4084686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<QualType, 4> ParamTypes; 4085686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<ParmVarDecl*, 4> ParamDecls; 4086f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const FunctionProtoType *T = TL.getTypePtr(); 40877e010a04fef171049291d8cb3047f118566da090Douglas Gregor 4088dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor QualType ResultType; 4089dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 4090dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (TL.getTrailingReturn()) { 4091a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), 4092a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getParmArray(), 4093a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getNumArgs(), 4094a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getTypePtr()->arg_type_begin(), 4095a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParamTypes, &ParamDecls)) 4096dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 4097dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 4098dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 4099dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (ResultType.isNull()) 4100dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 4101dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor } 4102dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor else { 4103dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 4104dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (ResultType.isNull()) 4105dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 4106dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 4107a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), 4108a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getParmArray(), 4109a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getNumArgs(), 4110a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getTypePtr()->arg_type_begin(), 4111a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParamTypes, &ParamDecls)) 4112dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 4113dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor } 4114dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 4115a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4116a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4117a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ResultType != T->getResultType() || 4118bd5f9f708aa31920d3bd73aa10fcb5de424c657aDouglas Gregor T->getNumArgs() != ParamTypes.size() || 4119a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { 4120a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildFunctionProtoType(ResultType, 4121a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ParamTypes.data(), 4122a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ParamTypes.size(), 4123a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->isVariadic(), 4124fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman T->getTypeQuals(), 4125c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor T->getRefQualifier(), 4126fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman T->getExtInfo()); 4127a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4128a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4129a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 41301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4131a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); 4132796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); 4133796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); 4134dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor NewTL.setTrailingReturn(TL.getTrailingReturn()); 4135a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) 4136a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setArg(i, ParamDecls[i]); 4137a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4138a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4139577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 41401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4141577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4142577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformFunctionNoProtoType( 4143a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 414443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FunctionNoProtoTypeLoc TL) { 4145f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const FunctionNoProtoType *T = TL.getTypePtr(); 4146a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 4147a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (ResultType.isNull()) 4148a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4149a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4150a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4151a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4152a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ResultType != T->getResultType()) 4153a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildFunctionNoProtoType(ResultType); 4154a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4155a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); 4156796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); 4157796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); 4158dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor NewTL.setTrailingReturn(false); 4159a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4160a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4161577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 41621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4163ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> QualType 4164ed97649e9574b9d854fa4d6109c9333ae0993554John McCallTreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, 416543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall UnresolvedUsingTypeLoc TL) { 4166f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const UnresolvedUsingType *T = TL.getTypePtr(); 41677c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); 4168ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (!D) 4169ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return QualType(); 4170ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4171ed97649e9574b9d854fa4d6109c9333ae0993554John McCall QualType Result = TL.getType(); 4172ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (getDerived().AlwaysRebuild() || D != T->getDecl()) { 4173ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Result = getDerived().RebuildUnresolvedUsingType(D); 4174ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (Result.isNull()) 4175ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return QualType(); 4176ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 4177ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4178ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // We might get an arbitrary type spec type back. We should at 4179ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // least always get a type spec type, though. 4180ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); 4181ed97649e9574b9d854fa4d6109c9333ae0993554John McCall NewTL.setNameLoc(TL.getNameLoc()); 4182ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4183ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return Result; 4184ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 4185ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4186577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4187a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, 418843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypedefTypeLoc TL) { 4189f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const TypedefType *T = TL.getTypePtr(); 4190162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TypedefNameDecl *Typedef 4191162e1c1b487352434552147967c3dd296ebee2f7Richard Smith = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), 4192162e1c1b487352434552147967c3dd296ebee2f7Richard Smith T->getDecl())); 4193577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Typedef) 4194577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 41951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4196a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4197a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4198a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Typedef != T->getDecl()) { 4199a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildTypedefType(Typedef); 4200a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4201a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4202a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4203a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4204a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); 4205a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 42061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4207a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4208577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 42091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4210577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4211a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, 421243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeOfExprTypeLoc TL) { 4213670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // typeof expressions are not potentially evaluated contexts 4214f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 42151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 421660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); 4217577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (E.isInvalid()) 4218577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 4219577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 4220a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4221a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4222cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall E.get() != TL.getUnderlyingExpr()) { 42232a984cad5ac3fdceeff2bd99daa7b90979313475John McCall Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); 4224a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4225a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4226577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 4227a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall else E.take(); 42281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4229a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); 4230cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setTypeofLoc(TL.getTypeofLoc()); 4231cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setLParenLoc(TL.getLParenLoc()); 4232cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setRParenLoc(TL.getRParenLoc()); 4233a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4234a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4235577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 42361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4238a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, 423943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeOfTypeLoc TL) { 4240cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); 4241cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); 4242cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall if (!New_Under_TI) 4243577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 42441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4245a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4246cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { 4247cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); 4248a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4249a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4250a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 42511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4252a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); 4253cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setTypeofLoc(TL.getTypeofLoc()); 4254cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setLParenLoc(TL.getLParenLoc()); 4255cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setRParenLoc(TL.getRParenLoc()); 4256cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setUnderlyingTInfo(New_Under_TI); 4257a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4258a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4259577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 42601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4262a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, 426343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DecltypeTypeLoc TL) { 4264f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DecltypeType *T = TL.getTypePtr(); 4265a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4266670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // decltype expressions are not potentially evaluated contexts 4267f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 42681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 426960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); 4270577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (E.isInvalid()) 4271577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 42721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4273a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4274a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4275a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall E.get() != T->getUnderlyingExpr()) { 42762a984cad5ac3fdceeff2bd99daa7b90979313475John McCall Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); 4277a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4278a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4279577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 4280a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall else E.take(); 4281a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4282a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); 4283a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 42841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4285a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4286577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 4287577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 4288577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4289ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType TreeTransform<Derived>::TransformUnaryTransformType( 4290ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt TypeLocBuilder &TLB, 4291ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformTypeLoc TL) { 4292ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType Result = TL.getType(); 4293ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt if (Result->isDependentType()) { 4294ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt const UnaryTransformType *T = TL.getTypePtr(); 4295ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType NewBase = 4296ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); 4297ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Result = getDerived().RebuildUnaryTransformType(NewBase, 4298ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt T->getUTTKind(), 4299ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt TL.getKWLoc()); 4300ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt if (Result.isNull()) 4301ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return QualType(); 4302ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt } 4303ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 4304ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); 4305ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt NewTL.setKWLoc(TL.getKWLoc()); 4306ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt NewTL.setParensRange(TL.getParensRange()); 4307ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); 4308ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return Result; 4309ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt} 4310ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 4311ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunttemplate<typename Derived> 431234b41d939a1328f484511c6002ba2456db879a29Richard SmithQualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, 431334b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoTypeLoc TL) { 431434b41d939a1328f484511c6002ba2456db879a29Richard Smith const AutoType *T = TL.getTypePtr(); 431534b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType OldDeduced = T->getDeducedType(); 431634b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType NewDeduced; 431734b41d939a1328f484511c6002ba2456db879a29Richard Smith if (!OldDeduced.isNull()) { 431834b41d939a1328f484511c6002ba2456db879a29Richard Smith NewDeduced = getDerived().TransformType(OldDeduced); 431934b41d939a1328f484511c6002ba2456db879a29Richard Smith if (NewDeduced.isNull()) 432034b41d939a1328f484511c6002ba2456db879a29Richard Smith return QualType(); 432134b41d939a1328f484511c6002ba2456db879a29Richard Smith } 432234b41d939a1328f484511c6002ba2456db879a29Richard Smith 432334b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType Result = TL.getType(); 432434b41d939a1328f484511c6002ba2456db879a29Richard Smith if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) { 432534b41d939a1328f484511c6002ba2456db879a29Richard Smith Result = getDerived().RebuildAutoType(NewDeduced); 432634b41d939a1328f484511c6002ba2456db879a29Richard Smith if (Result.isNull()) 432734b41d939a1328f484511c6002ba2456db879a29Richard Smith return QualType(); 432834b41d939a1328f484511c6002ba2456db879a29Richard Smith } 432934b41d939a1328f484511c6002ba2456db879a29Richard Smith 433034b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); 433134b41d939a1328f484511c6002ba2456db879a29Richard Smith NewTL.setNameLoc(TL.getNameLoc()); 433234b41d939a1328f484511c6002ba2456db879a29Richard Smith 433334b41d939a1328f484511c6002ba2456db879a29Richard Smith return Result; 433434b41d939a1328f484511c6002ba2456db879a29Richard Smith} 433534b41d939a1328f484511c6002ba2456db879a29Richard Smith 433634b41d939a1328f484511c6002ba2456db879a29Richard Smithtemplate<typename Derived> 4337a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, 433843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall RecordTypeLoc TL) { 4339f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const RecordType *T = TL.getTypePtr(); 4340577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor RecordDecl *Record 43417c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), 43427c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor T->getDecl())); 4343577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Record) 4344577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 43451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4346a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4347a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4348a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Record != T->getDecl()) { 4349a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildRecordType(Record); 4350a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4351a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4352a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 43531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4354a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); 4355a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 4356a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4357a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4358577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 43591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 43601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4361a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, 436243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall EnumTypeLoc TL) { 4363f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const EnumType *T = TL.getTypePtr(); 4364577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor EnumDecl *Enum 43657c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), 43667c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor T->getDecl())); 4367577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Enum) 4368577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 43691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4370a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4371a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4372a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Enum != T->getDecl()) { 4373a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildEnumType(Enum); 4374a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4375a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4376a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4377a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4378a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); 4379a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 43801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4381a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4382577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 43837da2431c23ef1ee8acb114e39692246e1801afc2John McCall 43843cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCalltemplate<typename Derived> 43853cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallQualType TreeTransform<Derived>::TransformInjectedClassNameType( 43863cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TypeLocBuilder &TLB, 438743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall InjectedClassNameTypeLoc TL) { 43883cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall Decl *D = getDerived().TransformDecl(TL.getNameLoc(), 43893cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TL.getTypePtr()->getDecl()); 43903cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall if (!D) return QualType(); 43913cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 43923cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); 43933cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); 43943cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return T; 43953cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 43963cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 4397577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4398577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateTypeParmType( 4399a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 440043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateTypeParmTypeLoc TL) { 4401a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return TransformTypeSpecType(TLB, TL); 4402577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 4403577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 44041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 440549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( 4406a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 440743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall SubstTemplateTypeParmTypeLoc TL) { 44080b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor const SubstTemplateTypeParmType *T = TL.getTypePtr(); 44090b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor 44100b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // Substitute into the replacement type, which itself might involve something 44110b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // that needs to be transformed. This only tends to occur with default 44120b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // template arguments of template template parameters. 44130b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); 44140b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor QualType Replacement = getDerived().TransformType(T->getReplacementType()); 44150b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor if (Replacement.isNull()) 44160b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor return QualType(); 44170b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor 44180b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // Always canonicalize the replacement type. 44190b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor Replacement = SemaRef.Context.getCanonicalType(Replacement); 44200b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor QualType Result 44210b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), 44220b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor Replacement); 44230b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor 44240b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // Propagate type-source information. 44250b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor SubstTemplateTypeParmTypeLoc NewTL 44260b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); 44270b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor NewTL.setNameLoc(TL.getNameLoc()); 44280b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor return Result; 44290b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor 443049a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall} 443149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 443249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCalltemplate<typename Derived> 4433c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( 4434c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor TypeLocBuilder &TLB, 4435c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackTypeLoc TL) { 4436c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return TransformTypeSpecType(TLB, TL); 4437c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 4438c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 4439c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregortemplate<typename Derived> 4440833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallQualType TreeTransform<Derived>::TransformTemplateSpecializationType( 444143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeLocBuilder &TLB, 444243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateSpecializationTypeLoc TL) { 444343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall const TemplateSpecializationType *T = TL.getTypePtr(); 4444828bff2079b6a91ecd7ed5b842c59527d7682789John McCall 44451d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor // The nested-name-specifier never matters in a TemplateSpecializationType, 44461d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor // because we can't have a dependent nested-name-specifier anyway. 44471d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor CXXScopeSpec SS; 444843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template 44491d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor = getDerived().TransformTemplateName(SS, T->getTemplateName(), 44501d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor TL.getTemplateNameLoc()); 445143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (Template.isNull()) 445243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return QualType(); 4453833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 445443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); 4455dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor} 445643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 4457b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmantemplate<typename Derived> 4458b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli FriedmanQualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, 4459b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicTypeLoc TL) { 4460b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); 4461b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (ValueType.isNull()) 4462b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return QualType(); 4463b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4464b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType Result = TL.getType(); 4465b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (getDerived().AlwaysRebuild() || 4466b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman ValueType != TL.getValueLoc().getType()) { 4467b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); 4468b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (Result.isNull()) 4469b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return QualType(); 4470b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 4471b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4472b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); 4473b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman NewTL.setKWLoc(TL.getKWLoc()); 4474b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman NewTL.setLParenLoc(TL.getLParenLoc()); 4475b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman NewTL.setRParenLoc(TL.getRParenLoc()); 4476b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4477b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return Result; 4478b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman} 4479b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 44807ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregornamespace { 44817ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \brief Simple iterator that traverses the template arguments in a 44827ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// container that provides a \c getArgLoc() member function. 44837ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// 44847ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// This iterator is intended to be used with the iterator form of 44857ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \c TreeTransform<Derived>::TransformTemplateArguments(). 44867ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor template<typename ArgLocContainer> 44877ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class TemplateArgumentLocContainerIterator { 44887ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgLocContainer *Container; 44897ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor unsigned Index; 44907ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 44917ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 44927ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc value_type; 44937ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc reference; 44947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef int difference_type; 44957ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef std::input_iterator_tag iterator_category; 44967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 44977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class pointer { 44987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Arg; 44997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 45017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } 45027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLoc *operator->() const { 45047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return &Arg; 45057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 45067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 45077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45087ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45097ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator() {} 45107ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45117ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator(ArgLocContainer &Container, 45127ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor unsigned Index) 45137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor : Container(&Container), Index(Index) { } 45147ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45157ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator &operator++() { 45167ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++Index; 45177ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return *this; 45187ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 45197ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator operator++(int) { 45217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator Old(*this); 45227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++(*this); 45237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Old; 45247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 45257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc operator*() const { 45277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Container->getArgLoc(Index); 45287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 45297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor pointer operator->() const { 45317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return pointer(Container->getArgLoc(Index)); 45327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 45337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator==(const TemplateArgumentLocContainerIterator &X, 4535f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor const TemplateArgumentLocContainerIterator &Y) { 45367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Container == Y.Container && X.Index == Y.Index; 45377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 45387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator!=(const TemplateArgumentLocContainerIterator &X, 4540f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor const TemplateArgumentLocContainerIterator &Y) { 45417ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return !(X == Y); 45427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 45437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 45447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor} 45457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 454743fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate <typename Derived> 4548577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateSpecializationType( 4549833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TypeLocBuilder &TLB, 4550833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateSpecializationTypeLoc TL, 455143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template) { 4552d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo NewTemplateArgs; 4553d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 4554d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 45557ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> 45567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgIterator; 45577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 45587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgIterator(TL, TL.getNumArgs()), 45597ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor NewTemplateArgs)) 45607f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return QualType(); 45611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4562833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: maybe don't rebuild if all the template arguments are the same. 4563833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 4564833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall QualType Result = 4565833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall getDerived().RebuildTemplateSpecializationType(Template, 4566833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TL.getTemplateNameLoc(), 4567d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs); 45681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4569833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!Result.isNull()) { 45703e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // Specializations of template template parameters are represented as 45713e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // TemplateSpecializationTypes, and substitution of type alias templates 45723e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // within a dependent context can transform them into 45733e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // DependentTemplateSpecializationTypes. 45743e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (isa<DependentTemplateSpecializationType>(Result)) { 45753e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith DependentTemplateSpecializationTypeLoc NewTL 45763e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 45773e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setKeywordLoc(TL.getTemplateNameLoc()); 45783e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setQualifierLoc(NestedNameSpecifierLoc()); 45793e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setNameLoc(TL.getTemplateNameLoc()); 45803e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setLAngleLoc(TL.getLAngleLoc()); 45813e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setRAngleLoc(TL.getRAngleLoc()); 45823e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 45833e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 45843e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return Result; 45853e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 45863e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 4587833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateSpecializationTypeLoc NewTL 4588833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall = TLB.push<TemplateSpecializationTypeLoc>(Result); 4589833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 4590833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setLAngleLoc(TL.getLAngleLoc()); 4591833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setRAngleLoc(TL.getRAngleLoc()); 4592833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 4593833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 4594833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 45951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4596833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return Result; 4597577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 45981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4599a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregortemplate <typename Derived> 4600a88f09f34e86125ee4e6949a757aaed314012664Douglas GregorQualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( 4601a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TypeLocBuilder &TLB, 4602a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc TL, 4603087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor TemplateName Template, 4604087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor CXXScopeSpec &SS) { 4605a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateArgumentListInfo NewTemplateArgs; 4606a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 4607a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 4608a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor typedef TemplateArgumentLocContainerIterator< 4609a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc> ArgIterator; 4610a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 4611a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor ArgIterator(TL, TL.getNumArgs()), 4612a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs)) 4613a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return QualType(); 4614a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4615a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor // FIXME: maybe don't rebuild if all the template arguments are the same. 4616a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4617a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { 4618a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor QualType Result 4619a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = getSema().Context.getDependentTemplateSpecializationType( 4620a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TL.getTypePtr()->getKeyword(), 4621a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DTN->getQualifier(), 4622a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DTN->getIdentifier(), 4623a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs); 4624a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4625a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc NewTL 4626a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 4627a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setKeywordLoc(TL.getKeywordLoc()); 462894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 462994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); 4630a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setNameLoc(TL.getNameLoc()); 4631a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setLAngleLoc(TL.getLAngleLoc()); 4632a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setRAngleLoc(TL.getRAngleLoc()); 4633a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 4634a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 4635a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return Result; 4636a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor } 4637a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4638a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor QualType Result 4639a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = getDerived().RebuildTemplateSpecializationType(Template, 4640a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TL.getNameLoc(), 4641a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs); 4642a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4643a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (!Result.isNull()) { 4644a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor /// FIXME: Wrap this in an elaborated-type-specifier? 4645a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateSpecializationTypeLoc NewTL 4646a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = TLB.push<TemplateSpecializationTypeLoc>(Result); 4647a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setTemplateNameLoc(TL.getNameLoc()); 4648a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setLAngleLoc(TL.getLAngleLoc()); 4649a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setRAngleLoc(TL.getRAngleLoc()); 4650a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 4651a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 4652a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor } 4653a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4654a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return Result; 4655a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor} 4656a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 46571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4658a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 4659465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, 466043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ElaboratedTypeLoc TL) { 4661f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const ElaboratedType *T = TL.getTypePtr(); 4662465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 46639e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 4664465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara // NOTE: the qualifier in an ElaboratedType is optional. 46659e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor if (TL.getQualifierLoc()) { 46669e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc 46679e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 46689e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor if (!QualifierLoc) 4669465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return QualType(); 4670465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 46711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 467243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); 467343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (NamedT.isNull()) 467443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return QualType(); 4675a63db84b164d3f1c987a3ea6251e3092db4f317bDaniel Dunbar 46763e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // C++0x [dcl.type.elab]p2: 46773e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // If the identifier resolves to a typedef-name or the simple-template-id 46783e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // resolves to an alias template specialization, the 46793e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // elaborated-type-specifier is ill-formed. 46801804174e1591bf59118f317775b48edd0382c3f0Richard Smith if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { 46811804174e1591bf59118f317775b48edd0382c3f0Richard Smith if (const TemplateSpecializationType *TST = 46821804174e1591bf59118f317775b48edd0382c3f0Richard Smith NamedT->getAs<TemplateSpecializationType>()) { 46831804174e1591bf59118f317775b48edd0382c3f0Richard Smith TemplateName Template = TST->getTemplateName(); 46841804174e1591bf59118f317775b48edd0382c3f0Richard Smith if (TypeAliasTemplateDecl *TAT = 46851804174e1591bf59118f317775b48edd0382c3f0Richard Smith dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) { 46861804174e1591bf59118f317775b48edd0382c3f0Richard Smith SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), 46871804174e1591bf59118f317775b48edd0382c3f0Richard Smith diag::err_tag_reference_non_tag) << 4; 46881804174e1591bf59118f317775b48edd0382c3f0Richard Smith SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); 46891804174e1591bf59118f317775b48edd0382c3f0Richard Smith } 46903e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 46913e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 46923e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 4693a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4694a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 46959e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc != TL.getQualifierLoc() || 4696e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NamedT != T->getNamedType()) { 469721e413fe6305a198564d436ac515497716c47844John McCall Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(), 46989e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor T->getKeyword(), 46999e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc, NamedT); 4700a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4701a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4702a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4703577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 4704465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 4705e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setKeywordLoc(TL.getKeywordLoc()); 47069e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 4707a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4708577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 47091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 47101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 47119d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallQualType TreeTransform<Derived>::TransformAttributedType( 47129d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall TypeLocBuilder &TLB, 47139d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeLoc TL) { 47149d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall const AttributedType *oldType = TL.getTypePtr(); 47159d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); 47169d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (modifiedType.isNull()) 47179d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return QualType(); 47189d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 47199d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType result = TL.getType(); 47209d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 47219d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // FIXME: dependent operand expressions? 47229d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (getDerived().AlwaysRebuild() || 47239d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall modifiedType != oldType->getModifiedType()) { 47249d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // TODO: this is really lame; we should really be rebuilding the 47259d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // equivalent type from first principles. 47269d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType equivalentType 47279d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall = getDerived().TransformType(oldType->getEquivalentType()); 47289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (equivalentType.isNull()) 47299d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return QualType(); 47309d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), 47319d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall modifiedType, 47329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall equivalentType); 47339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 47349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 47359d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); 47369d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrNameLoc(TL.getAttrNameLoc()); 47379d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (TL.hasAttrOperand()) 47389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); 47399d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (TL.hasAttrExprOperand()) 47409d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrExprOperand(TL.getAttrExprOperand()); 47419d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall else if (TL.hasAttrEnumOperand()) 47429d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); 47439d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 47449d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return result; 47459d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall} 47469d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 47479d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCalltemplate<typename Derived> 4748075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType 4749075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraTreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, 4750075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenTypeLoc TL) { 4751075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); 4752075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (Inner.isNull()) 4753075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(); 4754075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 4755075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Result = TL.getType(); 4756075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (getDerived().AlwaysRebuild() || 4757075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Inner != TL.getInnerLoc().getType()) { 4758075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Result = getDerived().RebuildParenType(Inner); 4759075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (Result.isNull()) 4760075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(); 4761075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 4762075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 4763075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); 4764075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara NewTL.setLParenLoc(TL.getLParenLoc()); 4765075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara NewTL.setRParenLoc(TL.getRParenLoc()); 4766075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return Result; 4767075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 4768075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 4769075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaratemplate<typename Derived> 47704714c12a1ab759156b78be8f109ea4c12213af57Douglas GregorQualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, 477143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentNameTypeLoc TL) { 4772f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentNameType *T = TL.getTypePtr(); 4773833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 47742494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor NestedNameSpecifierLoc QualifierLoc 47752494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 47762494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor if (!QualifierLoc) 4777577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 47781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 477933500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Result 47802494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor = getDerived().RebuildDependentNameType(T->getKeyword(), 478133500955d731c73717af52088b7fc0e7a85681e7John McCall TL.getKeywordLoc(), 47822494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor QualifierLoc, 47832494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor T->getIdentifier(), 478433500955d731c73717af52088b7fc0e7a85681e7John McCall TL.getNameLoc()); 4785a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4786a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4787a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4788e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { 4789e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara QualType NamedT = ElabT->getNamedType(); 479033500955d731c73717af52088b7fc0e7a85681e7John McCall TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); 479133500955d731c73717af52088b7fc0e7a85681e7John McCall 4792e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 4793e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setKeywordLoc(TL.getKeywordLoc()); 47949e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 479533500955d731c73717af52088b7fc0e7a85681e7John McCall } else { 4796e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); 4797e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setKeywordLoc(TL.getKeywordLoc()); 47982494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 4799e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setNameLoc(TL.getNameLoc()); 4800e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 4801a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4802577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 48031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4804577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 480533500955d731c73717af52088b7fc0e7a85681e7John McCallQualType TreeTransform<Derived>:: 480633500955d731c73717af52088b7fc0e7a85681e7John McCall TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 480743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentTemplateSpecializationTypeLoc TL) { 480894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 480994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (TL.getQualifierLoc()) { 481094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualifierLoc 481194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 481294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (!QualifierLoc) 4813a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return QualType(); 4814a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor } 4815a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 481643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived() 481794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); 481843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall} 481943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 482043fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived> 482143fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>:: 482294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas GregorTransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 482394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor DependentTemplateSpecializationTypeLoc TL, 482494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NestedNameSpecifierLoc QualifierLoc) { 482594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor const DependentTemplateSpecializationType *T = TL.getTypePtr(); 482694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 482794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor TemplateArgumentListInfo NewTemplateArgs; 482894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 482994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 483094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 483194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor typedef TemplateArgumentLocContainerIterator< 483294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor DependentTemplateSpecializationTypeLoc> ArgIterator; 483394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 483494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor ArgIterator(TL, TL.getNumArgs()), 483594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs)) 483694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return QualType(); 483794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 483894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualType Result 483994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), 484094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualifierLoc, 484194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor T->getIdentifier(), 484294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor TL.getNameLoc(), 484394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs); 484494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (Result.isNull()) 484594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return QualType(); 484694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 484794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { 484894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualType NamedT = ElabT->getNamedType(); 484994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 485094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Copy information relevant to the template specialization. 485194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor TemplateSpecializationTypeLoc NamedTL 48520a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor = TLB.push<TemplateSpecializationTypeLoc>(NamedT); 4853a35d5d7700b519d713039afd31477e95e2da7aa7Chandler Carruth NamedTL.setTemplateNameLoc(TL.getNameLoc()); 485494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NamedTL.setLAngleLoc(TL.getLAngleLoc()); 485594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NamedTL.setRAngleLoc(TL.getRAngleLoc()); 4856944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 48570a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 485894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 485994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Copy information relevant to the elaborated type. 486094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 486194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTL.setKeywordLoc(TL.getKeywordLoc()); 486294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 48630a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor } else if (isa<DependentTemplateSpecializationType>(Result)) { 48640a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor DependentTemplateSpecializationTypeLoc SpecTL 48650a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 4866944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor SpecTL.setKeywordLoc(TL.getKeywordLoc()); 48670a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setQualifierLoc(QualifierLoc); 4868a35d5d7700b519d713039afd31477e95e2da7aa7Chandler Carruth SpecTL.setNameLoc(TL.getNameLoc()); 48690a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setLAngleLoc(TL.getLAngleLoc()); 48700a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setRAngleLoc(TL.getRAngleLoc()); 4871944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 48720a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 487394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor } else { 48740a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor TemplateSpecializationTypeLoc SpecTL 48750a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor = TLB.push<TemplateSpecializationTypeLoc>(Result); 4876a35d5d7700b519d713039afd31477e95e2da7aa7Chandler Carruth SpecTL.setTemplateNameLoc(TL.getNameLoc()); 48770a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setLAngleLoc(TL.getLAngleLoc()); 48780a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setRAngleLoc(TL.getRAngleLoc()); 4879944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 48800a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 488194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor } 488294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return Result; 488394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor} 488494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 488594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregortemplate<typename Derived> 48867536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas GregorQualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, 48877536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor PackExpansionTypeLoc TL) { 48882fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor QualType Pattern 48892fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor = getDerived().TransformType(TLB, TL.getPatternLoc()); 48902fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor if (Pattern.isNull()) 48912fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor return QualType(); 48922fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor 48932fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor QualType Result = TL.getType(); 48942fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor if (getDerived().AlwaysRebuild() || 48952fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor Pattern != TL.getPatternLoc().getType()) { 48962fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor Result = getDerived().RebuildPackExpansionType(Pattern, 48972fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor TL.getPatternLoc().getSourceRange(), 4898cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor TL.getEllipsisLoc(), 4899cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor TL.getTypePtr()->getNumExpansions()); 49002fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor if (Result.isNull()) 49012fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor return QualType(); 49022fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor } 49032fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor 49042fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); 49052fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor NewT.setEllipsisLoc(TL.getEllipsisLoc()); 49062fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor return Result; 49077536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor} 49087536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 49097536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregortemplate<typename Derived> 4910a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 4911a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, 491243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCInterfaceTypeLoc TL) { 4913ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor // ObjCInterfaceType is never dependent. 4914c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 4915c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return TL.getType(); 4916c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 4917c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4918c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCalltemplate<typename Derived> 4919c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallQualType 4920c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallTreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, 492143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCObjectTypeLoc TL) { 4922c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // ObjCObjectType is never dependent. 4923c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 4924ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor return TL.getType(); 4925577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 49261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4928a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 4929a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, 493043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCObjectPointerTypeLoc TL) { 4931ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor // ObjCObjectPointerType is never dependent. 4932c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 4933ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor return TL.getType(); 493424fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis} 493524fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 4936577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 493743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor// Statement transformation 493843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===// 493943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 494060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 49411eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformNullStmt(NullStmt *S) { 49423fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 494343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 494443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 494543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 494660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 494743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { 494843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().TransformCompoundStmt(S, false); 494943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 495043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 495143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 495260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 49531eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, 495443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool IsStmtExpr) { 49557114cbab7eb6e8b714eb22f014327daf2c741c08John McCall bool SubStmtInvalid = false; 495643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool SubStmtChanged = false; 4957ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Stmt*> Statements(getSema()); 495843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); 495943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor B != BEnd; ++B) { 496060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Result = getDerived().TransformStmt(*B); 49617114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (Result.isInvalid()) { 49627114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // Immediately fail if this was a DeclStmt, since it's very 49637114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // likely that this will cause problems for future statements. 49647114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (isa<DeclStmt>(*B)) 49657114cbab7eb6e8b714eb22f014327daf2c741c08John McCall return StmtError(); 49667114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 49677114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // Otherwise, just keep processing substatements and fail later. 49687114cbab7eb6e8b714eb22f014327daf2c741c08John McCall SubStmtInvalid = true; 49697114cbab7eb6e8b714eb22f014327daf2c741c08John McCall continue; 49707114cbab7eb6e8b714eb22f014327daf2c741c08John McCall } 49711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 497243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SubStmtChanged = SubStmtChanged || Result.get() != *B; 497343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Statements.push_back(Result.takeAs<Stmt>()); 497443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 49751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49767114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (SubStmtInvalid) 49777114cbab7eb6e8b714eb22f014327daf2c741c08John McCall return StmtError(); 49787114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 497943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 498043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !SubStmtChanged) 49813fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 498243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 498343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildCompoundStmt(S->getLBracLoc(), 498443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor move_arg(Statements), 498543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getRBracLoc(), 498643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor IsStmtExpr); 498743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 49881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 498943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 499060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 49911eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { 499260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS, RHS; 4993264c1f8ec895952466eab59b84b8b06801e721faEli Friedman { 49946b3014b07c40a6ed8b0c8ed63950df02eeb82c28Eli Friedman EnterExpressionEvaluationContext Unevaluated(SemaRef, 49956b3014b07c40a6ed8b0c8ed63950df02eeb82c28Eli Friedman Sema::ConstantEvaluated); 49961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4997264c1f8ec895952466eab59b84b8b06801e721faEli Friedman // Transform the left-hand case value. 4998264c1f8ec895952466eab59b84b8b06801e721faEli Friedman LHS = getDerived().TransformExpr(S->getLHS()); 4999264c1f8ec895952466eab59b84b8b06801e721faEli Friedman if (LHS.isInvalid()) 5000f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5002264c1f8ec895952466eab59b84b8b06801e721faEli Friedman // Transform the right-hand case value (for the GNU case-range extension). 5003264c1f8ec895952466eab59b84b8b06801e721faEli Friedman RHS = getDerived().TransformExpr(S->getRHS()); 5004264c1f8ec895952466eab59b84b8b06801e721faEli Friedman if (RHS.isInvalid()) 5005f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5006264c1f8ec895952466eab59b84b8b06801e721faEli Friedman } 50071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 500843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Build the case statement. 500943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Case statements are always rebuilt so that they will attached to their 501043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transformed switch statement. 501160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), 50129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), 501343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getEllipsisLoc(), 50149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get(), 501543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getColonLoc()); 501643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Case.isInvalid()) 5017f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 501943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the statement following the case 502060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 502143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 5022f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 502443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Attach the body to the case statement 50259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); 502643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 502743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 502843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 502960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 50301eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { 503143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the statement following the default case 503260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 503343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 5034f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 503643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Default statements are always rebuilt 503743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), 50389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubStmt.get()); 503943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 50401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 504143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 504260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 50431eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { 504460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 504543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 5046f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 504857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), 504957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner S->getDecl()); 505057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner if (!LD) 505157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return StmtError(); 505257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 505357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 505443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // FIXME: Pass the real colon location in. 5055ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner return getDerived().RebuildLabelStmt(S->getIdentLoc(), 505657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner cast<LabelDecl>(LD), SourceLocation(), 505757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner SubStmt.get()); 505843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 50591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 506043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 506160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 50621eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIfStmt(IfStmt *S) { 506343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 506460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 50658cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor VarDecl *ConditionVar = 0; 50668cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor if (S->getConditionVariable()) { 5067c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 50688cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor = cast_or_null<VarDecl>( 5069aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5070aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5071aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 50728cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor if (!ConditionVar) 5073f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 507499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 50758cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 5076c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 507799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5078f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5079eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 5080eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor // Convert the condition to a boolean value. 5081afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 50828491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), 50838491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 5084afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 5085f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5086eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 50879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE.get(); 5088afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 508999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 5090c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 50919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 50929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 5093f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5094eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 509543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the "then" branch. 509660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Then = getDerived().TransformStmt(S->getThen()); 509743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Then.isInvalid()) 5098f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 510043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the "else" branch. 510160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Else = getDerived().TransformStmt(S->getElse()); 510243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Else.isInvalid()) 5103f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 510543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 51069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 510799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor ConditionVar == S->getConditionVariable() && 510843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Then.get() == S->getThen() && 510943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Else.get() == S->getElse()) 51103fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 51111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5112eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, 511344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis Then.get(), 51149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall S->getElseLoc(), Else.get()); 511543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 511643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 511743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 511860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 51191eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { 512043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition. 512160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 5122d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor VarDecl *ConditionVar = 0; 5123d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor if (S->getConditionVariable()) { 5124c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 5125d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor = cast_or_null<VarDecl>( 5126aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5127aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5128aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 5129d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor if (!ConditionVar) 5130f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 513199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 5132d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 5133c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 513499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5135f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 513699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 51371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 513843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Rebuild the switch statement. 513960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Switch 51409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), 5141586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor ConditionVar); 514243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Switch.isInvalid()) 5143f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 514543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body of the switch statement. 514660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 514743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5148f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 515043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Complete the switch statement. 51519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), 51529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 515343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 51541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 515543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 515660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 51571eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { 515843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 515960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 51605656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor VarDecl *ConditionVar = 0; 51615656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor if (S->getConditionVariable()) { 5162c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 51635656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor = cast_or_null<VarDecl>( 5164aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5165aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5166aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 51675656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor if (!ConditionVar) 5168f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 516999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 51705656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 5171c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 517299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5173f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5174afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 5175afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 5176afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor // Convert the condition to a boolean value. 51778491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), 51788491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 5179afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 5180f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE; 5182afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 518399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 51841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 51859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 51869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 5187f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5188eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 518943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 519060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 519143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5192f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 519443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 51959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 519699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor ConditionVar == S->getConditionVariable() && 519743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 51989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Owned(S); 51991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5200eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, 52019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ConditionVar, Body.get()); 520243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 52031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 520443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 520560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 520643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformDoStmt(DoStmt *S) { 520743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 520860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 520943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5210f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5212eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor // Transform the condition 521360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(S->getCond()); 5214eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor if (Cond.isInvalid()) 5215f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5216eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 521743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 521843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Cond.get() == S->getCond() && 521943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 52203fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 52211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), 52239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall /*FIXME:*/S->getWhileLoc(), Cond.get(), 522443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getRParenLoc()); 522543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 52261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 522743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 522860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 52291eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformForStmt(ForStmt *S) { 523043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the initialization statement 523160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Init = getDerived().TransformStmt(S->getInit()); 523243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Init.isInvalid()) 5233f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 523543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 523660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 523799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor VarDecl *ConditionVar = 0; 523899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (S->getConditionVariable()) { 5239c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 524099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor = cast_or_null<VarDecl>( 5241aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5242aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5243aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 524499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (!ConditionVar) 5245f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 524699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 524799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 5248c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 524999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5250f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5251afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 5252afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 5253afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor // Convert the condition to a boolean value. 52548491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), 52558491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 5256afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 5257f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5258afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 52599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE.get(); 5260afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 526199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 52621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 52649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 5265f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5266eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 526743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the increment 526860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Inc = getDerived().TransformExpr(S->getInc()); 526943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Inc.isInvalid()) 5270f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get())); 52739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (S->getInc() && !FullInc.get()) 5274f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5275eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 527643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 527760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 527843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5279f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 528143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 528243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Init.get() == S->getInit() && 52839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 528443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Inc.get() == S->getInc() && 528543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 52863fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 52871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 528843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), 52899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init.get(), FullCond, ConditionVar, 52909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullInc, S->getRParenLoc(), Body.get()); 529143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 529243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 529343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 529460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 52951eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { 529657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), 529757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner S->getLabel()); 529857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner if (!LD) 529957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return StmtError(); 530057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 530143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Goto statements must always be rebuilt, to resolve the label. 53021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), 530357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner cast<LabelDecl>(LD)); 530443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 530543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 530643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 530760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 53081eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { 530960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Target = getDerived().TransformExpr(S->getTarget()); 531043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Target.isInvalid()) 5311f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 53121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 531343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 531443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Target.get() == S->getTarget()) 53153fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 531643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 531743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), 53189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Target.get()); 531943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 532043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 532143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 532260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 53231eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { 53243fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 532543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 53261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 532743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 532860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 53291eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { 53303fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 533143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 53321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 533343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 533460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 53351eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { 533660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(S->getRetValue()); 533743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Result.isInvalid()) 5338f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 533943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 53401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // FIXME: We always rebuild the return statement because there is no way 534143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // to tell whether the return type of the function has changed. 53429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); 534343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 53441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 534543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 534660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 53471eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { 534843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool DeclChanged = false; 5349686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<Decl *, 4> Decls; 535043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); 535143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor D != DEnd; ++D) { 5352aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), 5353aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor *D); 535443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!Transformed) 5355f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 53561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 535743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Transformed != *D) 535843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor DeclChanged = true; 53591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 536043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Decls.push_back(Transformed); 536143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 53621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 536343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && !DeclChanged) 53643fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 53651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 53661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), 536743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getStartLoc(), S->getEndLoc()); 536843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 53691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 537043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 537160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 537243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { 5373c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5374ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Constraints(getSema()); 5375ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Exprs(getSema()); 5376686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<IdentifierInfo *, 4> Names; 5377a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson 537860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult AsmString; 5379ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Clobbers(getSema()); 5380703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5381703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool ExprsChanged = false; 5382c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5383703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the outputs. 5384703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { 5385ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson Names.push_back(S->getOutputIdentifier(I)); 5386c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5387703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the constraint literal. 53883fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Constraints.push_back(S->getOutputConstraintLiteral(I)); 5389c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5390703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Transform the output expr. 5391703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson Expr *OutputExpr = S->getOutputExpr(I); 539260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(OutputExpr); 5393703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (Result.isInvalid()) 5394f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5395c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5396703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson ExprsChanged |= Result.get() != OutputExpr; 5397c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 53989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs.push_back(Result.get()); 5399703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 5400c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5401703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the inputs. 5402703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { 5403ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson Names.push_back(S->getInputIdentifier(I)); 5404c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5405703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the constraint literal. 54063fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Constraints.push_back(S->getInputConstraintLiteral(I)); 5407c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5408703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Transform the input expr. 5409703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson Expr *InputExpr = S->getInputExpr(I); 541060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(InputExpr); 5411703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (Result.isInvalid()) 5412f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5413c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5414703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson ExprsChanged |= Result.get() != InputExpr; 5415c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 54169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs.push_back(Result.get()); 5417703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 5418c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5419703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (!getDerived().AlwaysRebuild() && !ExprsChanged) 54203fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 5421703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5422703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the clobbers. 5423703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) 54243fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Clobbers.push_back(S->getClobber(I)); 5425703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5426703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the asm string literal. 5427703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson AsmString = SemaRef.Owned(S->getAsmString()); 5428703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5429703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson return getDerived().RebuildAsmStmt(S->getAsmLoc(), 5430703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isSimple(), 5431703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isVolatile(), 5432703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getNumOutputs(), 5433703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getNumInputs(), 5434a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson Names.data(), 5435703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson move_arg(Constraints), 5436703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson move_arg(Exprs), 54379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall AsmString.get(), 5438703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson move_arg(Clobbers), 5439703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getRParenLoc(), 5440703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isMSAsm()); 544143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 544243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 544343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 544443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 544560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 54461eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { 54474dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the body of the @try. 544860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); 54494dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (TryBody.isInvalid()) 5450f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5451c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 54528f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor // Transform the @catch statements (if present). 54538f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor bool AnyCatchChanged = false; 5454ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Stmt*> CatchStmts(SemaRef); 54558f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { 545660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); 54574dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Catch.isInvalid()) 5458f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 54598f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor if (Catch.get() != S->getCatchStmt(I)) 54608f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor AnyCatchChanged = true; 54618f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor CatchStmts.push_back(Catch.release()); 54624dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 5463c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 54644dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the @finally statement (if present). 546560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Finally; 54664dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (S->getFinallyStmt()) { 54674dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Finally = getDerived().TransformStmt(S->getFinallyStmt()); 54684dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Finally.isInvalid()) 5469f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 54704dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 54714dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 54724dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // If nothing changed, just retain this statement. 54734dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (!getDerived().AlwaysRebuild() && 54744dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor TryBody.get() == S->getTryBody() && 54758f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor !AnyCatchChanged && 54764dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Finally.get() == S->getFinallyStmt()) 54773fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 5478c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 54794dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Build a new statement. 54809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), 54819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall move_arg(CatchStmts), Finally.get()); 548243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 54831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 548443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 548560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 54861eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { 5487be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor // Transform the @catch parameter, if there is one. 5488be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *Var = 0; 5489be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (VarDecl *FromVar = S->getCatchParamDecl()) { 5490be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TypeSourceInfo *TSInfo = 0; 5491be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (FromVar->getTypeSourceInfo()) { 5492be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); 5493be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (!TSInfo) 5494f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5495be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 5496c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5497be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor QualType T; 5498be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (TSInfo) 5499be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor T = TSInfo->getType(); 5500be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor else { 5501be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor T = getDerived().TransformType(FromVar->getType()); 5502be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (T.isNull()) 5503f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5504be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 5505c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5506be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); 5507be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (!Var) 5508f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5509be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 5510c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 551160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); 5512be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (Body.isInvalid()) 5513f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5514c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5515c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), 5516be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor S->getRParenLoc(), 55179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Var, Body.get()); 551843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 55191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 552043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 552160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 55221eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { 55234dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the body. 552460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); 55254dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Body.isInvalid()) 5526f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5527c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 55284dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // If nothing changed, just retain this statement. 55294dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (!getDerived().AlwaysRebuild() && 55304dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Body.get() == S->getFinallyBody()) 55313fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 55324dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 55334dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Build a new statement. 55344dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), 55359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 553643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 55371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 553843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 553960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 55401eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { 554160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Operand; 5542d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (S->getThrowExpr()) { 5543d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor Operand = getDerived().TransformExpr(S->getThrowExpr()); 5544d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (Operand.isInvalid()) 5545f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5546d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor } 5547c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5548d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (!getDerived().AlwaysRebuild() && 5549d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor Operand.get() == S->getThrowExpr()) 55503fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return getSema().Owned(S); 5551c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 55529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); 555343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 55541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 555543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 555660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 555743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCAtSynchronizedStmt( 55581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCAtSynchronizedStmt *S) { 55598fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Transform the object we are locking. 556060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); 55618fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (Object.isInvalid()) 5562f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 556307524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Object = 556407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), 556507524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Object.get()); 556607524039dce5c820f111a1b3f772b4261f004b4aJohn McCall if (Object.isInvalid()) 556707524039dce5c820f111a1b3f772b4261f004b4aJohn McCall return StmtError(); 5568c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 55698fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Transform the body. 557060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); 55718fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (Body.isInvalid()) 5572f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5573c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 55748fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // If nothing change, just retain the current statement. 55758fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (!getDerived().AlwaysRebuild() && 55768fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor Object.get() == S->getSynchExpr() && 55778fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor Body.get() == S->getSynchBody()) 55783fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 55798fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor 55808fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Build a new statement. 55818fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), 55829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Object.get(), Body.get()); 558343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 558443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 558543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 558660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 5587f85e193739c953358c865005855253af4f68a497John McCallTreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( 5588f85e193739c953358c865005855253af4f68a497John McCall ObjCAutoreleasePoolStmt *S) { 5589f85e193739c953358c865005855253af4f68a497John McCall // Transform the body. 5590f85e193739c953358c865005855253af4f68a497John McCall StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); 5591f85e193739c953358c865005855253af4f68a497John McCall if (Body.isInvalid()) 5592f85e193739c953358c865005855253af4f68a497John McCall return StmtError(); 5593f85e193739c953358c865005855253af4f68a497John McCall 5594f85e193739c953358c865005855253af4f68a497John McCall // If nothing changed, just retain this statement. 5595f85e193739c953358c865005855253af4f68a497John McCall if (!getDerived().AlwaysRebuild() && 5596f85e193739c953358c865005855253af4f68a497John McCall Body.get() == S->getSubStmt()) 5597f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(S); 5598f85e193739c953358c865005855253af4f68a497John McCall 5599f85e193739c953358c865005855253af4f68a497John McCall // Build a new statement. 5600f85e193739c953358c865005855253af4f68a497John McCall return getDerived().RebuildObjCAutoreleasePoolStmt( 5601f85e193739c953358c865005855253af4f68a497John McCall S->getAtLoc(), Body.get()); 5602f85e193739c953358c865005855253af4f68a497John McCall} 5603f85e193739c953358c865005855253af4f68a497John McCall 5604f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived> 5605f85e193739c953358c865005855253af4f68a497John McCallStmtResult 560643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCForCollectionStmt( 56071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCForCollectionStmt *S) { 5608c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the element statement. 560960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Element = getDerived().TransformStmt(S->getElement()); 5610c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Element.isInvalid()) 5611f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5612c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5613c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the collection expression. 561460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Collection = getDerived().TransformExpr(S->getCollection()); 5615c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Collection.isInvalid()) 5616f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5617990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(), 5618990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall Collection.take()); 5619990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall if (Collection.isInvalid()) 5620990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall return StmtError(); 5621c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5622c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the body. 562360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 5624c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Body.isInvalid()) 5625f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5626c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5627c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // If nothing changed, just retain this statement. 5628c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (!getDerived().AlwaysRebuild() && 5629c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Element.get() == S->getElement() && 5630c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Collection.get() == S->getCollection() && 5631c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Body.get() == S->getBody()) 56323fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 5633c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5634c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Build a new statement. 5635c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), 5636c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /*FIXME:*/S->getForLoc(), 56379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Element.get(), 56389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Collection.get(), 5639c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor S->getRParenLoc(), 56409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 564143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 564243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 564343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 564443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 564560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 564643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { 564743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the exception declaration, if any. 564843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor VarDecl *Var = 0; 564943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (S->getExceptionDecl()) { 565043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor VarDecl *ExceptionDecl = S->getExceptionDecl(); 565183cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor TypeSourceInfo *T = getDerived().TransformType( 565283cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor ExceptionDecl->getTypeSourceInfo()); 565383cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor if (!T) 5654f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 56551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 565683cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, 5657ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getInnerLocStart(), 5658ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getLocation(), 5659ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getIdentifier()); 5660ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor if (!Var || Var->isInvalidDecl()) 5661f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 566243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 56631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 566443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the actual exception handler. 566560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); 5666ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor if (Handler.isInvalid()) 5667f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 56681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 566943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 567043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !Var && 567143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Handler.get() == S->getHandlerBlock()) 56723fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 567343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 567443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), 567543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Var, 56769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Handler.get()); 567743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 56781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 567943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 568060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 568143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { 568243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the try block itself. 568360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TryBlock 568443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor = getDerived().TransformCompoundStmt(S->getTryBlock()); 568543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (TryBlock.isInvalid()) 5686f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 56871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 568843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the handlers. 568943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool HandlerChanged = false; 5690ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Stmt*> Handlers(SemaRef); 569143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { 569260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Handler 569343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor = getDerived().TransformCXXCatchStmt(S->getHandler(I)); 569443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Handler.isInvalid()) 5695f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 56961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 569743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); 569843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Handlers.push_back(Handler.takeAs<Stmt>()); 569943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 57001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 570143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 570243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor TryBlock.get() == S->getTryBlock() && 570343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !HandlerChanged) 57043fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 570543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 57069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), 57071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump move_arg(Handlers)); 570843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 57091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5710ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate<typename Derived> 5711ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithStmtResult 5712ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithTreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { 5713ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); 5714ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Range.isInvalid()) 5715ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5716ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5717ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt()); 5718ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (BeginEnd.isInvalid()) 5719ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5720ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5721ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ExprResult Cond = getDerived().TransformExpr(S->getCond()); 5722ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Cond.isInvalid()) 5723ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5724ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5725ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ExprResult Inc = getDerived().TransformExpr(S->getInc()); 5726ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Inc.isInvalid()) 5727ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5728ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5729ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); 5730ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (LoopVar.isInvalid()) 5731ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5732ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5733ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult NewStmt = S; 5734ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (getDerived().AlwaysRebuild() || 5735ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Range.get() != S->getRangeStmt() || 5736ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith BeginEnd.get() != S->getBeginEndStmt() || 5737ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Cond.get() != S->getCond() || 5738ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Inc.get() != S->getInc() || 5739ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith LoopVar.get() != S->getLoopVarStmt()) 5740ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), 5741ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getColonLoc(), Range.get(), 5742ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith BeginEnd.get(), Cond.get(), 5743ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Inc.get(), LoopVar.get(), 5744ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getRParenLoc()); 5745ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5746ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult Body = getDerived().TransformStmt(S->getBody()); 5747ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Body.isInvalid()) 5748ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5749ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5750ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith // Body has changed but we didn't rebuild the for-range statement. Rebuild 5751ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith // it now so we have a new statement to attach the body to. 5752ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Body.get() != S->getBody() && NewStmt.get() == S) 5753ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), 5754ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getColonLoc(), Range.get(), 5755ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith BeginEnd.get(), Cond.get(), 5756ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Inc.get(), LoopVar.get(), 5757ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getRParenLoc()); 5758ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5759ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (NewStmt.get() == S) 5760ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return SemaRef.Owned(S); 5761ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5762ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); 5763ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith} 5764ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 576528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 576628bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 5767ba0513de93d2fab6db5ab30b6927209fcc883078Douglas GregorTreeTransform<Derived>::TransformMSDependentExistsStmt( 5768ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor MSDependentExistsStmt *S) { 5769ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // Transform the nested-name-specifier, if any. 5770ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 5771ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (S->getQualifierLoc()) { 5772ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor QualifierLoc 5773ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); 5774ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (!QualifierLoc) 5775ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return StmtError(); 5776ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor } 5777ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5778ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // Transform the declaration name. 5779ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor DeclarationNameInfo NameInfo = S->getNameInfo(); 5780ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (NameInfo.getName()) { 5781ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 5782ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (!NameInfo.getName()) 5783ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return StmtError(); 5784ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor } 5785ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5786ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // Check whether anything changed. 5787ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (!getDerived().AlwaysRebuild() && 5788ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor QualifierLoc == S->getQualifierLoc() && 5789ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NameInfo.getName() == S->getNameInfo().getName()) 5790ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return S; 5791ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5792ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // Determine whether this name exists, if we can. 5793ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor CXXScopeSpec SS; 5794ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor SS.Adopt(QualifierLoc); 5795ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor bool Dependent = false; 5796ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) { 5797ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor case Sema::IER_Exists: 5798ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (S->isIfExists()) 5799ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor break; 5800ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5801ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return new (getSema().Context) NullStmt(S->getKeywordLoc()); 5802ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5803ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor case Sema::IER_DoesNotExist: 5804ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (S->isIfNotExists()) 5805ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor break; 5806ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5807ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return new (getSema().Context) NullStmt(S->getKeywordLoc()); 5808ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5809ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor case Sema::IER_Dependent: 5810ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor Dependent = true; 5811ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor break; 581265019acfc46ffb191fac4e781ac0c4b8d0c8434eDouglas Gregor 581365019acfc46ffb191fac4e781ac0c4b8d0c8434eDouglas Gregor case Sema::IER_Error: 581465019acfc46ffb191fac4e781ac0c4b8d0c8434eDouglas Gregor return StmtError(); 5815ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor } 5816ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5817ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // We need to continue with the instantiation, so do so now. 5818ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); 5819ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (SubStmt.isInvalid()) 5820ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return StmtError(); 5821ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5822ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // If we have resolved the name, just transform to the substatement. 5823ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (!Dependent) 5824ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return SubStmt; 5825ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5826ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // The name is still dependent, so build a dependent expression again. 5827ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), 5828ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor S->isIfExists(), 5829ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor QualifierLoc, 5830ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NameInfo, 5831ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor SubStmt.get()); 5832ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor} 5833ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5834ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregortemplate<typename Derived> 5835ba0513de93d2fab6db5ab30b6927209fcc883078Douglas GregorStmtResult 583628bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { 583728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock()); 583828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(TryBlock.isInvalid()) return StmtError(); 583928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 584028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); 584128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(!getDerived().AlwaysRebuild() && 584228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley TryBlock.get() == S->getTryBlock() && 584328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Handler.get() == S->getHandler()) 584428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return SemaRef.Owned(S); 584528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 584628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), 584728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley S->getTryLoc(), 584828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley TryBlock.take(), 584928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Handler.take()); 585028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 585128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 585228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 585328bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 585428bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { 585528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); 585628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(Block.isInvalid()) return StmtError(); 585728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 585828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), 585928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Block.take()); 586028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 586128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 586228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 586328bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 586428bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { 586528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); 586628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(FilterExpr.isInvalid()) return StmtError(); 586728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 586828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); 586928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(Block.isInvalid()) return StmtError(); 587028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 587128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), 587228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley FilterExpr.take(), 587328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Block.take()); 587428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 587528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 587628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 587728bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 587828bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { 587928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(isa<SEHFinallyStmt>(Handler)) 588028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); 588128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley else 588228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); 588328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 588428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 588543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===// 5886b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Expression transformation 5887577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 58881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 588960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5890454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { 58913fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 58921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 58931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 58941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 589560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5896454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { 589740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc; 589840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (E->getQualifierLoc()) { 589940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc 590040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 590140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!QualifierLoc) 5902f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5903a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 5904dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 5905dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *ND 59067c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), 59077c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getDecl())); 5908b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!ND) 5909f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 59101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5911ec8045d3f0375302eadaa63deb373bacaf25a569John McCall DeclarationNameInfo NameInfo = E->getNameInfo(); 5912ec8045d3f0375302eadaa63deb373bacaf25a569John McCall if (NameInfo.getName()) { 5913ec8045d3f0375302eadaa63deb373bacaf25a569John McCall NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 5914ec8045d3f0375302eadaa63deb373bacaf25a569John McCall if (!NameInfo.getName()) 5915f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5916ec8045d3f0375302eadaa63deb373bacaf25a569John McCall } 59172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 59182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!getDerived().AlwaysRebuild() && 591940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc == E->getQualifierLoc() && 5920a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor ND == E->getDecl() && 59212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getDecl()->getDeclName() && 5922096832c5ed5b9106fa177ebc148489760c3bc496John McCall !E->hasExplicitTemplateArgs()) { 59231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5924dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // Mark it referenced in the new context regardless. 5925dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // FIXME: this is a bit instantiation-specific. 5926dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); 5927a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 59283fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5929a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 5930dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 5931dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; 5932096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (E->hasExplicitTemplateArgs()) { 5933dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TemplateArgs = &TransArgs; 5934dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TransArgs.setLAngleLoc(E->getLAngleLoc()); 5935dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TransArgs.setRAngleLoc(E->getRAngleLoc()); 5936fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 5937fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 5938fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 5939fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 5940dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall } 5941dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 594240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, 594340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor TemplateArgs); 5944577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 59451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5946b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 594760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5948454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { 59493fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5950577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 59511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5952b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 595360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5954454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { 59553fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5956b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 59571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5958b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 595960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5960454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { 59613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5962b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 59631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 59641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 596560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5966454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { 59673fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5968b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 59691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5970b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 597160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5972454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { 59733fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5974b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 59751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5976b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 597760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5978f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneTreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { 5979f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult ControllingExpr = 5980f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne getDerived().TransformExpr(E->getControllingExpr()); 5981f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (ControllingExpr.isInvalid()) 5982f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ExprError(); 5983f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 5984686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<Expr *, 4> AssocExprs; 5985686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<TypeSourceInfo *, 4> AssocTypes; 5986f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne for (unsigned i = 0; i != E->getNumAssocs(); ++i) { 5987f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); 5988f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (TS) { 5989f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo *AssocType = getDerived().TransformType(TS); 5990f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!AssocType) 5991f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ExprError(); 5992f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes.push_back(AssocType); 5993f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } else { 5994f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes.push_back(0); 5995f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 5996f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 5997f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); 5998f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (AssocExpr.isInvalid()) 5999f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ExprError(); 6000f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs.push_back(AssocExpr.release()); 6001f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 6002f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 6003f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), 6004f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E->getDefaultLoc(), 6005f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E->getRParenLoc(), 6006f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ControllingExpr.release(), 6007f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes.data(), 6008f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs.data(), 6009f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E->getNumAssocs()); 6010f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne} 6011f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 6012f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbournetemplate<typename Derived> 6013f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneExprResult 6014454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { 601560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 6016b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6017f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 60181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6019b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) 60203fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 60211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), 6023b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParen()); 6024b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6025b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 60261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 602760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6028454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { 602960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 6030b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6031f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 60321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6033b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) 60343fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 60351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6036b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), 6037b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOpcode(), 60389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get()); 6039b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 60401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6041b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 604260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 60438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorTreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { 60448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Transform the type. 60458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); 60468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (!Type) 6047f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6048c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 60498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Transform all of the components into components similar to what the 60508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // parser uses. 6051c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // FIXME: It would be slightly more efficient in the non-dependent case to 6052c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // just map FieldDecls, rather than requiring the rebuilder to look for 6053c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // the fields again. However, __builtin_offsetof is rare enough in 60548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // template code that we don't care. 60558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor bool ExprChanged = false; 6056f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall typedef Sema::OffsetOfComponent Component; 60578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor typedef OffsetOfExpr::OffsetOfNode Node; 6058686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<Component, 4> Components; 60598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { 60608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor const Node &ON = E->getComponent(I); 60618ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Component Comp; 606272be24f39c162448e53dd73cf57cc6357114361eDouglas Gregor Comp.isBrackets = true; 606306dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara Comp.LocStart = ON.getSourceRange().getBegin(); 606406dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara Comp.LocEnd = ON.getSourceRange().getEnd(); 60658ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor switch (ON.getKind()) { 60668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Array: { 60678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); 606860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Index = getDerived().TransformExpr(FromIndex); 60698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (Index.isInvalid()) 6070f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6071c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 60728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor ExprChanged = ExprChanged || Index.get() != FromIndex; 60738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.isBrackets = true; 60749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Comp.U.E = Index.get(); 60758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor break; 60768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 6077c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 60788ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Field: 60798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Identifier: 60808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.isBrackets = false; 60818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.U.IdentInfo = ON.getFieldName(); 608229d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor if (!Comp.U.IdentInfo) 608329d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor continue; 6084c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 60858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor break; 6086c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6087cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor case Node::Base: 6088cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor // Will be recomputed during the rebuild. 6089cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor continue; 60908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 6091c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 60928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Components.push_back(Comp); 60938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 6094c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 60958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // If nothing changed, retain the existing expression. 60968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (!getDerived().AlwaysRebuild() && 60978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Type == E->getTypeSourceInfo() && 60988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor !ExprChanged) 60993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6100c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 61018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Build a new offsetof expression. 61028ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, 61038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Components.data(), Components.size(), 61048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor E->getRParenLoc()); 61057cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall} 61067cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall 61077cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCalltemplate<typename Derived> 61087cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallExprResult 61097cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallTreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { 61107cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall assert(getDerived().AlreadyTransformed(E->getType()) && 61117cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall "opaque value expression requires transformation"); 61127cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall return SemaRef.Owned(E); 61138ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 61148ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 61158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregortemplate<typename Derived> 611660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 61174b9c2d235fb9449e249d74f48ecfec601650de93John McCallTreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { 611801e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // Rebuild the syntactic form. The original syntactic form has 611901e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // opaque-value expressions in it, so strip those away and rebuild 612001e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // the result. This is a really awful way of doing this, but the 612101e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // better solution (rebuilding the semantic expressions and 612201e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // rebinding OVEs as necessary) doesn't work; we'd need 612301e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // TreeTransform to not strip away implicit conversions. 612401e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); 612501e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall ExprResult result = getDerived().TransformExpr(newSyntacticForm); 61264b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (result.isInvalid()) return ExprError(); 61274b9c2d235fb9449e249d74f48ecfec601650de93John McCall 61284b9c2d235fb9449e249d74f48ecfec601650de93John McCall // If that gives us a pseudo-object result back, the pseudo-object 61294b9c2d235fb9449e249d74f48ecfec601650de93John McCall // expression must have been an lvalue-to-rvalue conversion which we 61304b9c2d235fb9449e249d74f48ecfec601650de93John McCall // should reapply. 61314b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) 61324b9c2d235fb9449e249d74f48ecfec601650de93John McCall result = SemaRef.checkPseudoObjectRValue(result.take()); 61334b9c2d235fb9449e249d74f48ecfec601650de93John McCall 61344b9c2d235fb9449e249d74f48ecfec601650de93John McCall return result; 61354b9c2d235fb9449e249d74f48ecfec601650de93John McCall} 61364b9c2d235fb9449e249d74f48ecfec601650de93John McCall 61374b9c2d235fb9449e249d74f48ecfec601650de93John McCalltemplate<typename Derived> 61384b9c2d235fb9449e249d74f48ecfec601650de93John McCallExprResult 6139f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter CollingbourneTreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( 6140f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr *E) { 6141b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->isArgumentType()) { 6142a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *OldT = E->getArgumentTypeInfo(); 61435557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor 6144a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *NewT = getDerived().TransformType(OldT); 61455ab75172051a6d2ea71a80a79e81c65519fd3462John McCall if (!NewT) 6146f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61485ab75172051a6d2ea71a80a79e81c65519fd3462John McCall if (!getDerived().AlwaysRebuild() && OldT == NewT) 61493fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 61501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6151f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), 6152f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getKind(), 6153f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getSourceRange()); 6154b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 61551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 615660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr; 61571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump { 6158b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // C++0x [expr.sizeof]p1: 6159b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // The operand is either an expression, which is an unevaluated operand 6160b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // [...] 6161f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 61621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6163b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); 6164b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6165f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6167b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) 61683fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6169b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 61701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6171f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), 6172f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getOperatorLoc(), 6173f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getKind(), 6174f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getSourceRange()); 6175b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 61761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6177b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 617860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6179454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { 618060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6181b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6182f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 618460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6185b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6186f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6189b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6190b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6191b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 61923fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 61931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildArraySubscriptExpr(LHS.get(), 6195b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLHS()->getLocStart(), 61969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get(), 6197b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRBracketLoc()); 6198b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 61991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 620160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6202454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCallExpr(CallExpr *E) { 6203b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the callee. 620460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 6205b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Callee.isInvalid()) 6206f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6207b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6208b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform arguments. 6209b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgChanged = false; 6210ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 6211aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 6212aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgChanged)) 6213aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6214aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 6215b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6216b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Callee.get() == E->getCallee() && 6217b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgChanged) 621892be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E);; 62191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6220b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Wrong source location information for the '('. 62211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeLParenLoc 6222b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = ((Expr *)Callee.get())->getSourceRange().getBegin(); 62239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, 6224b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Args), 6225b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6226b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 62271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 622960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6230454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { 623160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 6232b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Base.isInvalid()) 6233f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 623540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc; 623683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor if (E->hasQualifier()) { 623740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc 623840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 623940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 624040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!QualifierLoc) 6241f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 624283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 62431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6244f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *Member 62457c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), 62467c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getMemberDecl())); 6247b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Member) 6248f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62506bb8017bb9e828d118e15e59d71c66bba323c364John McCall NamedDecl *FoundDecl = E->getFoundDecl(); 62516bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (FoundDecl == E->getMemberDecl()) { 62526bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl = Member; 62536bb8017bb9e828d118e15e59d71c66bba323c364John McCall } else { 62546bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl = cast_or_null<NamedDecl>( 62556bb8017bb9e828d118e15e59d71c66bba323c364John McCall getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); 62566bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!FoundDecl) 6257f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62586bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 62596bb8017bb9e828d118e15e59d71c66bba323c364John McCall 6260b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6261b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Base.get() == E->getBase() && 626240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc == E->getQualifierLoc() && 62638a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor Member == E->getMemberDecl() && 62646bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl == E->getFoundDecl() && 6265096832c5ed5b9106fa177ebc148489760c3bc496John McCall !E->hasExplicitTemplateArgs()) { 6266c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 62671f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson // Mark it referenced in the new context regardless. 62681f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson // FIXME: this is a bit instantiation-specific. 62691f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); 62703fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 62711f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson } 6272b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6273d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs; 6274096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (E->hasExplicitTemplateArgs()) { 6275d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TransArgs.setLAngleLoc(E->getLAngleLoc()); 6276d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TransArgs.setRAngleLoc(E->getRAngleLoc()); 6277fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 6278fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 6279fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 6280fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 62818a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor } 6282c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6283b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Bogus source location for the operator 6284b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeOperatorLoc 6285b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); 6286b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6287c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // FIXME: to do this check properly, we will need to preserve the 6288c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // first-qualifier-in-scope here, just in case we had a dependent 6289c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // base (and therefore couldn't do the check) and a 6290c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // nested-name-qualifier (and therefore could do the lookup). 6291c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall NamedDecl *FirstQualifierInScope = 0; 6292c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 62939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, 6294b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrow(), 629540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc, 62962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara E->getMemberNameInfo(), 62978a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor Member, 62986bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl, 6299096832c5ed5b9106fa177ebc148489760c3bc496John McCall (E->hasExplicitTemplateArgs() 6300d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall ? &TransArgs : 0), 6301c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall FirstQualifierInScope); 6302b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 63031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6304b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 630560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6306454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { 630760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6308b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6309f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 631160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6312b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6313f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6315b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6316b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 63183fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 63191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), 63219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), RHS.get()); 6322b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6323b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 63241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 632560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6326b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCompoundAssignOperator( 6327454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CompoundAssignOperator *E) { 6328454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformBinaryOperator(E); 6329b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 63301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6331b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 633256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallExprResult TreeTransform<Derived>:: 633356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallTransformBinaryConditionalOperator(BinaryConditionalOperator *e) { 633456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // Just rebuild the common and RHS expressions and see whether we 633556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // get any changes. 633656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 633756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); 633856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (commonExpr.isInvalid()) 633956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return ExprError(); 634056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 634156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); 634256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (rhs.isInvalid()) 634356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return ExprError(); 634456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 634556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (!getDerived().AlwaysRebuild() && 634656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall commonExpr.get() == e->getCommon() && 634756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs.get() == e->getFalseExpr()) 634856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return SemaRef.Owned(e); 634956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 635056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return getDerived().RebuildConditionalOperator(commonExpr.take(), 635156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall e->getQuestionLoc(), 635256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 0, 635356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall e->getColonLoc(), 635456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs.get()); 635556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 635656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 635756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCalltemplate<typename Derived> 635860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6359454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { 636060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(E->getCond()); 6361b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Cond.isInvalid()) 6362f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 636460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6365b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6366f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 636860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6369b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6370f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6372b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6373b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Cond.get() == E->getCond() && 6374b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6375b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 63763fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 63771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildConditionalOperator(Cond.get(), 637947e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor E->getQuestionLoc(), 63809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), 638147e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor E->getColonLoc(), 63829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get()); 6383b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 63841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 638660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6387454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { 6388a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor // Implicit casts are eliminated during transformation, since they 6389a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor // will be recomputed by semantic analysis after transformation. 63906eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return getDerived().TransformExpr(E->getSubExprAsWritten()); 6391b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 63921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6393b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 639460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6395454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { 6396ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 6397ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 6398ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 6399ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor 640060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 64016eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 6402b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6403f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6405b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6406ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 6407b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 64083fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 64091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 64109d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), 6411ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type, 6412b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc(), 64139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get()); 6414b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6416b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 641760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6418454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { 641942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *OldT = E->getTypeSourceInfo(); 642042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *NewT = getDerived().TransformType(OldT); 642142f56b50062cd3b3c6b23fdb9053578ae9145664John McCall if (!NewT) 6422f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 642460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Init = getDerived().TransformExpr(E->getInitializer()); 6425b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Init.isInvalid()) 6426f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6428b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 642942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall OldT == NewT && 6430b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Init.get() == E->getInitializer()) 643192be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 6432b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 64331d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // Note: the expression type doesn't necessarily match the 64341d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // type-as-written, but that's okay, because it should always be 64351d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // derivable from the initializer. 64361d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 643742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, 6438b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getInitializer()->getLocEnd(), 64399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init.get()); 6440b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6442b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 644360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6444454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { 644560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 6446b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Base.isInvalid()) 6447f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6449b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6450b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Base.get() == E->getBase()) 64513fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 64521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6453b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Bad source location 64541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeOperatorLoc 6455b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); 64569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, 6457b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getAccessorLoc(), 6458b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getAccessor()); 6459b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6461b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 646260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6463454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { 6464b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool InitChanged = false; 64651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6466ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*, 4> Inits(SemaRef); 6467aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, 6468aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Inits, &InitChanged)) 6469aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6470aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 6471b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && !InitChanged) 64723fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 64731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6474b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), 6475e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor E->getRBraceLoc(), E->getType()); 6476b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6478b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 647960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6480454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { 6481b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Designation Desig; 64821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 648343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transform the initializer value 648460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Init = getDerived().TransformExpr(E->getInit()); 6485b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Init.isInvalid()) 6486f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 648843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transform the designators. 6489ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef); 6490b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ExprChanged = false; 6491b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), 6492b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor DEnd = E->designators_end(); 6493b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D != DEnd; ++D) { 6494b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (D->isFieldDesignator()) { 6495b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Desig.AddDesignator(Designator::getField(D->getFieldName(), 6496b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getDotLoc(), 6497b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getFieldLoc())); 6498b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor continue; 6499b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 65001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6501b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (D->isArrayDesignator()) { 650260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); 6503b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Index.isInvalid()) 6504f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 65061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Desig.AddDesignator(Designator::getArray(Index.get(), 6507b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getLBracketLoc())); 65081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6509b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); 6510b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(Index.release()); 6511b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor continue; 6512b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 65131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6514b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor assert(D->isArrayRangeDesignator() && "New kind of designator?"); 651560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Start 6516b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = getDerived().TransformExpr(E->getArrayRangeStart(*D)); 6517b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Start.isInvalid()) 6518f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 652060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); 6521b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (End.isInvalid()) 6522f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 65241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Desig.AddDesignator(Designator::getArrayRange(Start.get(), 6525b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor End.get(), 6526b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getLBracketLoc(), 6527b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getEllipsisLoc())); 65281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6529b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || 6530b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor End.get() != E->getArrayRangeEnd(*D); 65311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6532b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(Start.release()); 6533b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(End.release()); 6534b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 65351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6536b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6537b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Init.get() == E->getInit() && 6538b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ExprChanged) 65393fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 65401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6541b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), 6542b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getEqualOrColonLoc(), 65439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall E->usesGNUSyntax(), Init.get()); 6544b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 65451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6546b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 654760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6548b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformImplicitValueInitExpr( 6549454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall ImplicitValueInitExpr *E) { 65505557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); 6551c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 65525557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor // FIXME: Will we ever have proper type location here? Will we actually 65535557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor // need to transform the type? 6554b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor QualType T = getDerived().TransformType(E->getType()); 6555b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (T.isNull()) 6556f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6558b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6559b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T == E->getType()) 65603fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 65611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6562b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildImplicitValueInitExpr(T); 6563b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 65641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6565b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 656660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6567454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { 65689bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); 65699bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor if (!TInfo) 6570f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 657260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 6573b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6574f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6576b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 65772cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TInfo == E->getWrittenTypeInfo() && 6578b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 65793fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 65801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 65819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), 65822cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TInfo, E->getRParenLoc()); 6583b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6584b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6585b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 658660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6587454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { 6588b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 6589ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*, 4> Inits(SemaRef); 6590aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, 6591aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 6592aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6593aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 6594b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildParenListExpr(E->getLParenLoc(), 6595b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Inits), 6596b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6597b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 65981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6599b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform an address-of-label expression. 6600b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 6601b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// By default, the transformation of an address-of-label expression always 6602b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// rebuilds the expression, so that the label identifier can be resolved to 6603b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// the corresponding label statement by semantic analysis. 6604b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 660560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6606454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { 660757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), 660857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner E->getLabel()); 660957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner if (!LD) 661057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return ExprError(); 661157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 6612b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), 661357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner cast<LabelDecl>(LD)); 6614b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 66161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 661760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6618454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { 661960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt 6620b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = getDerived().TransformCompoundStmt(E->getSubStmt(), true); 6621b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubStmt.isInvalid()) 6622f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6624b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6625b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubStmt.get() == E->getSubStmt()) 662692be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 66271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 66281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildStmtExpr(E->getLParenLoc(), 66299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubStmt.get(), 6630b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6631b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6633b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 663460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6635454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { 663660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(E->getCond()); 6637b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Cond.isInvalid()) 6638f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 664060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6641b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6642f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 664460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6645b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6646f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6648b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6649b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Cond.get() == E->getCond() && 6650b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6651b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 66523fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 66531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6654b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), 66559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond.get(), LHS.get(), RHS.get(), 6656b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6657b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6659b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 666060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6661454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { 66623fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6663b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6664b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6665b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 666660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6667454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { 6668668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor switch (E->getOperator()) { 6669668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_New: 6670668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Delete: 6671668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Array_New: 6672668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Array_Delete: 6673668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); 6674f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6675c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6676668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Call: { 6677668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // This is a call to an object's operator(). 6678668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); 6679668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6680668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Transform the object itself. 668160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Object = getDerived().TransformExpr(E->getArg(0)); 6682668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor if (Object.isInvalid()) 6683f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6684668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6685668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // FIXME: Poor location information 6686668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor SourceLocation FakeLParenLoc 6687668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor = SemaRef.PP.getLocForEndOfToken( 6688668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor static_cast<Expr *>(Object.get())->getLocEnd()); 6689668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6690668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Transform the call arguments. 6691ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 6692aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, 6693aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args)) 6694aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6695668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 66969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, 6697668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor move_arg(Args), 6698668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor E->getLocEnd()); 6699668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor } 6700668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6701668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ 6702668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_##Name: 6703668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) 6704668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#include "clang/Basic/OperatorKinds.def" 6705668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Subscript: 6706668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Handled below. 6707668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor break; 6708668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6709668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Conditional: 6710668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("conditional operator is not actually overloadable"); 6711f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6712668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6713668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_None: 6714668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case NUM_OVERLOADED_OPERATORS: 6715668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("not an overloaded operator?"); 6716f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6717668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor } 6718668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 671960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 6720b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Callee.isInvalid()) 6721f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 67221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 672360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult First = getDerived().TransformExpr(E->getArg(0)); 6724b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (First.isInvalid()) 6725f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6726b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 672760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Second; 6728b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->getNumArgs() == 2) { 6729b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Second = getDerived().TransformExpr(E->getArg(1)); 6730b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Second.isInvalid()) 6731f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6732b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 67331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6734b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6735b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Callee.get() == E->getCallee() && 6736b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor First.get() == E->getArg(0) && 67371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) 673892be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 67391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6740b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), 6741b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOperatorLoc(), 67429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Callee.get(), 67439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall First.get(), 67449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Second.get()); 6745b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 67461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6747b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 674860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6749454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { 6750454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCallExpr(E); 6751b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 67521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6753b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 6754e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneExprResult 6755e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneTreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { 6756e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // Transform the callee. 6757e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 6758e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (Callee.isInvalid()) 6759e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return ExprError(); 6760e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6761e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // Transform exec config. 6762e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); 6763e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (EC.isInvalid()) 6764e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return ExprError(); 6765e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6766e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // Transform arguments. 6767e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne bool ArgChanged = false; 6768e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ASTOwningVector<Expr*> Args(SemaRef); 6769e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 6770e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne &ArgChanged)) 6771e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return ExprError(); 6772e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6773e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (!getDerived().AlwaysRebuild() && 6774e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne Callee.get() == E->getCallee() && 6775e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne !ArgChanged) 677692be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 6777e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6778e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // FIXME: Wrong source location information for the '('. 6779e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne SourceLocation FakeLParenLoc 6780e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne = ((Expr *)Callee.get())->getSourceRange().getBegin(); 6781e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, 6782e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne move_arg(Args), 6783e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne E->getRParenLoc(), EC.get()); 6784e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne} 6785e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6786e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournetemplate<typename Derived> 678760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6788454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { 6789ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 6790ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 6791ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 6792ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor 679360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 67946eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 6795b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6796f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 67971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6798b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6799ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 6800b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 68013fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 68021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6803b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Poor source location information here. 68041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeLAngleLoc 6805b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); 6806b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); 6807b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeRParenLoc 6808b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken( 6809b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getSubExpr()->getSourceRange().getEnd()); 6810b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), 68111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump E->getStmtClass(), 6812b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeLAngleLoc, 6813ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type, 6814b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRAngleLoc, 6815b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRAngleLoc, 68169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 6817b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRParenLoc); 6818b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6820b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 682160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6822454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { 6823454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 6824b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6826b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 682760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6828454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { 6829454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 6830b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6832b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 683360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6834b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXReinterpretCastExpr( 6835454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXReinterpretCastExpr *E) { 6836454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 6837b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6839b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 684060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6841454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { 6842454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 6843b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6845b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 684660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6847b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXFunctionalCastExpr( 6848454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXFunctionalCastExpr *E) { 6849ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 6850ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 6851ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 68521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 685360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 68546eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 6855b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6856f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6858b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6859ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 6860b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 68613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 68621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6863ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return getDerived().RebuildCXXFunctionalCastExpr(Type, 6864b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getSubExpr()->getLocStart(), 68659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 6866b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6867b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6869b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 687060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6871454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { 6872b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->isTypeOperand()) { 687357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TypeSourceInfo *TInfo 687457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor = getDerived().TransformType(E->getTypeOperandSourceInfo()); 687557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor if (!TInfo) 6876f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6878b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 687957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TInfo == E->getTypeOperandSourceInfo()) 68803fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 68811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 688257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return getDerived().RebuildCXXTypeidExpr(E->getType(), 688357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor E->getLocStart(), 688457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TInfo, 6885b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 6886b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 68871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6888ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman // We don't know whether the subexpression is potentially evaluated until 6889ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman // after we perform semantic analysis. We speculatively assume it is 6890ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman // unevaluated; it will get fixed later if the subexpression is in fact 6891b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // potentially evaluated. 6892ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 68931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 689460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); 6895b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6896f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6898b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6899b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getExprOperand()) 69003fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 69011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 690257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return getDerived().RebuildCXXTypeidExpr(E->getType(), 690357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor E->getLocStart(), 69049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 6905b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 6906b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6907b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6908b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 690960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 691001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetTreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { 691101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (E->isTypeOperand()) { 691201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TypeSourceInfo *TInfo 691301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet = getDerived().TransformType(E->getTypeOperandSourceInfo()); 691401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!TInfo) 691501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return ExprError(); 691601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 691701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!getDerived().AlwaysRebuild() && 691801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TInfo == E->getTypeOperandSourceInfo()) 69193fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 692001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 69213c52a218f41f091a17582d037663594d2b8dc708Douglas Gregor return getDerived().RebuildCXXUuidofExpr(E->getType(), 692201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocStart(), 692301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TInfo, 692401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocEnd()); 692501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 692601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 692701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 692801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 692901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); 693001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (SubExpr.isInvalid()) 693101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return ExprError(); 693201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 693301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!getDerived().AlwaysRebuild() && 693401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SubExpr.get() == E->getExprOperand()) 69353fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 693601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 693701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getDerived().RebuildCXXUuidofExpr(E->getType(), 693801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocStart(), 693901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SubExpr.get(), 694001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocEnd()); 694101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet} 694201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 694301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichettemplate<typename Derived> 694401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetExprResult 6945454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { 69463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6947b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 69481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6949b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 695060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6951b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( 6952454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXNullPtrLiteralExpr *E) { 69533fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6954b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 69551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6956b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 695760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6958454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { 6959ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor DeclContext *DC = getSema().getFunctionLevelDeclContext(); 69607a614d8380297fcd2bc23986241905d97222948cRichard Smith QualType T; 69617a614d8380297fcd2bc23986241905d97222948cRichard Smith if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) 69627a614d8380297fcd2bc23986241905d97222948cRichard Smith T = MD->getThisType(getSema().Context); 69637a614d8380297fcd2bc23986241905d97222948cRichard Smith else 69647a614d8380297fcd2bc23986241905d97222948cRichard Smith T = getSema().Context.getPointerType( 69657a614d8380297fcd2bc23986241905d97222948cRichard Smith getSema().Context.getRecordType(cast<CXXRecordDecl>(DC))); 69661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6967ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!getDerived().AlwaysRebuild() && T == E->getType()) 69683fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 69691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6970828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); 6971b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 69721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6973b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 697460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6975454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { 697660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 6977b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6978f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 69791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6980b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6981b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 69823fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6983b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6984bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), 6985bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor E->isThrownVariableInScope()); 6986b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 69871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6988b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 698960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6990454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { 69911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParmVarDecl *Param 69927c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), 69937c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getParam())); 6994b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Param) 6995f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 69961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 699753cb6f82c41397917b14fb8cdcb32e6c9bd07655Chandler Carruth if (!getDerived().AlwaysRebuild() && 6998b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Param == E->getParam()) 69993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 70001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7001036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); 7002b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 70031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7004b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 700560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7006ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas GregorTreeTransform<Derived>::TransformCXXScalarValueInitExpr( 7007ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXScalarValueInitExpr *E) { 7008ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 7009ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 7010f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7011ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor 7012b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7013ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo()) 70143fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 70151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7016ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXScalarValueInitExpr(T, 7017ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /*FIXME:*/T->getTypeLoc().getEndLoc(), 7018ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor E->getRParenLoc()); 7019b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 70201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7021b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 702260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7023454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { 7024b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the type that we're allocating 70251bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *AllocTypeInfo 70261bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); 70271bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor if (!AllocTypeInfo) 7028f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7030b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the size of the array we're allocating (if any). 703160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); 7032b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (ArraySize.isInvalid()) 7033f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7035b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the placement arguments (if any). 7036b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 7037ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> PlacementArgs(SemaRef); 7038aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getPlacementArgs(), 7039aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor E->getNumPlacementArgs(), true, 7040aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor PlacementArgs, &ArgumentChanged)) 7041aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 70421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 70434e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor // Transform the constructor arguments (if any). 70444e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor // As an annoying corner case, we may have introduced an implicit value- 70454e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor // initialization expression when allocating a new array, which we implicitly 70464e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor // drop. It will be re-created during type checking. 7047ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> ConstructorArgs(SemaRef); 70484e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor if (!(E->isArray() && E->getNumConstructorArgs() == 1 && 70494e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor isa<ImplicitValueInitExpr>(E->getConstructorArgs()[0])) && 70504e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true, 7051aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor ConstructorArgs, &ArgumentChanged)) 7052aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 70531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 70541af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Transform constructor, new operator, and delete operator. 70551af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor CXXConstructorDecl *Constructor = 0; 70561af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getConstructor()) { 70571af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor Constructor = cast_or_null<CXXConstructorDecl>( 70587c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 70597c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 70601af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!Constructor) 7061f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70621af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 70631af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor 70641af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorNew = 0; 70651af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorNew()) { 70661af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorNew = cast_or_null<FunctionDecl>( 70677c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 70687c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorNew())); 70691af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorNew) 7070f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70711af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 70721af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor 70731af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorDelete = 0; 70741af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorDelete()) { 70751af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete = cast_or_null<FunctionDecl>( 70767c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 70777c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorDelete())); 70781af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorDelete) 7079f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70801af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 7081c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7082b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 70831bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocTypeInfo == E->getAllocatedTypeSourceInfo() && 7084b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArraySize.get() == E->getArraySize() && 70851af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor Constructor == E->getConstructor() && 70861af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorNew == E->getOperatorNew() && 70871af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete == E->getOperatorDelete() && 70881af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor !ArgumentChanged) { 70891af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark any declarations we need as referenced. 70901af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: instantiation-specific. 70911af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (Constructor) 70921af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); 70931af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorNew) 70941af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); 70951af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorDelete) 70961af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); 70972ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor 70982ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor if (E->isArray() && Constructor && 70992ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor !E->getAllocatedType()->isDependentType()) { 71002ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor QualType ElementType 71012ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor = SemaRef.Context.getBaseElementType(E->getAllocatedType()); 71022ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { 71032ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); 71042ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { 71052ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), Destructor); 71062ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor } 71072ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor } 71082ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor } 71092ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor 71103fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 71111af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 71121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71131bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor QualType AllocType = AllocTypeInfo->getType(); 71145b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (!ArraySize.get()) { 71155b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // If no array size was specified, but the new expression was 71165b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // instantiated with an array type (e.g., "new T" where T is 71175b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // instantiated with "int[4]"), extract the outer bound from the 71185b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // array type as our array size. We do this with constant and 71195b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // dependently-sized array types. 71205b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); 71215b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (!ArrayT) { 71225b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // Do nothing 71235b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } else if (const ConstantArrayType *ConsArrayT 71245b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor = dyn_cast<ConstantArrayType>(ArrayT)) { 7125c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ArraySize 71269996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, 71279996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis ConsArrayT->getSize(), 71289996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis SemaRef.Context.getSizeType(), 71299996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /*FIXME:*/E->getLocStart())); 71305b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor AllocType = ConsArrayT->getElementType(); 71315b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } else if (const DependentSizedArrayType *DepArrayT 71325b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor = dyn_cast<DependentSizedArrayType>(ArrayT)) { 71335b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (DepArrayT->getSizeExpr()) { 71343fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); 71355b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor AllocType = DepArrayT->getElementType(); 71365b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 71375b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 71385b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 71391bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor 7140b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXNewExpr(E->getLocStart(), 7141b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isGlobalNew(), 7142b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLocStart(), 7143b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(PlacementArgs), 7144b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLocStart(), 71454bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor E->getTypeIdParens(), 7146b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor AllocType, 71471bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocTypeInfo, 71489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ArraySize.get(), 71494e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor E->getConstructorLParen(), 7150b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(ConstructorArgs), 71514e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor E->getConstructorRParen()); 7152b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 71531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7154b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 715560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7156454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { 715760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Operand = getDerived().TransformExpr(E->getArgument()); 7158b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Operand.isInvalid()) 7159f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 71601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71611af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Transform the delete operator, if known. 71621af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorDelete = 0; 71631af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorDelete()) { 71641af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete = cast_or_null<FunctionDecl>( 71657c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 71667c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorDelete())); 71671af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorDelete) 7168f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 71691af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 7170c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7171b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 71721af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor Operand.get() == E->getArgument() && 71731af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete == E->getOperatorDelete()) { 71741af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark any declarations we need as referenced. 71751af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: instantiation-specific. 71761af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorDelete) 71771af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); 71785833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor 71795833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor if (!E->getArgument()->isTypeDependent()) { 71805833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor QualType Destroyed = SemaRef.Context.getBaseElementType( 71815833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor E->getDestroyedType()); 71825833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { 71835833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); 71845833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), 71855833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor SemaRef.LookupDestructor(Record)); 71865833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor } 71875833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor } 71885833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor 71893fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 71901af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 71911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7192b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), 7193b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isGlobalDelete(), 7194b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrayForm(), 71959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Operand.get()); 7196b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 71971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7198b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 719960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7200a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas GregorTreeTransform<Derived>::TransformCXXPseudoDestructorExpr( 7201454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXPseudoDestructorExpr *E) { 720260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 7203a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor if (Base.isInvalid()) 7204f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 72051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7206b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectTypePtr; 7207a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor bool MayBePseudoDestructor = false; 72089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), 7209a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getOperatorLoc(), 7210a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->isArrow()? tok::arrow : tok::period, 7211a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor ObjectTypePtr, 7212a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor MayBePseudoDestructor); 7213a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (Base.isInvalid()) 7214f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7215c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7216b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall QualType ObjectType = ObjectTypePtr.get(); 7217f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); 7218f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor if (QualifierLoc) { 7219f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor QualifierLoc 7220f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); 7221f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor if (!QualifierLoc) 722243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return ExprError(); 722343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } 7224f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor CXXScopeSpec SS; 7225f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SS.Adopt(QualifierLoc); 72261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7227a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed; 7228a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (E->getDestroyedTypeInfo()) { 7229a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor TypeSourceInfo *DestroyedTypeInfo 723043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), 7231b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor ObjectType, 0, SS); 7232a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (!DestroyedTypeInfo) 7233f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7234a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed = DestroyedTypeInfo; 72356b18e740495b67b439fa366367242110365cc4d9Douglas Gregor } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { 7236a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // We aren't likely to be able to resolve the identifier down to a type 7237a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // now anyway, so just retain the identifier. 7238a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), 7239a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc()); 7240a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } else { 7241a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // Look for a destructor known with the given name. 7242b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), 7243a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor *E->getDestroyedTypeIdentifier(), 7244a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc(), 7245a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /*Scope=*/0, 7246a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor SS, ObjectTypePtr, 7247a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor false); 7248a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (!T) 7249f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7250c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7251a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed 7252a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), 7253a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc()); 7254a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 725526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor 725626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor TypeSourceInfo *ScopeTypeInfo = 0; 725726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor if (E->getScopeTypeInfo()) { 725843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo()); 725926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor if (!ScopeTypeInfo) 7260f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7261a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor } 7262c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 72639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), 7264a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor E->getOperatorLoc(), 7265a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor E->isArrow(), 7266f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SS, 726726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor ScopeTypeInfo, 726826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor E->getColonColonLoc(), 7269fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor E->getTildeLoc(), 7270a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed); 7271a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor} 72721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7273a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregortemplate<typename Derived> 727460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7275ba13543329afac4a0d01304ec2ec4924d99306a6John McCallTreeTransform<Derived>::TransformUnresolvedLookupExpr( 7276454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall UnresolvedLookupExpr *Old) { 7277f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), 7278f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall Sema::LookupOrdinaryName); 7279f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7280f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Transform all the decls. 7281f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), 7282f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall E = Old->decls_end(); I != E; ++I) { 72837c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor NamedDecl *InstD = static_cast<NamedDecl*>( 72847c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(Old->getNameLoc(), 72857c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor *I)); 72869f54ad4381370c6b771424b53d219e661d6d6706John McCall if (!InstD) { 72879f54ad4381370c6b771424b53d219e661d6d6706John McCall // Silently ignore these if a UsingShadowDecl instantiated to nothing. 72889f54ad4381370c6b771424b53d219e661d6d6706John McCall // This can happen because of dependent hiding. 72899f54ad4381370c6b771424b53d219e661d6d6706John McCall if (isa<UsingShadowDecl>(*I)) 72909f54ad4381370c6b771424b53d219e661d6d6706John McCall continue; 72919f54ad4381370c6b771424b53d219e661d6d6706John McCall else 7292f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 72939f54ad4381370c6b771424b53d219e661d6d6706John McCall } 7294f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7295f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Expand using declarations. 7296f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (isa<UsingDecl>(InstD)) { 7297f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall UsingDecl *UD = cast<UsingDecl>(InstD); 7298f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall for (UsingDecl::shadow_iterator I = UD->shadow_begin(), 7299f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall E = UD->shadow_end(); I != E; ++I) 7300f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.addDecl(*I); 7301f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall continue; 7302f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 7303f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7304f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.addDecl(InstD); 7305f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 7306f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7307f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Resolve a kind, but don't do any further analysis. If it's 7308f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // ambiguous, the callee needs to deal with it. 7309f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.resolveKind(); 7310f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7311f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Rebuild the nested-name qualifier, if present. 7312f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall CXXScopeSpec SS; 73134c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (Old->getQualifierLoc()) { 73144c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc 73154c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); 73164c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (!QualifierLoc) 7317f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7318c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 73194c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor SS.Adopt(QualifierLoc); 7320c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt } 7321c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7322c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor if (Old->getNamingClass()) { 732366c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor CXXRecordDecl *NamingClass 732466c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( 732566c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNameLoc(), 732666c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNamingClass())); 732766c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor if (!NamingClass) 7328f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7329c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 733066c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor R.setNamingClass(NamingClass); 7331f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 7332f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7333f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // If we have no template arguments, it's a normal declaration name. 7334f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!Old->hasExplicitTemplateArgs()) 7335f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); 7336f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7337f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // If we have template arguments, rebuild them, then rebuild the 7338f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // templateid expression. 7339f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); 7340fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), 7341fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor Old->getNumTemplateArgs(), 7342fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7343fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 7344f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7345f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), 7346f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall TransArgs); 7347b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 73481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7349b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 735060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7351454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { 73523d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); 73533d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor if (!T) 7354f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 73551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7356b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 73573d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor T == E->getQueriedTypeSourceInfo()) 73583fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 73591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 73601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildUnaryTypeTrait(E->getTrait(), 7361b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocStart(), 7362b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T, 7363b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 7364b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 73651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7366b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 736760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 73686ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetTreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { 73696ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); 73706ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!LhsT) 73716ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return ExprError(); 73726ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 73736ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); 73746ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!RhsT) 73756ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return ExprError(); 73766ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 73776ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!getDerived().AlwaysRebuild() && 73786ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) 73796ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return SemaRef.Owned(E); 73806ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 73816ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return getDerived().RebuildBinaryTypeTrait(E->getTrait(), 73826ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet E->getLocStart(), 73836ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet LhsT, RhsT, 73846ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet E->getLocEnd()); 73856ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet} 73866ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 73876ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichettemplate<typename Derived> 73886ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetExprResult 738921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John WiegleyTreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { 739021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); 739121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (!T) 739221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return ExprError(); 739321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 739421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (!getDerived().AlwaysRebuild() && 739521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley T == E->getQueriedTypeSourceInfo()) 739621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return SemaRef.Owned(E); 739721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 739821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ExprResult SubExpr; 739921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley { 740021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 740121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); 740221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (SubExpr.isInvalid()) 740321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return ExprError(); 740421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 740521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) 740621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return SemaRef.Owned(E); 740721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 740821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 740921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return getDerived().RebuildArrayTypeTrait(E->getTrait(), 741021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley E->getLocStart(), 741121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley T, 741221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SubExpr.get(), 741321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley E->getLocEnd()); 741421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley} 741521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 741621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleytemplate<typename Derived> 741721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John WiegleyExprResult 7418552622067dc45013d240f73952fece703f5e63bdJohn WiegleyTreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { 7419552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExprResult SubExpr; 7420552622067dc45013d240f73952fece703f5e63bdJohn Wiegley { 7421552622067dc45013d240f73952fece703f5e63bdJohn Wiegley EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 7422552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); 7423552622067dc45013d240f73952fece703f5e63bdJohn Wiegley if (SubExpr.isInvalid()) 7424552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return ExprError(); 7425552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 7426552622067dc45013d240f73952fece703f5e63bdJohn Wiegley if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) 7427552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return SemaRef.Owned(E); 7428552622067dc45013d240f73952fece703f5e63bdJohn Wiegley } 7429552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 7430552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return getDerived().RebuildExpressionTrait( 7431552622067dc45013d240f73952fece703f5e63bdJohn Wiegley E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); 7432552622067dc45013d240f73952fece703f5e63bdJohn Wiegley} 7433552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 7434552622067dc45013d240f73952fece703f5e63bdJohn Wiegleytemplate<typename Derived> 7435552622067dc45013d240f73952fece703f5e63bdJohn WiegleyExprResult 7436865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformDependentScopeDeclRefExpr( 74372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DependentScopeDeclRefExpr *E) { 743800cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc 743900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 744000cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor if (!QualifierLoc) 7441f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 74421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 744343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // TODO: If this is a conversion-function-id, verify that the 744443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // destination type name (if present) resolves the same way after 744543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // instantiation as it did in the local scope. 744643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 74472577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo 74482577743c5650c646fb705df01403707e94f2df04Abramo Bagnara = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); 74492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!NameInfo.getName()) 7450f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 74511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7452f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!E->hasExplicitTemplateArgs()) { 7453f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!getDerived().AlwaysRebuild() && 745400cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor QualifierLoc == E->getQualifierLoc() && 74552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // Note: it is sufficient to compare the Name component of NameInfo: 74562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // if name has not changed, DNLoc has not changed either. 74572577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getDeclName()) 74583fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 74591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 746000cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, 74612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7462f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /*TemplateArgs*/ 0); 7463f17bb74e74aca9bb0525d2249041ab65c7d1fd48Douglas Gregor } 7464d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 7465d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); 7466fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 7467fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 7468fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7469fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 7470b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 747100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, 74722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7473f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall &TransArgs); 7474b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7475b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7476b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 747760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7478454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { 7479321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor // CXXConstructExprs are always implicit, so when we have a 7480321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor // 1-argument construction we just transform that argument. 7481321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor if (E->getNumArgs() == 1 || 7482321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) 7483321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor return getDerived().TransformExpr(E->getArg(0)); 7484321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor 7485b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); 7486b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7487b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor QualType T = getDerived().TransformType(E->getType()); 7488b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (T.isNull()) 7489f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7490b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7491b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXConstructorDecl *Constructor 7492b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = cast_or_null<CXXConstructorDecl>( 74937c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 74947c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 7495b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Constructor) 7496f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 74971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7498b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 7499ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 7500aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 7501aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 7502aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 7503aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 7504b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7505b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T == E->getType() && 7506b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Constructor == E->getConstructor() && 7507c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor !ArgumentChanged) { 75081af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark the constructor as referenced. 75091af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: Instantiation-specific 7510c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); 75113fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7512c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor } 75131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 75144411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), 75154411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor Constructor, E->isElidable(), 75168c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor move_arg(Args), 75177cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara E->hadMultipleCandidates(), 75188c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor E->requiresZeroInitialization(), 7519428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth E->getConstructionKind(), 7520428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth E->getParenRange()); 7521b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 75221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7523b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform a C++ temporary-binding expression. 7524b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 75255132655e4296b780672e9a96b46a740135073534Douglas Gregor/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just 75265132655e4296b780672e9a96b46a740135073534Douglas Gregor/// transform the subexpression and return that. 7527b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 752860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7529454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { 75305132655e4296b780672e9a96b46a740135073534Douglas Gregor return getDerived().TransformExpr(E->getSubExpr()); 7531b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 75321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 75334765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// \brief Transform a C++ expression that contains cleanups that should 75344765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// be run after the expression is evaluated. 7535b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 75364765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Since ExprWithCleanups nodes are implicitly generated, we 75375132655e4296b780672e9a96b46a740135073534Douglas Gregor/// just transform the subexpression and return that. 7538b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 753960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 75404765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallTreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { 75415132655e4296b780672e9a96b46a740135073534Douglas Gregor return getDerived().TransformExpr(E->getSubExpr()); 7542b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 75431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7544b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 754560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7546b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXTemporaryObjectExpr( 7547ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXTemporaryObjectExpr *E) { 7548ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 7549ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 7550f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 75511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7552b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXConstructorDecl *Constructor 7553b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = cast_or_null<CXXConstructorDecl>( 7554c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt getDerived().TransformDecl(E->getLocStart(), 75557c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 7556b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Constructor) 7557f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 75581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7559b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 7560ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 7561b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Args.reserve(E->getNumArgs()); 7562aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 7563aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 7564aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 75651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7566b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7567ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo() && 7568b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Constructor == E->getConstructor() && 756991be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor !ArgumentChanged) { 757091be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor // FIXME: Instantiation-specific 7571ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); 75723fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.MaybeBindToTemporary(E); 757391be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor } 7574ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor 7575ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXTemporaryObjectExpr(T, 7576ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /*FIXME:*/T->getTypeLoc().getEndLoc(), 7577b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Args), 7578b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 7579b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 75801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7581b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 758260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7583b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( 7584454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXUnresolvedConstructExpr *E) { 7585ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 7586ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 7587f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 75881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7589b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 7590ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 7591aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args.reserve(E->arg_size()); 7592aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, 7593aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 7594aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 7595aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 7596b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7597ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo() && 7598b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgumentChanged) 75993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 76001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7601b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: we're faking the locations of the commas 7602ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXUnresolvedConstructExpr(T, 7603b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLParenLoc(), 7604b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Args), 7605b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 7606b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 76071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7608b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 760960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7610865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( 76112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara CXXDependentScopeMemberExpr *E) { 7612b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the base of the expression. 761360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base((Expr*) 0); 7614aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *OldBase; 7615aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType; 7616aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType ObjectType; 7617aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!E->isImplicitAccess()) { 7618aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OldBase = E->getBase(); 7619aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base = getDerived().TransformExpr(OldBase); 7620aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 7621f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 76221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7623aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall // Start the member reference and compute the object's type. 7624b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectTy; 7625d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor bool MayBePseudoDestructor = false; 76269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), 7627aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall E->getOperatorLoc(), 7628a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor E->isArrow()? tok::arrow : tok::period, 7629d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor ObjectTy, 7630d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor MayBePseudoDestructor); 7631aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 7632f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7633aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 7634b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ObjectType = ObjectTy.get(); 7635aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = ((Expr*) Base.get())->getType(); 7636aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } else { 7637aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OldBase = 0; 7638aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = getDerived().TransformType(E->getBaseType()); 7639aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); 7640aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 76411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76426cd219879ffce00920189ec1dcea927a42602961Douglas Gregor // Transform the first part of the nested-name-specifier that qualifies 76436cd219879ffce00920189ec1dcea927a42602961Douglas Gregor // the member name. 7644c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor NamedDecl *FirstQualifierInScope 76456cd219879ffce00920189ec1dcea927a42602961Douglas Gregor = getDerived().TransformFirstQualifierInScope( 76467c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor E->getFirstQualifierFoundInScope(), 76477c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor E->getQualifierLoc().getBeginLoc()); 76481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76497c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 7650a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor if (E->getQualifier()) { 76517c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc 76527c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), 76537c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor ObjectType, 76547c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor FirstQualifierInScope); 76557c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor if (!QualifierLoc) 7656f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7657a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor } 76581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 765943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // TODO: If this is a conversion-function-id, verify that the 766043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // destination type name (if present) resolves the same way after 766143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // instantiation as it did in the local scope. 766243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 76632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo 766443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); 76652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!NameInfo.getName()) 7666f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 76671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7668aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!E->hasExplicitTemplateArgs()) { 76693b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor // This is a reference to a member without an explicitly-specified 76703b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor // template argument list. Optimize for this common case. 76713b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor if (!getDerived().AlwaysRebuild() && 7672aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base.get() == OldBase && 7673aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType == E->getBaseType() && 76747c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc == E->getQualifierLoc() && 76752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getMember() && 76763b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor FirstQualifierInScope == E->getFirstQualifierFoundInScope()) 76773fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 76781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), 7680aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 76813b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor E->isArrow(), 76823b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor E->getOperatorLoc(), 76837c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc, 7684129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall FirstQualifierInScope, 76852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7686129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /*TemplateArgs*/ 0); 76873b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 76883b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor 7689d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); 7690fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 7691fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 7692fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7693fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 76941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), 7696aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 7697b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrow(), 7698b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOperatorLoc(), 76997c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc, 77003b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor FirstQualifierInScope, 77012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7702129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall &TransArgs); 7703129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall} 7704129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7705129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCalltemplate<typename Derived> 770660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7707454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { 7708129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Transform the base of the expression. 770960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base((Expr*) 0); 7710aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType; 7711aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!Old->isImplicitAccess()) { 7712aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base = getDerived().TransformExpr(Old->getBase()); 7713aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 7714f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 77159138b4e96429cbaae00c52c15c960f72b6645088Richard Smith Base = getSema().PerformMemberExprBaseConversion(Base.take(), 77169138b4e96429cbaae00c52c15c960f72b6645088Richard Smith Old->isArrow()); 77179138b4e96429cbaae00c52c15c960f72b6645088Richard Smith if (Base.isInvalid()) 77189138b4e96429cbaae00c52c15c960f72b6645088Richard Smith return ExprError(); 77199138b4e96429cbaae00c52c15c960f72b6645088Richard Smith BaseType = Base.get()->getType(); 7720aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } else { 7721aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = getDerived().TransformType(Old->getBaseType()); 7722aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 7723129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 77244c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 77254c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (Old->getQualifierLoc()) { 77264c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor QualifierLoc 77274c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); 77284c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (!QualifierLoc) 7729f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7730129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 7731129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 77322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LookupResult R(SemaRef, Old->getMemberNameInfo(), 7733129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Sema::LookupOrdinaryName); 7734129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7735129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Transform all the decls. 7736129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), 7737129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall E = Old->decls_end(); I != E; ++I) { 77387c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor NamedDecl *InstD = static_cast<NamedDecl*>( 77397c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(Old->getMemberLoc(), 77407c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor *I)); 77419f54ad4381370c6b771424b53d219e661d6d6706John McCall if (!InstD) { 77429f54ad4381370c6b771424b53d219e661d6d6706John McCall // Silently ignore these if a UsingShadowDecl instantiated to nothing. 77439f54ad4381370c6b771424b53d219e661d6d6706John McCall // This can happen because of dependent hiding. 77449f54ad4381370c6b771424b53d219e661d6d6706John McCall if (isa<UsingShadowDecl>(*I)) 77459f54ad4381370c6b771424b53d219e661d6d6706John McCall continue; 774634f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis else { 774734f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis R.clear(); 7748f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 774934f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis } 77509f54ad4381370c6b771424b53d219e661d6d6706John McCall } 7751129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7752129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Expand using declarations. 7753129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (isa<UsingDecl>(InstD)) { 7754129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall UsingDecl *UD = cast<UsingDecl>(InstD); 7755129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall for (UsingDecl::shadow_iterator I = UD->shadow_begin(), 7756129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall E = UD->shadow_end(); I != E; ++I) 7757129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.addDecl(*I); 7758129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall continue; 7759129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 7760129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7761129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.addDecl(InstD); 7762129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 7763129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7764129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.resolveKind(); 7765129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7766c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor // Determine the naming class. 7767042d6f98ea73d781e43cc17077e8fc84a4201eefChandler Carruth if (Old->getNamingClass()) { 7768c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt CXXRecordDecl *NamingClass 7769c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( 777066c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getMemberLoc(), 777166c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNamingClass())); 777266c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor if (!NamingClass) 7773f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7774c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 777566c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor R.setNamingClass(NamingClass); 7776c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor } 7777c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7778129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TemplateArgumentListInfo TransArgs; 7779129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (Old->hasExplicitTemplateArgs()) { 7780129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TransArgs.setLAngleLoc(Old->getLAngleLoc()); 7781129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TransArgs.setRAngleLoc(Old->getRAngleLoc()); 7782fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), 7783fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor Old->getNumTemplateArgs(), 7784fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7785fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 7786129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 7787c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 7788c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // FIXME: to do this check properly, we will need to preserve the 7789c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // first-qualifier-in-scope here, just in case we had a dependent 7790c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // base (and therefore couldn't do the check) and a 7791c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // nested-name-qualifier (and therefore could do the lookup). 7792c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall NamedDecl *FirstQualifierInScope = 0; 7793c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 77949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildUnresolvedMemberExpr(Base.get(), 7795aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 7796129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Old->getOperatorLoc(), 7797129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Old->isArrow(), 77984c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor QualifierLoc, 7799c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall FirstQualifierInScope, 7800129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R, 7801129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall (Old->hasExplicitTemplateArgs() 7802129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall ? &TransArgs : 0)); 7803b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7804b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7805b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 780660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 78072e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlTreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { 7808eea06c609b73afc7bcfdf3e101efb8d9e7b3560cSean Hunt EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 78092e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); 78102e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl if (SubExpr.isInvalid()) 78112e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return ExprError(); 78122e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 78132e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) 78143fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 78152e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 78162e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); 78172e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl} 78182e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 78192e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redltemplate<typename Derived> 78202e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlExprResult 7821be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorTreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { 78224f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); 78234f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor if (Pattern.isInvalid()) 78244f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor return ExprError(); 78254f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor 78264f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) 78274f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor return SemaRef.Owned(E); 78284f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor 782967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), 783067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor E->getNumExpansions()); 7831be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor} 7832ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 7833ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregortemplate<typename Derived> 7834ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorExprResult 7835ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorTreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { 7836ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // If E is not value-dependent, then nothing will change when we transform it. 7837ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // Note: This is an instantiation-centric view. 7838ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor if (!E->isValueDependent()) 7839ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return SemaRef.Owned(E); 7840ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 7841ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // Note: None of the implementations of TryExpandParameterPacks can ever 7842ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // produce a diagnostic when given only a single unexpanded parameter pack, 7843ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // so 7844ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); 7845ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor bool ShouldExpand = false; 7846d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 7847cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions; 7848ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), 7849a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 7850d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ShouldExpand, RetainExpansion, 7851d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) 7852ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return ExprError(); 7853ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 7854089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor if (RetainExpansion) 7855ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return SemaRef.Owned(E); 7856089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor 7857089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor NamedDecl *Pack = E->getPack(); 7858089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor if (!ShouldExpand) { 7859089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(), 7860089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor Pack)); 7861089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor if (!Pack) 7862089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor return ExprError(); 7863089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor } 7864089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor 7865be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 7866ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // We now know the length of the parameter pack, so build a new expression 7867ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // that stores that length. 7868089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, 7869ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor E->getPackLoc(), E->getRParenLoc(), 7870089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor NumExpansions); 7871ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor} 7872ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 7873be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregortemplate<typename Derived> 7874be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorExprResult 7875c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorTreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( 7876c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor SubstNonTypeTemplateParmPackExpr *E) { 7877c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor // Default behavior is to do nothing with this transformation. 787891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return SemaRef.Owned(E); 787991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall} 788091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 788191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCalltemplate<typename Derived> 788291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallExprResult 788391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallTreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( 788491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall SubstNonTypeTemplateParmExpr *E) { 788591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall // Default behavior is to do nothing with this transformation. 7886c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor return SemaRef.Owned(E); 7887c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor} 7888c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor 7889c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregortemplate<typename Derived> 7890c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorExprResult 789103e80030515c800d1ab44125b9052dfffd1bd04cDouglas GregorTreeTransform<Derived>::TransformMaterializeTemporaryExpr( 789203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor MaterializeTemporaryExpr *E) { 789303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return getDerived().TransformExpr(E->GetTemporaryExpr()); 789403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor} 789503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 789603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregortemplate<typename Derived> 789703e80030515c800d1ab44125b9052dfffd1bd04cDouglas GregorExprResult 7898454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { 78993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7900b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7901b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 79021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 790360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7904454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { 790581d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *EncodedTypeInfo 790681d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor = getDerived().TransformType(E->getEncodedTypeSourceInfo()); 790781d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor if (!EncodedTypeInfo) 7908f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 79091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7910b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 791181d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedTypeInfo == E->getEncodedTypeSourceInfo()) 79123fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7913b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7914b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), 791581d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedTypeInfo, 7916b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 7917b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 79181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7919b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 7920f85e193739c953358c865005855253af4f68a497John McCallExprResult TreeTransform<Derived>:: 7921f85e193739c953358c865005855253af4f68a497John McCallTransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { 7922f85e193739c953358c865005855253af4f68a497John McCall ExprResult result = getDerived().TransformExpr(E->getSubExpr()); 7923f85e193739c953358c865005855253af4f68a497John McCall if (result.isInvalid()) return ExprError(); 7924f85e193739c953358c865005855253af4f68a497John McCall Expr *subExpr = result.take(); 7925f85e193739c953358c865005855253af4f68a497John McCall 7926f85e193739c953358c865005855253af4f68a497John McCall if (!getDerived().AlwaysRebuild() && 7927f85e193739c953358c865005855253af4f68a497John McCall subExpr == E->getSubExpr()) 7928f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(E); 7929f85e193739c953358c865005855253af4f68a497John McCall 7930f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(new(SemaRef.Context) 7931f85e193739c953358c865005855253af4f68a497John McCall ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy())); 7932f85e193739c953358c865005855253af4f68a497John McCall} 7933f85e193739c953358c865005855253af4f68a497John McCall 7934f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived> 7935f85e193739c953358c865005855253af4f68a497John McCallExprResult TreeTransform<Derived>:: 7936f85e193739c953358c865005855253af4f68a497John McCallTransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { 7937f85e193739c953358c865005855253af4f68a497John McCall TypeSourceInfo *TSInfo 7938f85e193739c953358c865005855253af4f68a497John McCall = getDerived().TransformType(E->getTypeInfoAsWritten()); 7939f85e193739c953358c865005855253af4f68a497John McCall if (!TSInfo) 7940f85e193739c953358c865005855253af4f68a497John McCall return ExprError(); 7941f85e193739c953358c865005855253af4f68a497John McCall 7942f85e193739c953358c865005855253af4f68a497John McCall ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); 7943f85e193739c953358c865005855253af4f68a497John McCall if (Result.isInvalid()) 7944f85e193739c953358c865005855253af4f68a497John McCall return ExprError(); 7945f85e193739c953358c865005855253af4f68a497John McCall 7946f85e193739c953358c865005855253af4f68a497John McCall if (!getDerived().AlwaysRebuild() && 7947f85e193739c953358c865005855253af4f68a497John McCall TSInfo == E->getTypeInfoAsWritten() && 7948f85e193739c953358c865005855253af4f68a497John McCall Result.get() == E->getSubExpr()) 7949f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(E); 7950f85e193739c953358c865005855253af4f68a497John McCall 7951f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), 7952f85e193739c953358c865005855253af4f68a497John McCall E->getBridgeKeywordLoc(), TSInfo, 7953f85e193739c953358c865005855253af4f68a497John McCall Result.get()); 7954f85e193739c953358c865005855253af4f68a497John McCall} 7955f85e193739c953358c865005855253af4f68a497John McCall 7956f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived> 795760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7958454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { 795992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Transform arguments. 796092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor bool ArgChanged = false; 7961ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 7962aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args.reserve(E->getNumArgs()); 7963aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, 7964aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgChanged)) 7965aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 7966aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 796792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (E->getReceiverKind() == ObjCMessageExpr::Class) { 796892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Class message: transform the receiver type. 796992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor TypeSourceInfo *ReceiverTypeInfo 797092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor = getDerived().TransformType(E->getClassReceiverTypeInfo()); 797192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!ReceiverTypeInfo) 7972f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7973c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 797492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // If nothing changed, just retain the existing message send. 797592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!getDerived().AlwaysRebuild() && 797692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) 797792be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 797892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 797992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Build a new class message send. 7980207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SmallVector<SourceLocation, 16> SelLocs; 7981207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis E->getSelectorLocs(SelLocs); 798292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, 798392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getSelector(), 7984207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocs, 798592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getMethodDecl(), 798692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getLeftLoc(), 798792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor move_arg(Args), 798892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getRightLoc()); 798992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 799092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 799192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Instance message: transform the receiver 799292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor assert(E->getReceiverKind() == ObjCMessageExpr::Instance && 799392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor "Only class and instance messages may be instantiated"); 799460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Receiver 799592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor = getDerived().TransformExpr(E->getInstanceReceiver()); 799692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (Receiver.isInvalid()) 7997f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 799892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 799992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // If nothing changed, just retain the existing message send. 800092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!getDerived().AlwaysRebuild() && 800192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Receiver.get() == E->getInstanceReceiver() && !ArgChanged) 800292be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 8003c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 800492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Build a new instance message send. 8005207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SmallVector<SourceLocation, 16> SelLocs; 8006207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis E->getSelectorLocs(SelLocs); 80079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCMessageExpr(Receiver.get(), 800892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getSelector(), 8009207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocs, 801092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getMethodDecl(), 801192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getLeftLoc(), 801292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor move_arg(Args), 801392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getRightLoc()); 8014b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8015b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 80161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 801760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8018454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { 80193fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8020b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8021b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 80221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 802360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8024454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { 80253fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8026b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8027b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 80281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 802960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8030454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { 8031f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // Transform the base expression. 803260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 8033f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Base.isInvalid()) 8034f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8035f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor 8036f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // We don't need to transform the ivar; it will never change. 8037c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8038f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // If nothing changed, just retain the existing expression. 8039f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (!getDerived().AlwaysRebuild() && 8040f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Base.get() == E->getBase()) 80413fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8042c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 80439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), 8044f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->getLocation(), 8045f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->isArrow(), E->isFreeIvar()); 8046b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8047b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 80481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 804960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8050454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { 805112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // 'super' and types never change. Property never changes. Just 805212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // retain the existing expression. 805312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (!E->isObjectReceiver()) 80543fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 80558ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian 8056e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // Transform the base expression. 805760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 8058e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (Base.isInvalid()) 8059f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8060c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8061e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // We don't need to transform the property; it will never change. 8062c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8063e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // If nothing changed, just retain the existing expression. 8064e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (!getDerived().AlwaysRebuild() && 8065e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor Base.get() == E->getBase()) 80663fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8067b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 806812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (E->isExplicitProperty()) 806912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getDerived().RebuildObjCPropertyRefExpr(Base.get(), 807012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getExplicitProperty(), 807112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getLocation()); 807212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 807312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getDerived().RebuildObjCPropertyRefExpr(Base.get(), 80743c3b7f90a863af43fa63043d396553ecf205351cJohn McCall SemaRef.Context.PseudoObjectTy, 807512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getImplicitPropertyGetter(), 807612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getImplicitPropertySetter(), 807712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getLocation()); 8078b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8079b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 80801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 808160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8082454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { 8083f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // Transform the base expression. 808460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 8085f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Base.isInvalid()) 8086f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8087c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8088f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // If nothing changed, just retain the existing expression. 8089f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (!getDerived().AlwaysRebuild() && 8090f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Base.get() == E->getBase()) 80913fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8092c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 80939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), 8094f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->isArrow()); 8095b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8096b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 80971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 809860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8099454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { 8100b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 8101ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> SubExprs(SemaRef); 8102aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor SubExprs.reserve(E->getNumSubExprs()); 8103aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, 8104aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor SubExprs, &ArgumentChanged)) 8105aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 81061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8107b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 8108b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgumentChanged) 81093fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 81101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8111b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), 8112b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(SubExprs), 8113b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 8114b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8115b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 81161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 811760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8118454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { 8119c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall BlockDecl *oldBlock = E->getBlockDecl(); 8120a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 8121c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); 8122c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall BlockScopeInfo *blockScope = SemaRef.getCurBlock(); 8123c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 8124c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); 81250586520acb2f368c874943353a222be7f00c3068Fariborz Jahanian blockScope->TheDecl->setBlockMissingReturnType( 81260586520acb2f368c874943353a222be7f00c3068Fariborz Jahanian oldBlock->blockMissingReturnType()); 8127ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian 8128686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<ParmVarDecl*, 4> params; 8129686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<QualType, 4> paramTypes; 8130a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 8131a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian // Parameter substitution. 8132c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), 8133c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldBlock->param_begin(), 8134c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldBlock->param_size(), 813500b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis 0, paramTypes, ¶ms)) { 813600b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); 813792be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return ExprError(); 813800b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis } 8139c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 8140c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall const FunctionType *exprFunctionType = E->getFunctionType(); 8141c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall QualType exprResultType = exprFunctionType->getResultType(); 8142c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (!exprResultType.isNull()) { 8143c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (!exprResultType->isDependentType()) 8144c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->ReturnType = exprResultType; 8145c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall else if (exprResultType != getSema().Context.DependentTy) 8146c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->ReturnType = getDerived().TransformType(exprResultType); 8147a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian } 8148a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 8149a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // If the return type has not been determined yet, leave it as a dependent 8150a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // type; it'll get set when we process the body. 8151c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (blockScope->ReturnType.isNull()) 8152c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->ReturnType = getSema().Context.DependentTy; 8153a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 8154a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // Don't allow returning a objc interface by value. 8155c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (blockScope->ReturnType->isObjCObjectType()) { 8156c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall getSema().Diag(E->getCaretLocation(), 8157a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor diag::err_object_cannot_be_passed_returned_by_value) 8158c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall << 0 << blockScope->ReturnType; 815900b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); 8160a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor return ExprError(); 8161a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor } 8162711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 8163c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall QualType functionType = getDerived().RebuildFunctionProtoType( 8164c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->ReturnType, 8165c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall paramTypes.data(), 8166c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall paramTypes.size(), 8167c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldBlock->isVariadic(), 8168c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 0, RQ_None, 8169c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall exprFunctionType->getExtInfo()); 8170c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->FunctionType = functionType; 8171711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 8172711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Set the parameters on the block decl. 8173c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (!params.empty()) 81744278c654b645402554eb52a48e9c7097c9f1233aDavid Blaikie blockScope->TheDecl->setParams(params); 8175a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 8176a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // If the return type wasn't explicitly set, it will have been marked as a 8177a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // dependent type (DependentTy); clear out the return type setting so 8178a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // we will deduce the return type when type-checking the block's body. 8179c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (blockScope->ReturnType == getSema().Context.DependentTy) 8180c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->ReturnType = QualType(); 8181a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 8182711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Transform the body 8183c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall StmtResult body = getDerived().TransformStmt(E->getBody()); 818400b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis if (body.isInvalid()) { 818500b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); 8186711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return ExprError(); 818700b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis } 8188711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 8189c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#ifndef NDEBUG 8190c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall // In builds with assertions, make sure that we captured everything we 8191c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall // captured before. 8192fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor if (!SemaRef.getDiagnostics().hasErrorOccurred()) { 8193fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), 8194fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor e = oldBlock->capture_end(); i != e; ++i) { 8195fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor VarDecl *oldCapture = i->getVariable(); 8196fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor 8197fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor // Ignore parameter packs. 8198fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor if (isa<ParmVarDecl>(oldCapture) && 8199fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor cast<ParmVarDecl>(oldCapture)->isParameterPack()) 8200fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor continue; 8201c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 8202fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor VarDecl *newCapture = 8203fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), 8204fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor oldCapture)); 8205fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor assert(blockScope->CaptureMap.count(newCapture)); 8206fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor } 8207c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall } 8208c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#endif 8209c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 8210c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), 8211c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall /*Scope=*/0); 8212b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8213b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 82141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 821560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8216454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { 8217a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian ValueDecl *ND 8218a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), 8219a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian E->getDecl())); 8220a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian if (!ND) 8221f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 82222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 8223a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian if (!getDerived().AlwaysRebuild() && 8224a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian ND == E->getDecl()) { 8225a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian // Mark it referenced in the new context regardless. 8226a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian // FIXME: this is a bit instantiation-specific. 8227a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); 8228a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 82293fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8230a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian } 8231a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 82322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation()); 823340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(), 82342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ND, NameInfo, 0); 8235b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 82361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 823761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnertemplate<typename Derived> 823861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya LattnerExprResult 823961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya LattnerTreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { 8240b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Cannot transform asType expressions yet"); 824161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner} 8242276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 8243276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmantemplate<typename Derived> 8244276b061970939293f1abaf694bd3ef05b2cbda79Eli FriedmanExprResult 8245276b061970939293f1abaf694bd3ef05b2cbda79Eli FriedmanTreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { 8246dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman QualType RetTy = getDerived().TransformType(E->getType()); 8247dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman bool ArgumentChanged = false; 8248dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ASTOwningVector<Expr*> SubExprs(SemaRef); 8249dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman SubExprs.reserve(E->getNumSubExprs()); 8250dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, 8251dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman SubExprs, &ArgumentChanged)) 8252dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman return ExprError(); 8253dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 8254dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (!getDerived().AlwaysRebuild() && 8255dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman !ArgumentChanged) 8256dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman return SemaRef.Owned(E); 8257dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 8258dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs), 8259dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman RetTy, E->getOp(), E->getRParenLoc()); 8260276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman} 826161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 8262b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===// 8263b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Type reconstruction 8264b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===// 8265b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 82661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 826785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, 826885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Star) { 82692865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildPointerType(PointeeType, Star, 8270b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor getDerived().getBaseEntity()); 8271b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8272b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 82731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 827485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, 827585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Star) { 82762865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildBlockPointerType(PointeeType, Star, 8277b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor getDerived().getBaseEntity()); 8278b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8279b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 82801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 82811eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 828285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, 828385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall bool WrittenAsLValue, 828485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil) { 82852865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, 828685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Sigil, getDerived().getBaseEntity()); 8287b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8288b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 82891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 82901eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 829185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, 829285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType ClassType, 829385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil) { 82942865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildMemberPointerType(PointeeType, ClassType, 829585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Sigil, getDerived().getBaseEntity()); 8296577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8297577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8298577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 82991eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 8300577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorTreeTransform<Derived>::RebuildArrayType(QualType ElementType, 8301577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 8302577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt *Size, 8303577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Expr *SizeExpr, 8304577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 8305577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 8306577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (SizeExpr || !Size) 8307577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, 8308577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange, 8309577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor getDerived().getBaseEntity()); 83101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 83111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Types[] = { 83121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, 83131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, 83141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty 8315577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor }; 8316577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const unsigned NumTypes = sizeof(Types) / sizeof(QualType); 8317577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType SizeType; 8318577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor for (unsigned I = 0; I != NumTypes; ++I) 8319577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { 8320577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SizeType = Types[I]; 8321577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor break; 8322577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 83231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 83249996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType, 83259996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /*FIXME*/BracketsRange.getBegin()); 83261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, 8327577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange, 83281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getDerived().getBaseEntity()); 8329577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 83301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8331577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 83321eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 83331eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, 8334577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 8335577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt &Size, 833685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 833785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange) { 83381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, 833985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall IndexTypeQuals, BracketsRange); 8340577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8341577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8342577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 83431eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 83441eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, 8345577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 834685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 834785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange) { 83481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, 834985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall IndexTypeQuals, BracketsRange); 8350577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 83511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8352577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 83531eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 83541eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, 8355577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 83569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 8357577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 8358577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 83591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 83609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SizeExpr, 8361577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange); 8362577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8363577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8364577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 83651eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 83661eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, 8367577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 83689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 8369577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 8370577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 83711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 83729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SizeExpr, 8373577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange); 8374577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8375577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8376577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8377577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, 8378e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson unsigned NumElements, 8379e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::VectorKind VecKind) { 8380577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor // FIXME: semantic checking! 8381e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); 8382577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 83831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8384577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8385577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, 8386577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumElements, 8387577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc) { 8388577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), 8389577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor NumElements, true); 8390577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IntegerLiteral *VectorSize 83919996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, 83929996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis AttributeLoc); 83939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); 8394577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 83951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8396577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 83971eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 83981eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, 83999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 8400577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc) { 84019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); 8402577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 84031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8404577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8405577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, 84061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType *ParamTypes, 8407577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumParamTypes, 84081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool Variadic, 8409fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman unsigned Quals, 8410c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind RefQualifier, 8411fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman const FunctionType::ExtInfo &Info) { 84121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, 8413c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor Quals, RefQualifier, 8414577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor getDerived().getBaseLocation(), 8415fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman getDerived().getBaseEntity(), 8416fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman Info); 8417577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 84181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8419577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8420a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { 8421a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return SemaRef.Context.getFunctionNoProtoType(T); 8422a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 8423a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 8424a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 8425ed97649e9574b9d854fa4d6109c9333ae0993554John McCallQualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { 8426ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(D && "no decl found"); 8427ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (D->isInvalidDecl()) return QualType(); 8428ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 842992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // FIXME: Doesn't account for ObjCInterfaceDecl! 8430ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TypeDecl *Ty; 8431ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (isa<UsingDecl>(D)) { 8432ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UsingDecl *Using = cast<UsingDecl>(D); 8433ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(Using->isTypeName() && 8434ed97649e9574b9d854fa4d6109c9333ae0993554John McCall "UnresolvedUsingTypenameDecl transformed to non-typename using"); 8435ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 8436ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // A valid resolved using typename decl points to exactly one type decl. 8437ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(++Using->shadow_begin() == Using->shadow_end()); 8438ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); 8439c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8440ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } else { 8441ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(isa<UnresolvedUsingTypenameDecl>(D) && 8442ed97649e9574b9d854fa4d6109c9333ae0993554John McCall "UnresolvedUsingTypenameDecl transformed to non-using decl"); 8443ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Ty = cast<UnresolvedUsingTypenameDecl>(D); 8444ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 8445ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 8446ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return SemaRef.Context.getTypeDeclType(Ty); 8447ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 8448ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 8449ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> 84502a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, 84512a984cad5ac3fdceeff2bd99daa7b90979313475John McCall SourceLocation Loc) { 84522a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return SemaRef.BuildTypeofExprType(E, Loc); 8453577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8454577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8455577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8456577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { 8457577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeOfType(Underlying); 8458577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8459577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8460577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 84612a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, 84622a984cad5ac3fdceeff2bd99daa7b90979313475John McCall SourceLocation Loc) { 84632a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return SemaRef.BuildDecltypeType(E, Loc); 8464577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8465577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8466577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8467ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, 8468ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType::UTTKind UKind, 8469ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt SourceLocation Loc) { 8470ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); 8471ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt} 8472ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 8473ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunttemplate<typename Derived> 8474577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTemplateSpecializationType( 8475833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateName Template, 8476833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation TemplateNameLoc, 847767714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor TemplateArgumentListInfo &TemplateArgs) { 8478d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); 8479577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 84801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8481dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived> 8482b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli FriedmanQualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, 8483b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman SourceLocation KWLoc) { 8484b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return SemaRef.BuildAtomicType(ValueType, KWLoc); 8485b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman} 8486b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 8487b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmantemplate<typename Derived> 84881eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 8489fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 8490d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor bool TemplateKW, 8491d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TemplateDecl *Template) { 8492fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, 8493d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor Template); 8494d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor} 8495d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor 8496d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived> 84971eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 8498fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 8499fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor const IdentifierInfo &Name, 8500fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 850143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 850243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope) { 8503fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor UnqualifiedId TemplateName; 8504fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName.setIdentifier(&Name, NameLoc); 8505d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Sema::TemplateTy Template; 8506d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor getSema().ActOnDependentTemplateName(/*Scope=*/0, 8507fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /*FIXME:*/SourceLocation(), 8508d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor SS, 8509fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName, 8510b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType::make(ObjectType), 8511d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor /*EnteringContext=*/false, 8512d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Template); 851343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return Template.get(); 8514d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor} 85151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8516b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 8517ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTemplateName 8518fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 8519ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor OverloadedOperatorKind Operator, 8520fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 8521ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor QualType ObjectType) { 8522ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId Name; 8523fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor // FIXME: Bogus location information. 8524fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; 8525fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); 8526d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Sema::TemplateTy Template; 8527d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor getSema().ActOnDependentTemplateName(/*Scope=*/0, 8528fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /*FIXME:*/SourceLocation(), 8529d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor SS, 8530d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Name, 8531b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType::make(ObjectType), 8532d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor /*EnteringContext=*/false, 8533d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Template); 8534d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor return Template.template getAsVal<TemplateName>(); 8535ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor} 8536c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8537ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregortemplate<typename Derived> 853860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8539b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, 8540b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 85419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *OrigCallee, 85429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *First, 85439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Second) { 85449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Callee = OrigCallee->IgnoreParenCasts(); 85459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); 85461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8547b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Determine whether this should be a builtin operation. 8548f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl if (Op == OO_Subscript) { 85499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType() && 85509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall !Second->getType()->isOverloadableType()) 85519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().CreateBuiltinArraySubscriptExpr(First, 85529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Callee->getLocStart(), 85539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Second, OpLoc); 85541a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman } else if (Op == OO_Arrow) { 85551a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman // -> is never a builtin operation. 85569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); 85579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall } else if (Second == 0 || isPostIncDec) { 85589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType()) { 8559b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // The argument is not of overloadable type, so try to create a 8560b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // built-in unary operation. 85612de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc 8562b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); 85631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 85649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); 8565b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 8566b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } else { 85679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType() && 85689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall !Second->getType()->isOverloadableType()) { 8569b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Neither of the arguments is an overloadable type, so try to 8570b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // create a built-in binary operation. 85712de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 857260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 85739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); 8574b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 8575f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 85761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8577b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return move(Result); 8578b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 8579b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 85801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 85811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Compute the transformed set of functions (and function templates) to be 8582b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // used during overload resolution. 85836e26689f5d513e24ad7783a4493201930fdeccc0John McCall UnresolvedSet<16> Functions; 85841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 85859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { 8586ba13543329afac4a0d01304ec2ec4924d99306a6John McCall assert(ULE->requiresADL()); 8587ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 8588ba13543329afac4a0d01304ec2ec4924d99306a6John McCall // FIXME: Do we have to check 8589ba13543329afac4a0d01304ec2ec4924d99306a6John McCall // IsAcceptableNonMemberOperatorCandidate for each of these? 85906e26689f5d513e24ad7783a4493201930fdeccc0John McCall Functions.append(ULE->decls_begin(), ULE->decls_end()); 8591ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } else { 85929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl()); 8593ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } 85941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8595b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Add any functions found via argument-dependent lookup. 85969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Args[2] = { First, Second }; 85979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall unsigned NumArgs = 1 + (Second != 0); 85981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8599b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Create the overloaded operator invocation for unary operators. 8600b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (NumArgs == 1 || isPostIncDec) { 86012de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc 8602b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); 86039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); 8604b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 86051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 86065b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor if (Op == OO_Subscript) { 86075b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor SourceLocation LBrace; 86085b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor SourceLocation RBrace; 86095b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor 86105b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { 86115b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo(); 86125b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor LBrace = SourceLocation::getFromRawEncoding( 86135b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor NameLoc.CXXOperatorName.BeginOpNameLoc); 86145b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor RBrace = SourceLocation::getFromRawEncoding( 86155b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor NameLoc.CXXOperatorName.EndOpNameLoc); 86165b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor } else { 86175b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor LBrace = Callee->getLocStart(); 86185b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor RBrace = OpLoc; 86195b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor } 86205b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor 86215b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, 86225b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor First, Second); 86235b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor } 8624f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl 8625b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Create the overloaded operator invocation for binary operators. 86262de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 862760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 8628b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); 8629b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 8630f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 86311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 86321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return move(Result); 8633b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 86341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 863526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregortemplate<typename Derived> 863660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 86379ae2f076ca5ab1feb3ba95629099ec2319833701John McCallTreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, 863826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SourceLocation OperatorLoc, 863926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor bool isArrow, 8640f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor CXXScopeSpec &SS, 864126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor TypeSourceInfo *ScopeType, 864226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SourceLocation CCLoc, 8643fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SourceLocation TildeLoc, 8644a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed) { 86459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall QualType BaseType = Base->getType(); 86469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (Base->isTypeDependent() || Destroyed.getIdentifier() || 864726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor (!isArrow && !BaseType->getAs<RecordType>()) || 8648c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt (isArrow && BaseType->getAs<PointerType>() && 8649bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif !BaseType->getAs<PointerType>()->getPointeeType() 8650bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif ->template getAs<RecordType>())){ 865126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor // This pseudo-destructor expression is still a pseudo-destructor. 86529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, 865326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor isArrow? tok::arrow : tok::period, 8654fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SS, ScopeType, CCLoc, TildeLoc, 8655a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed, 865626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /*FIXME?*/true); 865726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor } 86582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 8659a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); 86602577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( 86612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SemaRef.Context.getCanonicalType(DestroyedType->getType()))); 86622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); 86632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.setNamedTypeInfo(DestroyedType); 86642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 866526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor // FIXME: the ScopeType should be tacked onto SS. 86662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 86679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, BaseType, 866826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor OperatorLoc, isArrow, 866926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SS, /*FIXME: FirstQualifier*/ 0, 86702577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 867126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /*TemplateArgs*/ 0); 867226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor} 867326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor 8674577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} // end namespace clang 8675577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8676577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H 8677