TreeTransform.h revision 9d9922af13edf3ddf8804a41a98d997324fdd58e
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, 421e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 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, 1467e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 1468f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const DeclarationNameInfo &MemberNameInfo, 1469f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ValueDecl *Member, 1470f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall NamedDecl *FoundDecl, 1471d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *ExplicitTemplateArgs, 1472f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall NamedDecl *FirstQualifierInScope) { 14739138b4e96429cbaae00c52c15c960f72b6645088Richard Smith ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, 14749138b4e96429cbaae00c52c15c960f72b6645088Richard Smith isArrow); 1475d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson if (!Member->getDeclName()) { 1476f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // We have a reference to an unnamed field. This is always the 1477f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // base of an anonymous struct/union member access, i.e. the 1478f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // field is always of record type. 147940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); 1480f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall assert(Member->getType()->isRecordType() && 1481f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall "unnamed member not of record type?"); 14821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14839138b4e96429cbaae00c52c15c960f72b6645088Richard Smith BaseResult = 14849138b4e96429cbaae00c52c15c960f72b6645088Richard Smith getSema().PerformObjectMemberConversion(BaseResult.take(), 1485429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley QualifierLoc.getNestedNameSpecifier(), 1486429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley FoundDecl, Member); 1487429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (BaseResult.isInvalid()) 1488f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 1489429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley Base = BaseResult.take(); 1490f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); 14911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump MemberExpr *ME = 14929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall new (getSema().Context) MemberExpr(Base, isArrow, 14932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Member, MemberNameInfo, 1494f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall cast<FieldDecl>(Member)->getType(), 1495f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall VK, OK_Ordinary); 1496d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson return getSema().Owned(ME); 1497d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson } 14981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 149983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor CXXScopeSpec SS; 150040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor SS.Adopt(QualifierLoc); 150183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 1502429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley Base = BaseResult.take(); 15039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall QualType BaseType = Base->getType(); 1504aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 15056bb8017bb9e828d118e15e59d71c66bba323c364John McCall // FIXME: this involves duplicating earlier analysis in a lot of 15066bb8017bb9e828d118e15e59d71c66bba323c364John McCall // cases; we should avoid this when possible. 15072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); 15086bb8017bb9e828d118e15e59d71c66bba323c364John McCall R.addDecl(FoundDecl); 1509c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R.resolveKind(); 1510c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 15119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, 1512e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, TemplateKWLoc, 1513e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara FirstQualifierInScope, 1514c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R, ExplicitTemplateArgs); 1515b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1517b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new binary operator expression. 15181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1519b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1520b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 152160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildBinaryOperator(SourceLocation OpLoc, 15222de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc, 15239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *LHS, Expr *RHS) { 15249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); 1525b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1526b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1527b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new conditional operator expression. 15281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1529b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1530b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 153160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildConditionalOperator(Expr *Cond, 153256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation QuestionLoc, 153356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *LHS, 153456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation ColonLoc, 153556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *RHS) { 15369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, 15379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS, RHS); 1538b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1539b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1540b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C-style cast expression. 15411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1542b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1543b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 154460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, 15459d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1546b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc, 15479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr) { 1548b042fdfc9460e0018276412257e3c3226f9ea96eJohn McCall return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, 15499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr); 1550b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1552b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new compound literal expression. 15531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1554b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1555b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 155660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, 155742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *TInfo, 1558b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc, 15599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Init) { 156042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, 15619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init); 1562b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1564b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new extended vector element access expression. 15651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1566b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1567b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 156860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildExtVectorElementExpr(Expr *Base, 1569b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 1570b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation AccessorLoc, 1571b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor IdentifierInfo &Accessor) { 1572aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 1573129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall CXXScopeSpec SS; 15742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); 15759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, Base->getType(), 1576129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall OpLoc, /*IsArrow*/ false, 1577e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, SourceLocation(), 1578e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /*FirstQualifierInScope*/ 0, 15792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 1580129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /* TemplateArgs */ 0); 1581b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1583b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new initializer list expression. 15841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1585b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1586b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 158760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildInitList(SourceLocation LBraceLoc, 1588c8fc90a854b4ccba21c85884676a80334159dd94John McCall MultiExprArg Inits, 1589c8fc90a854b4ccba21c85884676a80334159dd94John McCall SourceLocation RBraceLoc, 1590c8fc90a854b4ccba21c85884676a80334159dd94John McCall QualType ResultTy) { 159160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 1592e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); 1593e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor if (Result.isInvalid() || ResultTy->isDependentType()) 1594e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor return move(Result); 1595c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1596e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor // Patch in the result type we were given, which may have been computed 1597e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor // when the initial InitListExpr was built. 1598e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); 1599e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor ILE->setType(ResultTy); 1600e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor return move(Result); 1601b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1603b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new designated initializer expression. 16041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1605b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1606b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 160760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildDesignatedInitExpr(Designation &Desig, 1608b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg ArrayExprs, 1609b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation EqualOrColonLoc, 1610b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool GNUSyntax, 16119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Init) { 161260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 1613b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, 16149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init); 1615b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 1616f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 16171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1618b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.release(); 1619b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return move(Result); 1620b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1622b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new value-initialized expression. 16231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1624b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds the implicit value initialization without performing 1625b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// any semantic analysis. Subclasses may override this routine to provide 1626b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// different behavior. 162760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildImplicitValueInitExpr(QualType T) { 1628b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); 1629b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1631b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new \c va_arg expression. 16321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1633b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1634b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 163560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, 16369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, TypeSourceInfo *TInfo, 16372cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara SourceLocation RParenLoc) { 16382cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara return getSema().BuildVAArgExpr(BuiltinLoc, 16399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, TInfo, 16402cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara RParenLoc); 1641b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1642b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1643b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression list in parentheses. 16441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1645b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1646b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 164760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildParenListExpr(SourceLocation LParenLoc, 1648b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg SubExprs, 1649b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1650c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, 1651f88f7ab5adaa11d050270ffee6aa871e855f83b8Fariborz Jahanian move(SubExprs)); 1652b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1654b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new address-of-label expression. 16551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 16561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, performs semantic analysis, using the name of the label 1657b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// rather than attempting to map the label statement itself. 1658b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 165960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, 1660ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation LabelLoc, LabelDecl *Label) { 166157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); 1662b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1664b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new GNU statement expression. 16651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1666b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1667b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 166860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildStmtExpr(SourceLocation LParenLoc, 16699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *SubStmt, 1670b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 16719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); 1672b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1674b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new __builtin_choose_expr expression. 1675b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1677b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 167860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, 16799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Cond, Expr *LHS, Expr *RHS, 1680b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.ActOnChooseExpr(BuiltinLoc, 16829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond, LHS, RHS, 1683b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 1684b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1686f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// \brief Build a new generic selection expression. 1687f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// 1688f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// By default, performs semantic analysis to build the new expression. 1689f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// Subclasses may override this routine to provide different behavior. 1690f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, 1691f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation DefaultLoc, 1692f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 1693f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *ControllingExpr, 1694f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **Types, 1695f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr **Exprs, 1696f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs) { 1697f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, 1698f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ControllingExpr, Types, Exprs, 1699f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne NumAssocs); 1700f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 1701f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 1702b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new overloaded operator call expression. 1703b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1704b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1705b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// The semantic analysis provides the behavior of template instantiation, 1706b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// copying with transformations that turn what looks like an overloaded 17071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// operator call into a use of a builtin operator, performing 1708b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// argument-dependent lookup, etc. Subclasses may override this routine to 1709b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// provide different behavior. 171060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, 1711b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 17129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Callee, 17139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *First, 17149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Second); 17151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new C++ "named" cast expression, such as static_cast or 1717b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// reinterpret_cast. 1718b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1719b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, this routine dispatches to one of the more-specific routines 17201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). 1721b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 172260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, 1723b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Stmt::StmtClass Class, 1724b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 17259d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1726b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1727b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 17289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1729b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1730b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor switch (Class) { 1731b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXStaticCastExprClass: 17329d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, 17331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 1735b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1736b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXDynamicCastExprClass: 17379d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, 17381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 17401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1741b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXReinterpretCastExprClass: 17429d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, 17431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, 1745b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 17461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1747b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXConstCastExprClass: 17489d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, 17491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 17511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1752b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor default: 1753b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Invalid C++ named cast"); 1754b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1756f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 1757b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1759b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ static_cast expression. 1760b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1761b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1762b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 176360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, 1764b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 17659d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1766b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1767b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 17689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1769b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1770c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, 17719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1772c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1773c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1774b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1775b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1776b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ dynamic_cast expression. 1777b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1778b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1779b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 178060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, 1781b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 17829d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1783b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1784b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 17859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1786b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1787c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, 17889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1789c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1790c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1791b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1792b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1793b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ reinterpret_cast expression. 1794b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1795b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1796b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 179760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, 1798b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 17999d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1800b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1801b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 18029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1803b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1804c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, 18059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1806c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1807c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1808b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1809b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1810b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ const_cast expression. 1811b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1812b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1813b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 181460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, 1815b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 18169d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1817b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1818b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 18199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1820b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1821c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, 18229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1823c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1824c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1825b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1827b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ functional-style cast expression. 1828b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1829b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1830b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1831ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, 1832ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 1833ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor Expr *Sub, 1834ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 1835ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, 1836f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiExprArg(&Sub, 1), 1837b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 1838b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1840b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ typeid(type) expression. 1841b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1842b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1843b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 184460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, 184557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor SourceLocation TypeidLoc, 184657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TypeSourceInfo *Operand, 1847b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1848c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, 184957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor RParenLoc); 1850b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 185201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 1853b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ typeid(expr) expression. 1854b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1855b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1856b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 185760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, 185857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor SourceLocation TypeidLoc, 18599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand, 1860b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 18619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, 186257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor RParenLoc); 18631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 18641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 186501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Build a new C++ __uuidof(type) expression. 186601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// 186701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// By default, performs semantic analysis to build the new expression. 186801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// Subclasses may override this routine to provide different behavior. 186901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, 187001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation TypeidLoc, 187101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TypeSourceInfo *Operand, 187201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation RParenLoc) { 187301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, 187401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet RParenLoc); 187501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 187601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 187701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Build a new C++ __uuidof(expr) expression. 187801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// 187901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// By default, performs semantic analysis to build the new expression. 188001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// Subclasses may override this routine to provide different behavior. 188101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, 188201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation TypeidLoc, 188301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Expr *Operand, 188401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation RParenLoc) { 188501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, 188601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet RParenLoc); 188701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 188801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 1889b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "this" expression. 1890b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1891b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds a new "this" expression without performing any 18921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// semantic analysis. Subclasses may override this routine to provide 1893b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// different behavior. 189460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, 1895ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor QualType ThisType, 1896ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor bool isImplicit) { 1897b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman getSema().CheckCXXThisCapture(ThisLoc); 1898b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getSema().Owned( 1899828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, 1900828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor isImplicit)); 1901b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1902b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1903b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ throw expression. 1904b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1905b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1906b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1907bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, 1908bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor bool IsThrownVariableInScope) { 1909bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); 1910b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1911b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1912b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ default-argument expression. 1913b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1914b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds a new default-argument expression, which does not 1915b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// require any semantic analysis. Subclasses may override this routine to 1916b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// provide different behavior. 191760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, 1918036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor ParmVarDecl *Param) { 1919036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, 1920036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor Param)); 1921b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1922b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1923b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ zero-initialization expression. 1924b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1925b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1926b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1927ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, 1928ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 1929ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 1930ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, 19311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump MultiExprArg(getSema(), 0, 0), 1932ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor RParenLoc); 1933b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 19341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1935b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "new" expression. 1936b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1937b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1938b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 193960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, 19401bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor bool UseGlobal, 19411bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation PlacementLParen, 19421bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor MultiExprArg PlacementArgs, 19431bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation PlacementRParen, 19441bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceRange TypeIdParens, 19451bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor QualType AllocatedType, 19461bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *AllocatedTypeInfo, 19471bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor Expr *ArraySize, 19481bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation ConstructorLParen, 19491bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor MultiExprArg ConstructorArgs, 19501bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation ConstructorRParen) { 19511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getSema().BuildCXXNew(StartLoc, UseGlobal, 1952b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor PlacementLParen, 1953b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(PlacementArgs), 1954b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor PlacementRParen, 19554bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor TypeIdParens, 19561bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocatedType, 19571bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocatedTypeInfo, 19589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ArraySize, 1959b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ConstructorLParen, 1960b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(ConstructorArgs), 1961b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ConstructorRParen); 1962b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 19631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1964b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "delete" expression. 1965b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1966b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1967b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 196860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, 1969b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool IsGlobalDelete, 1970b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool IsArrayForm, 19719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand) { 1972b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, 19739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Operand); 1974b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 19751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1976b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new unary type trait expression. 1977b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1978b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1979b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 198060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, 19813d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor SourceLocation StartLoc, 19823d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *T, 19833d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor SourceLocation RParenLoc) { 19843d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); 1985b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1986b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 19876ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// \brief Build a new binary type trait expression. 19886ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// 19896ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// By default, performs semantic analysis to build the new expression. 19906ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// Subclasses may override this routine to provide different behavior. 19916ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, 19926ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation StartLoc, 19936ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *LhsT, 19946ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *RhsT, 19956ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation RParenLoc) { 19966ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); 19976ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 19986ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 199921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// \brief Build a new array type trait expression. 200021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// 200121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// By default, performs semantic analysis to build the new expression. 200221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// Subclasses may override this routine to provide different behavior. 200321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, 200421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SourceLocation StartLoc, 200521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *TSInfo, 200621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Expr *DimExpr, 200721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SourceLocation RParenLoc) { 200821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); 200921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 201021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 2011552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// \brief Build a new expression trait expression. 2012552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// 2013552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// By default, performs semantic analysis to build the new expression. 2014552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// Subclasses may override this routine to provide different behavior. 2015552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExprResult RebuildExpressionTrait(ExpressionTrait Trait, 2016552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation StartLoc, 2017552622067dc45013d240f73952fece703f5e63bdJohn Wiegley Expr *Queried, 2018552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation RParenLoc) { 2019552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); 2020552622067dc45013d240f73952fece703f5e63bdJohn Wiegley } 2021552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 20221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new (previously unresolved) declaration reference 2023b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// expression. 2024b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2025b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2026b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 202700cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor ExprResult RebuildDependentScopeDeclRefExpr( 202800cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 2029e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 20302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2031f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall const TemplateArgumentListInfo *TemplateArgs) { 2032b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXScopeSpec SS; 203300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor SS.Adopt(QualifierLoc); 2034f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 20359d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara if (TemplateArgs || TemplateKWLoc.isValid()) 2036e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, 20379d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara NameInfo, TemplateArgs); 2038f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 20399d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo); 2040b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2041b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2042b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new template-id expression. 2043b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2044b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2045b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 204660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, 2047e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 2048e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara LookupResult &R, 2049e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool RequiresADL, 20509d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara const TemplateArgumentListInfo *TemplateArgs) { 2051e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, 2052e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateArgs); 2053b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2054b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2055b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 2056b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2057b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2058b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 205960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXConstructExpr(QualType T, 20607cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara SourceLocation Loc, 20617cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara CXXConstructorDecl *Constructor, 20627cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool IsElidable, 20637cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara MultiExprArg Args, 20647cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates, 20657cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool RequiresZeroInit, 2066428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth CXXConstructExpr::ConstructionKind ConstructKind, 20677cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara SourceRange ParenRange) { 2068ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> ConvertedArgs(SemaRef); 2069c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, 20704411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor ConvertedArgs)) 2071f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2072c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 20734411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, 20748c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor move_arg(ConvertedArgs), 20757cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HadMultipleCandidates, 2076428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth RequiresZeroInit, ConstructKind, 2077428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth ParenRange); 2078b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2079b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2080b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 2081b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2082b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2083b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 2084ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, 2085ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 2086ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor MultiExprArg Args, 2087ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 2088ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, 2089b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LParenLoc, 2090b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(Args), 2091b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 2092b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2093b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2094b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 2095b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2096b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2097b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 2098ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, 2099ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 2100ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor MultiExprArg Args, 2101ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 2102ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, 2103b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LParenLoc, 2104b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(Args), 2105b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 2106b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 21071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2108b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new member reference expression. 2109b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2110b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2111b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 211260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, 21137c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualType BaseType, 21147c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor bool IsArrow, 21157c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor SourceLocation OperatorLoc, 21167c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2117e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 2118129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall NamedDecl *FirstQualifierInScope, 21192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &MemberNameInfo, 2120129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall const TemplateArgumentListInfo *TemplateArgs) { 2121b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXScopeSpec SS; 21227c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor SS.Adopt(QualifierLoc); 21231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, 2125aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OperatorLoc, IsArrow, 2126e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, TemplateKWLoc, 2127e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara FirstQualifierInScope, 21282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberNameInfo, 21292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TemplateArgs); 2130b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2131b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2132129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Build a new member reference expression. 21333b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// 21343b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// By default, performs semantic analysis to build the new expression. 21353b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// Subclasses may override this routine to provide different behavior. 21369138b4e96429cbaae00c52c15c960f72b6645088Richard Smith ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, 21379138b4e96429cbaae00c52c15c960f72b6645088Richard Smith SourceLocation OperatorLoc, 21389138b4e96429cbaae00c52c15c960f72b6645088Richard Smith bool IsArrow, 21399138b4e96429cbaae00c52c15c960f72b6645088Richard Smith NestedNameSpecifierLoc QualifierLoc, 2140e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 21419138b4e96429cbaae00c52c15c960f72b6645088Richard Smith NamedDecl *FirstQualifierInScope, 21429138b4e96429cbaae00c52c15c960f72b6645088Richard Smith LookupResult &R, 2143129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall const TemplateArgumentListInfo *TemplateArgs) { 21443b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor CXXScopeSpec SS; 21454c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor SS.Adopt(QualifierLoc); 21461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, 2148aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OperatorLoc, IsArrow, 2149e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, TemplateKWLoc, 2150e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara FirstQualifierInScope, 2151c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R, TemplateArgs); 21523b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 21531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21542e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// \brief Build a new noexcept expression. 21552e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// 21562e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// By default, performs semantic analysis to build the new expression. 21572e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// Subclasses may override this routine to provide different behavior. 21582e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { 21592e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); 21602e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl } 21612e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 2162ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Build a new expression to compute the length of a parameter pack. 2163ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, 2164ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation PackLoc, 2165ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation RParenLoc, 2166089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor llvm::Optional<unsigned> Length) { 2167089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor if (Length) 2168089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), 2169089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor OperatorLoc, Pack, PackLoc, 2170089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor RParenLoc, *Length); 2171089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor 2172ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), 2173ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor OperatorLoc, Pack, PackLoc, 2174089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor RParenLoc); 2175ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor } 2176ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 2177b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new Objective-C @encode expression. 2178b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2179b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2180b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 218160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, 218281d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *EncodeTypeInfo, 2183b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 218481d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, 2185b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc)); 21861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 2187b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 218892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /// \brief Build a new Objective-C class message. 218960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, 219092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Selector Sel, 2191207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelectorLocs, 219292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ObjCMethodDecl *Method, 2193c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation LBracLoc, 219492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor MultiExprArg Args, 219592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor SourceLocation RBracLoc) { 219692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return SemaRef.BuildClassMessage(ReceiverTypeInfo, 219792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ReceiverTypeInfo->getType(), 219892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /*SuperLoc=*/SourceLocation(), 2199207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Sel, Method, LBracLoc, SelectorLocs, 2200f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis RBracLoc, move(Args)); 220192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 220292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 220392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /// \brief Build a new Objective-C instance message. 220460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCMessageExpr(Expr *Receiver, 220592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Selector Sel, 2206207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelectorLocs, 220792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ObjCMethodDecl *Method, 2208c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation LBracLoc, 220992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor MultiExprArg Args, 221092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor SourceLocation RBracLoc) { 22119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildInstanceMessage(Receiver, 22129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Receiver->getType(), 221392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /*SuperLoc=*/SourceLocation(), 2214207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Sel, Method, LBracLoc, SelectorLocs, 2215f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis RBracLoc, move(Args)); 221692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 221792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 2218f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// \brief Build a new Objective-C ivar reference expression. 2219f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// 2220f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// By default, performs semantic analysis to build the new expression. 2221f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// Subclasses may override this routine to provide different behavior. 222260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, 2223f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor SourceLocation IvarLoc, 2224f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor bool IsArrow, bool IsFreeIvar) { 2225f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // FIXME: We lose track of the IsFreeIvar bit. 2226f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor CXXScopeSpec SS; 2227429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Base = getSema().Owned(BaseArg); 2228f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, 2229f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Sema::LookupMemberName); 223060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2231f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FIME:*/IvarLoc, 2232d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, 2233ad00b7705f9bbee81beeac428e7c6587734ab5a6John McCall false); 2234429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Result.isInvalid() || Base.isInvalid()) 2235f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2236c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2237f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Result.get()) 2238f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor return move(Result); 2239c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2240429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), 2241e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /*FIXME:*/IvarLoc, IsArrow, 2242e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, SourceLocation(), 2243f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FirstQualifierInScope=*/0, 2244c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt R, 2245f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*TemplateArgs=*/0); 2246f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor } 2247e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor 2248e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// \brief Build a new Objective-C property reference expression. 2249e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// 2250e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2251e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 225260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, 22533c3b7f90a863af43fa63043d396553ecf205351cJohn McCall ObjCPropertyDecl *Property, 22543c3b7f90a863af43fa63043d396553ecf205351cJohn McCall SourceLocation PropertyLoc) { 2255e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor CXXScopeSpec SS; 2256429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Base = getSema().Owned(BaseArg); 2257e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, 2258e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor Sema::LookupMemberName); 2259e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor bool IsArrow = false; 226060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2261e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*FIME:*/PropertyLoc, 2262d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, false); 2263429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Result.isInvalid() || Base.isInvalid()) 2264f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2265c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2266e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (Result.get()) 2267e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor return move(Result); 2268c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2269429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), 2270c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /*FIXME:*/PropertyLoc, IsArrow, 2271e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, SourceLocation(), 2272e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*FirstQualifierInScope=*/0, 2273c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt R, 2274e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*TemplateArgs=*/0); 2275e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor } 2276c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 227712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// \brief Build a new Objective-C property reference expression. 22789cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor /// 22799cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor /// By default, performs semantic analysis to build the new expression. 228012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// Subclasses may override this routine to provide different behavior. 228112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, 228212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *Getter, 228312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *Setter, 228412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation PropertyLoc) { 228512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // Since these expressions can only be value-dependent, we do not 228612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // need to perform semantic analysis again. 228712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return Owned( 228812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, 228912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall VK_LValue, OK_ObjCProperty, 229012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall PropertyLoc, Base)); 22919cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor } 22929cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor 2293f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// \brief Build a new Objective-C "isa" expression. 2294f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// 2295f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// By default, performs semantic analysis to build the new expression. 2296f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// Subclasses may override this routine to provide different behavior. 229760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, 2298f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor bool IsArrow) { 2299f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor CXXScopeSpec SS; 2300429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Base = getSema().Owned(BaseArg); 2301f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, 2302f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Sema::LookupMemberName); 230360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2304f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FIME:*/IsaLoc, 2305d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, false); 2306429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Result.isInvalid() || Base.isInvalid()) 2307f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2308c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2309f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Result.get()) 2310f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor return move(Result); 2311c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2312429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), 2313e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /*FIXME:*/IsaLoc, IsArrow, 2314e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, SourceLocation(), 2315f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FirstQualifierInScope=*/0, 2316c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt R, 2317f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*TemplateArgs=*/0); 2318f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor } 2319c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new shuffle vector expression. 2321b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2322b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2323b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 232460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, 2325f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall MultiExprArg SubExprs, 2326f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation RParenLoc) { 2327b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Find the declaration for __builtin_shufflevector 23281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const IdentifierInfo &Name 2329b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.Context.Idents.get("__builtin_shufflevector"); 2330b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); 2331b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); 2332b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); 23331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2334b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Build a reference to the __builtin_shufflevector builtin 2335b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); 2336429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Callee 2337429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), 2338429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley VK_LValue, BuiltinLoc)); 2339429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley Callee = SemaRef.UsualUnaryConversions(Callee.take()); 2340429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Callee.isInvalid()) 2341429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return ExprError(); 23421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Build the CallExpr 2344b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor unsigned NumSubExprs = SubExprs.size(); 2345b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Expr **Subs = (Expr **)SubExprs.release(); 2346429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult TheCall = SemaRef.Owned( 2347429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(), 2348b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Subs, NumSubExprs, 23495291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor Builtin->getCallResultType(), 2350f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr::getValueKindForType(Builtin->getResultType()), 2351429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley RParenLoc)); 23521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2353b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Type-check the __builtin_shufflevector expression. 2354429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take())); 2355b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 235643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 23578491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \brief Build a new template argument pack expansion. 23588491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 23598491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// By default, performs semantic analysis to build a new pack expansion 23608491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// for a template argument. Subclasses may override this routine to provide 23618491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// different behavior. 23628491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, 2363cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor SourceLocation EllipsisLoc, 2364cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 23658491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor switch (Pattern.getArgument().getKind()) { 23667a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor case TemplateArgument::Expression: { 23677a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor ExprResult Result 236867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor = getSema().CheckPackExpansion(Pattern.getSourceExpression(), 236967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor EllipsisLoc, NumExpansions); 23707a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor if (Result.isInvalid()) 23717a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor return TemplateArgumentLoc(); 23727a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor 23737a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor return TemplateArgumentLoc(Result.get(), Result.get()); 23747a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor } 2375dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 23768491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Template: 2377a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor return TemplateArgumentLoc(TemplateArgument( 2378a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor Pattern.getArgument().getAsTemplate(), 23792be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor NumExpansions), 2380b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Pattern.getTemplateQualifierLoc(), 2381a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor Pattern.getTemplateNameLoc(), 2382a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor EllipsisLoc); 23838491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 23848491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Null: 23858491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Integral: 23868491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Declaration: 23878491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Pack: 2388a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 23898491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor llvm_unreachable("Pack expansion pattern has no parameter packs"); 23908491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 23918491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Type: 23928491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (TypeSourceInfo *Expansion 23938491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), 2394cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor EllipsisLoc, 2395cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions)) 23968491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), 23978491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Expansion); 23988491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor break; 23998491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 24008491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 24018491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return TemplateArgumentLoc(); 24028491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 24038491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 2404dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// \brief Build a new expression pack expansion. 2405dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// 2406dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// By default, performs semantic analysis to build a new pack expansion 2407dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// for an expression. Subclasses may override this routine to provide 2408dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// different behavior. 240967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, 241067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> NumExpansions) { 241167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); 2412dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2413dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 2414dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman /// \brief Build a new atomic operation expression. 2415dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman /// 2416dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman /// By default, performs semantic analysis to build the new expression. 2417dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman /// Subclasses may override this routine to provide different behavior. 2418dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, 2419dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman MultiExprArg SubExprs, 2420dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman QualType RetTy, 2421dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman AtomicExpr::AtomicOp Op, 2422dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman SourceLocation RParenLoc) { 2423dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman // Just create the expression; there is not any interesting semantic 2424dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman // analysis here because we can't actually build an AtomicExpr until 2425dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman // we are sure it is semantically sound. 2426dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman unsigned NumSubExprs = SubExprs.size(); 2427dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman Expr **Subs = (Expr **)SubExprs.release(); 2428dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs, 2429dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman NumSubExprs, RetTy, Op, 2430dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman RParenLoc); 2431dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman } 2432dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 243343fed0de4f5bc189e45562491f83d5193eb8dac0John McCallprivate: 2434c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TypeLoc TransformTypeInObjectScope(TypeLoc TL, 2435c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType, 2436c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *FirstQualifierInScope, 2437c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor CXXScopeSpec &SS); 2438b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 2439b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, 2440b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor QualType ObjectType, 2441b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor NamedDecl *FirstQualifierInScope, 2442b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor CXXScopeSpec &SS); 2443577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}; 2444b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 244543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 244660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { 244743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!S) 244843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return SemaRef.Owned(S); 24491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 245043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor switch (S->getStmtClass()) { 245143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor case Stmt::NoStmtClass: break; 24521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 245343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform individual statement nodes 245443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) \ 245543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); 245663c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define ABSTRACT_STMT(Node) 245743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) 24584bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 24591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 246043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform expressions by calling TransformExpr. 246143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) 24627381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 246343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) case Stmt::Node##Class: 24644bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 246543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor { 246660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); 246743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (E.isInvalid()) 2468f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 24691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take())); 247143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 24721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 24731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24743fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 247543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 24761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2478670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregortemplate<typename Derived> 247960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { 2480b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!E) 2481b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.Owned(E); 2482b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2483b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor switch (E->getStmtClass()) { 2484b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::NoStmtClass: break; 2485b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define STMT(Node, Parent) case Stmt::Node##Class: break; 24867381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 2487b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent) \ 2488454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); 24894bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 24901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 24911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24923fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 2493657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor} 2494657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor 2495657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregortemplate<typename Derived> 2496aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorbool TreeTransform<Derived>::TransformExprs(Expr **Inputs, 2497aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor unsigned NumInputs, 2498aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool IsCall, 2499686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<Expr *> &Outputs, 2500aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool *ArgChanged) { 2501aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor for (unsigned I = 0; I != NumInputs; ++I) { 2502aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor // If requested, drop call arguments that need to be dropped. 2503aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (IsCall && getDerived().DropCallArgument(Inputs[I])) { 2504aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (ArgChanged) 2505aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor *ArgChanged = true; 2506aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2507aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor break; 2508aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 2509aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2510dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { 2511dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Expr *Pattern = Expansion->getPattern(); 2512dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2513686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<UnexpandedParameterPack, 2> Unexpanded; 2514dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 2515dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 2516dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2517dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // Determine whether the set of unexpanded parameter packs can and should 2518dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // be expanded. 2519dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor bool Expand = true; 2520d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 252167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> OrigNumExpansions 252267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor = Expansion->getNumExpansions(); 252367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; 2524dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), 2525dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Pattern->getSourceRange(), 2526a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 2527d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Expand, RetainExpansion, 2528d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) 2529dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2530dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2531dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (!Expand) { 2532dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // The transform has determined that we should perform a simple 2533dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // transformation on the pack expansion, producing another pack 2534dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // expansion. 2535dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 2536dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult OutPattern = getDerived().TransformExpr(Pattern); 2537dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (OutPattern.isInvalid()) 2538dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2539dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2540dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), 254167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor Expansion->getEllipsisLoc(), 254267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor NumExpansions); 2543dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (Out.isInvalid()) 2544dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2545dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2546dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (ArgChanged) 2547dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor *ArgChanged = true; 2548dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Outputs.push_back(Out.get()); 2549dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor continue; 2550dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2551c8fc90a854b4ccba21c85884676a80334159dd94John McCall 2552c8fc90a854b4ccba21c85884676a80334159dd94John McCall // Record right away that the argument was changed. This needs 2553c8fc90a854b4ccba21c85884676a80334159dd94John McCall // to happen even if the array expands to nothing. 2554c8fc90a854b4ccba21c85884676a80334159dd94John McCall if (ArgChanged) *ArgChanged = true; 2555dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2556dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // The transform has determined that we should perform an elementwise 2557dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // expansion of the pattern. Do so. 2558cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 2559dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 2560dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult Out = getDerived().TransformExpr(Pattern); 2561dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (Out.isInvalid()) 2562dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2563dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 256477d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.get()->containsUnexpandedParameterPack()) { 256567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), 256667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor OrigNumExpansions); 256777d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.isInvalid()) 256877d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor return true; 256977d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor } 257077d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor 2571dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Outputs.push_back(Out.get()); 2572dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2573dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2574dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor continue; 2575dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2576dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2577aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor ExprResult Result = getDerived().TransformExpr(Inputs[I]); 2578aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (Result.isInvalid()) 2579aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return true; 2580aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2581aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (Result.get() != Inputs[I] && ArgChanged) 2582aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor *ArgChanged = true; 2583aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2584aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Outputs.push_back(Result.get()); 2585aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 2586aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2587aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return false; 2588aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor} 2589aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2590aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregortemplate<typename Derived> 2591c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorNestedNameSpecifierLoc 2592c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorTreeTransform<Derived>::TransformNestedNameSpecifierLoc( 2593c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc NNS, 2594c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType, 2595c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *FirstQualifierInScope) { 2596686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; 2597c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; 2598c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Qualifier = Qualifier.getPrefix()) 2599c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Qualifiers.push_back(Qualifier); 2600c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2601c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor CXXScopeSpec SS; 2602c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor while (!Qualifiers.empty()) { 2603c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); 2604c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); 2605c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2606c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor switch (QNNS->getKind()) { 2607c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::Identifier: 2608c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0, 2609c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor *QNNS->getAsIdentifier(), 2610c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalBeginLoc(), 2611c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalEndLoc(), 2612c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor ObjectType, false, SS, 2613c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor FirstQualifierInScope, false)) 2614c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(); 2615c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2616c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2617c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2618c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::Namespace: { 2619c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamespaceDecl *NS 2620c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast_or_null<NamespaceDecl>( 2621c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor getDerived().TransformDecl( 2622c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalBeginLoc(), 2623c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QNNS->getAsNamespace())); 2624c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); 2625c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2626c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 2627c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2628c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::NamespaceAlias: { 2629c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamespaceAliasDecl *Alias 2630c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast_or_null<NamespaceAliasDecl>( 2631c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor getDerived().TransformDecl(Q.getLocalBeginLoc(), 2632c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QNNS->getAsNamespaceAlias())); 2633c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), 2634c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalEndLoc()); 2635c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2636c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 2637c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2638c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::Global: 2639c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // There is no meaningful transformation that one could perform on the 2640c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // global scope. 2641c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); 2642c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2643c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2644c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::TypeSpecWithTemplate: 2645c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::TypeSpec: { 2646c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, 2647c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor FirstQualifierInScope, SS); 2648c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2649c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (!TL) 2650c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(); 2651c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2652c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || 2653c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor (SemaRef.getLangOptions().CPlusPlus0x && 2654c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TL.getType()->isEnumeralType())) { 2655c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor assert(!TL.getType().hasLocalQualifiers() && 2656c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor "Can't get cv-qualifiers here"); 265795aafb2453e1fecec8dcfd9e125cd78277f45859Richard Smith if (TL.getType()->isEnumeralType()) 265895aafb2453e1fecec8dcfd9e125cd78277f45859Richard Smith SemaRef.Diag(TL.getBeginLoc(), 265995aafb2453e1fecec8dcfd9e125cd78277f45859Richard Smith diag::warn_cxx98_compat_enum_nested_name_spec); 2660c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, 2661c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalEndLoc()); 2662c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2663c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 266400c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu // If the nested-name-specifier is an invalid type def, don't emit an 266500c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu // error because a previous error should have already been emitted. 266600c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL); 266700c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) { 266800c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) 266900c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu << TL.getType() << SS.getRange(); 267000c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu } 2671c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(); 2672c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 26737c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor } 2674c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 26757c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor // The qualifier-in-scope and object type only apply to the leftmost entity. 2676c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor FirstQualifierInScope = 0; 26777c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor ObjectType = QualType(); 2678c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 2679c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2680c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // Don't rebuild the nested-name-specifier if we don't have to. 2681c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && 2682c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor !getDerived().AlwaysRebuild()) 2683c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NNS; 2684c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2685c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // If we can re-use the source-location data from the original 2686c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // nested-name-specifier, do so. 2687c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (SS.location_size() == NNS.getDataLength() && 2688c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) 2689c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); 2690c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2691c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // Allocate new nested-name-specifier location information. 2692c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return SS.getWithLocInContext(SemaRef.Context); 2693c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor} 2694c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2695c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived> 26962577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclarationNameInfo 26972577743c5650c646fb705df01403707e94f2df04Abramo BagnaraTreeTransform<Derived> 269843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { 26992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName Name = NameInfo.getName(); 270081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor if (!Name) 27012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(); 270281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor 270381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor switch (Name.getNameKind()) { 270481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::Identifier: 270581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCZeroArgSelector: 270681499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCOneArgSelector: 270781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCMultiArgSelector: 270881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXOperatorName: 27093e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt case DeclarationName::CXXLiteralOperatorName: 271081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXUsingDirective: 27112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return NameInfo; 27121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 271381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXConstructorName: 271481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXDestructorName: 271581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXConversionFunctionName: { 27162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TypeSourceInfo *NewTInfo; 27172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara CanQualType NewCanTy; 27182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { 271943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NewTInfo = getDerived().TransformType(OldTInfo); 272043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (!NewTInfo) 272143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return DeclarationNameInfo(); 272243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); 27232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 27242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara else { 27252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewTInfo = 0; 27262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); 272743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType NewT = getDerived().TransformType(Name.getCXXNameType()); 27282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (NewT.isNull()) 27292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(); 27302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewCanTy = SemaRef.Context.getCanonicalType(NewT); 27312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 27321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 27332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName NewName 27342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), 27352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewCanTy); 27362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NewNameInfo(NameInfo); 27372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewNameInfo.setName(NewName); 27382577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewNameInfo.setNamedTypeInfo(NewTInfo); 27392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return NewNameInfo; 274081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor } 27411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 27421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2743b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unknown name kind."); 274481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor} 274581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor 274681499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregortemplate<typename Derived> 27471eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 2748fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, 2749fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName Name, 2750fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 2751fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor QualType ObjectType, 2752fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor NamedDecl *FirstQualifierInScope) { 2753fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { 2754fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateDecl *Template = QTN->getTemplateDecl(); 2755fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor assert(Template && "qualified template name must refer to a template"); 2756fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2757fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateDecl *TransTemplate 2758fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, 2759fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor Template)); 2760fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!TransTemplate) 2761fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 2762fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2763fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2764fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SS.getScopeRep() == QTN->getQualifier() && 2765fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransTemplate == Template) 2766fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 2767fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2768fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), 2769fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransTemplate); 2770fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2771fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2772fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { 2773fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (SS.getScopeRep()) { 2774fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor // These apply to the scope specifier, not the template. 2775fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType = QualType(); 2776fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor FirstQualifierInScope = 0; 2777fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2778fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2779fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2780fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SS.getScopeRep() == DTN->getQualifier() && 2781fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType.isNull()) 2782fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 2783fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2784fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (DTN->isIdentifier()) { 2785fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(SS, 2786fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor *DTN->getIdentifier(), 2787fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor NameLoc, 2788fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType, 2789fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor FirstQualifierInScope); 2790fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2791fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2792fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, 2793fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType); 2794fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2795fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2796fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (TemplateDecl *Template = Name.getAsTemplateDecl()) { 2797fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateDecl *TransTemplate 2798fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, 2799fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor Template)); 2800fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!TransTemplate) 2801fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 2802fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2803fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2804fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransTemplate == Template) 2805fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 2806fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2807fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(TransTemplate); 2808fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2809fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2810fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (SubstTemplateTemplateParmPackStorage *SubstPack 2811fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = Name.getAsSubstTemplateTemplateParmPack()) { 2812fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateTemplateParmDecl *TransParam 2813fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = cast_or_null<TemplateTemplateParmDecl>( 2814fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); 2815fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!TransParam) 2816fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 2817fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2818fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2819fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransParam == SubstPack->getParameterPack()) 2820fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 2821fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2822fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(TransParam, 2823fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SubstPack->getArgumentPack()); 2824fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2825fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2826fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor // These should be getting filtered out before they reach the AST. 2827fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor llvm_unreachable("overloaded function decl survived to here"); 2828fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 2829fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor} 2830fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2831fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregortemplate<typename Derived> 2832833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallvoid TreeTransform<Derived>::InventTemplateArgumentLoc( 2833833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgument &Arg, 2834833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &Output) { 2835833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation Loc = getDerived().getBaseLocation(); 2836670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor switch (Arg.getKind()) { 2837670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Null: 28389f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin llvm_unreachable("null template argument in TreeTransform"); 2839833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2840833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2841833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Type: 2842833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(Arg, 2843a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); 2844c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2845833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2846833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2847788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: 2848b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor case TemplateArgument::TemplateExpansion: { 2849b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor NestedNameSpecifierLocBuilder Builder; 2850b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor TemplateName Template = Arg.getAsTemplate(); 2851b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) 2852b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); 2853b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) 2854b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); 2855b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor 2856b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (Arg.getKind() == TemplateArgument::Template) 2857b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Output = TemplateArgumentLoc(Arg, 2858b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.getWithLocInContext(SemaRef.Context), 2859b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Loc); 2860b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor else 2861b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Output = TemplateArgumentLoc(Arg, 2862b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.getWithLocInContext(SemaRef.Context), 2863b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Loc, Loc); 2864b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor 2865a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor break; 2866b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor } 2867a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 2868833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Expression: 2869833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); 2870833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2871833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2872833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Declaration: 2873670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Integral: 2874833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Pack: 2875828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); 2876833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2877833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 2878833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 2879833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2880833ca991c1bfc967f0995974ca86f66ba1f666b5John McCalltemplate<typename Derived> 2881833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TreeTransform<Derived>::TransformTemplateArgument( 2882833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc &Input, 2883833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &Output) { 2884833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgument &Arg = Input.getArgument(); 2885833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall switch (Arg.getKind()) { 2886833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Null: 2887833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Integral: 2888833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = Input; 2889833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 28901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2891670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Type: { 2892a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *DI = Input.getTypeSourceInfo(); 2893833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (DI == NULL) 2894a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall DI = InventTypeSourceInfo(Input.getArgument().getAsType()); 2895833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2896833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall DI = getDerived().TransformType(DI); 2897833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!DI) return true; 2898833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2899833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); 2900833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2901670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 29021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2903670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Declaration: { 2904833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: we should never have to transform one of these. 2905972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor DeclarationName Name; 2906972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) 2907972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor Name = ND->getDeclName(); 2908788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor TemporaryBase Rebase(*this, Input.getLocation(), Name); 29097c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); 2910833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!D) return true; 2911833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2912828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Expr *SourceExpr = Input.getSourceDeclExpression(); 2913828bff2079b6a91ecd7ed5b842c59527d7682789John McCall if (SourceExpr) { 2914828bff2079b6a91ecd7ed5b842c59527d7682789John McCall EnterExpressionEvaluationContext Unevaluated(getSema(), 2915f6702a3927147655206ae729a84339c4fda4c651Richard Smith Sema::ConstantEvaluated); 291660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(SourceExpr); 29179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SourceExpr = (E.isInvalid() ? 0 : E.take()); 2918828bff2079b6a91ecd7ed5b842c59527d7682789John McCall } 2919828bff2079b6a91ecd7ed5b842c59527d7682789John McCall 2920828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); 2921833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2922670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 29231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2924788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: { 2925b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); 2926b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (QualifierLoc) { 2927b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); 2928b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (!QualifierLoc) 2929b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor return true; 2930b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor } 2931b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor 29321d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor CXXScopeSpec SS; 29331d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor SS.Adopt(QualifierLoc); 2934788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor TemplateName Template 29351d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), 29361d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor Input.getTemplateNameLoc()); 2937788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor if (Template.isNull()) 2938788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return true; 2939c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2940b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, 2941788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor Input.getTemplateNameLoc()); 2942788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return false; 2943788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor } 2944a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 2945a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 2946a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor llvm_unreachable("Caller should expand pack expansions"); 2947a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 2948670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Expression: { 2949f6702a3927147655206ae729a84339c4fda4c651Richard Smith // Template argument expressions are constant expressions. 29501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EnterExpressionEvaluationContext Unevaluated(getSema(), 2951f6702a3927147655206ae729a84339c4fda4c651Richard Smith Sema::ConstantEvaluated); 29521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2953833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Expr *InputExpr = Input.getSourceExpression(); 2954833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); 2955833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2956223de2497fdaacf3a6b0a123c12265ca837abf19Chris Lattner ExprResult E = getDerived().TransformExpr(InputExpr); 2957833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (E.isInvalid()) return true; 29589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); 2959833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2960670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 29611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2962670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Pack: { 2963686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<TemplateArgument, 4> TransformedArgs; 2964670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor TransformedArgs.reserve(Arg.pack_size()); 29651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (TemplateArgument::pack_iterator A = Arg.pack_begin(), 2966670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor AEnd = Arg.pack_end(); 2967670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor A != AEnd; ++A) { 29681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2969833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: preserve source information here when we start 2970833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // caring about parameter packs. 2971833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2972828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TemplateArgumentLoc InputArg; 2973828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TemplateArgumentLoc OutputArg; 2974828bff2079b6a91ecd7ed5b842c59527d7682789John McCall getDerived().InventTemplateArgumentLoc(*A, InputArg); 2975828bff2079b6a91ecd7ed5b842c59527d7682789John McCall if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) 2976833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 2977833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2978828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TransformedArgs.push_back(OutputArg.getArgument()); 2979670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 2980910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor 2981910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TemplateArgument *TransformedArgsPtr 2982910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor = new (getSema().Context) TemplateArgument[TransformedArgs.size()]; 2983910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor std::copy(TransformedArgs.begin(), TransformedArgs.end(), 2984910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TransformedArgsPtr); 2985910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr, 2986910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TransformedArgs.size()), 2987910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor Input.getLocInfo()); 2988833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2989670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 2990670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 29911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2992670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Work around bogus GCC warning 2993833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 2994670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor} 2995670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor 29967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// \brief Iterator adaptor that invents template argument location information 29977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// for each of the template arguments in its underlying iterator. 29987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename Derived, typename InputIterator> 29997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorclass TemplateArgumentLocInventIterator { 30007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TreeTransform<Derived> &Self; 30017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Iter; 30027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorpublic: 30047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc value_type; 30057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc reference; 30067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef typename std::iterator_traits<InputIterator>::difference_type 30077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor difference_type; 30087ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef std::input_iterator_tag iterator_category; 30097ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30107ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class pointer { 30117ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Arg; 3012fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 30137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 30147ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } 30157ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30167ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLoc *operator->() const { return &Arg; } 30177ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 30187ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30197ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator() { } 30207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, 30227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Iter) 30237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor : Self(Self), Iter(Iter) { } 30247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator &operator++() { 30267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++Iter; 30277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return *this; 3028fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor } 3029fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 30307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator operator++(int) { 30317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator Old(*this); 30327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++(*this); 30337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Old; 30347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 30357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor reference operator*() const { 30377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Result; 30387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor Self.InventTemplateArgumentLoc(*Iter, Result); 30397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Result; 30407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 30417ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor pointer operator->() const { return pointer(**this); } 30437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator==(const TemplateArgumentLocInventIterator &X, 30457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLocInventIterator &Y) { 30467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Iter == Y.Iter; 30477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 3048fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 30497ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator!=(const TemplateArgumentLocInventIterator &X, 30507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLocInventIterator &Y) { 30517ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Iter != Y.Iter; 30527ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 30537ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor}; 30547ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30557f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregortemplate<typename Derived> 30567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename InputIterator> 30577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorbool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, 30587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Last, 30597f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor TemplateArgumentListInfo &Outputs) { 30607ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor for (; First != Last; ++First) { 30617f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor TemplateArgumentLoc Out; 30627ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc In = *First; 30638491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30648491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (In.getArgument().getKind() == TemplateArgument::Pack) { 30658491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // Unpack argument packs, which we translate them into separate 30668491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // arguments. 30677ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // FIXME: We could do much better if we could guarantee that the 30687ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // TemplateArgumentLocInfo for the pack expansion would be usable for 30697ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // all of the template arguments in the argument pack. 30707ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLocInventIterator<Derived, 30717ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgument::pack_iterator> 30727ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor PackLocIterator; 30737ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor if (TransformTemplateArguments(PackLocIterator(*this, 30747ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor In.getArgument().pack_begin()), 30757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor PackLocIterator(*this, 30767ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor In.getArgument().pack_end()), 30777ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor Outputs)) 30787ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return true; 30798491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30808491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 30818491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 30828491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30838491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (In.getArgument().isPackExpansion()) { 30848491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // We have a pack expansion, for which we will be substituting into 30858491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // the pattern. 30868491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor SourceLocation Ellipsis; 3087cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> OrigNumExpansions; 30888491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc Pattern 3089cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions, 3090cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor getSema().Context); 30918491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 3092686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<UnexpandedParameterPack, 2> Unexpanded; 30938491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 30948491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 30958491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 30968491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // Determine whether the set of unexpanded parameter packs can and should 30978491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // be expanded. 30988491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor bool Expand = true; 3099d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 3100cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; 31018491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TryExpandParameterPacks(Ellipsis, 31028491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Pattern.getSourceRange(), 3103a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 3104d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Expand, 3105d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor RetainExpansion, 3106d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) 31078491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 31088491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 31098491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (!Expand) { 31108491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The transform has determined that we should perform a simple 31118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // transformation on the pack expansion, producing another pack 31128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // expansion. 31138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc OutPattern; 31148491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 31158491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) 31168491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 31178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 3118cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, 3119cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions); 31208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (Out.getArgument().isNull()) 31218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 31228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 31238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Outputs.addArgument(Out); 31248491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 31258491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 31268491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 31278491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The transform has determined that we should perform an elementwise 31288491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // expansion of the pattern. Do so. 3129cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 31308491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 31318491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 31328491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, Out)) 31338491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 31348491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 313577d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.getArgument().containsUnexpandedParameterPack()) { 3136cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Out = getDerived().RebuildPackExpansion(Out, Ellipsis, 3137cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor OrigNumExpansions); 313877d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.getArgument().isNull()) 313977d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor return true; 314077d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor } 314177d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor 31428491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Outputs.addArgument(Out); 31438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 31448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 31453cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 31463cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // forgetting the partially-substituted parameter pack. 31473cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (RetainExpansion) { 31483cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 31493cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 31503cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, Out)) 31513cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor return true; 31523cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 3153cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Out = getDerived().RebuildPackExpansion(Out, Ellipsis, 3154cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor OrigNumExpansions); 31553cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (Out.getArgument().isNull()) 31563cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor return true; 31573cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 31583cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor Outputs.addArgument(Out); 31593cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor } 3160d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 31618491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 31628491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 31638491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 31648491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The simple case: 31658491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(In, Out)) 31667f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return true; 31677f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 31687f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor Outputs.addArgument(Out); 31697f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor } 31707f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 31717f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return false; 31727f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 31737f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor} 31747f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 3175577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 3176577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// Type transformation 3177577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 3178577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3179577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 318043fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::TransformType(QualType T) { 3181577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (getDerived().AlreadyTransformed(T)) 3182577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return T; 31831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3184a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Temporary workaround. All of these transformations should 3185a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // eventually turn into transformations on TypeLocs. 3186c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, 3187c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor getDerived().getBaseLocation()); 3188c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 318943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeSourceInfo *NewDI = getDerived().TransformType(DI); 31901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3191a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (!NewDI) 3192a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 31931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3194a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return NewDI->getType(); 3195577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 31961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3197577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 319843fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { 3199f6702a3927147655206ae729a84339c4fda4c651Richard Smith // Refine the base location to the type's location. 3200f6702a3927147655206ae729a84339c4fda4c651Richard Smith TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), 3201f6702a3927147655206ae729a84339c4fda4c651Richard Smith getDerived().getBaseEntity()); 3202a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlreadyTransformed(DI->getType())) 3203a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return DI; 32041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3205a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder TLB; 32061bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 3207a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLoc TL = DI->getTypeLoc(); 3208a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TLB.reserve(TL.getFullDataSize()); 32091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 321043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result = getDerived().TransformType(TLB, TL); 3211a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3212a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return 0; 32131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3214a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall return TLB.getTypeSourceInfo(SemaRef.Context, Result); 3215577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 32161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3218a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 321943fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { 3220a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall switch (T.getTypeLocClass()) { 3221a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT) 3222a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT) \ 3223a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall case TypeLoc::CLASS: \ 322443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); 3225a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def" 3226a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3227577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 32289f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin llvm_unreachable("unhandled type loc!"); 3229a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3230577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 32311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3232a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// FIXME: By default, this routine adds type qualifiers only to types 3233a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that can have qualifiers, and silently suppresses those qualifiers 3234a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that are not permitted (e.g., qualifiers on reference or function 3235a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// types). This is the right thing for template instantiation, but 3236a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// probably not for other clients. 32371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 32381eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3239a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, 324043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualifiedTypeLoc T) { 3241a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor Qualifiers Quals = T.getType().getLocalQualifiers(); 3242a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 324343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); 3244a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3245577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 32461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3247a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Silently suppress qualifiers if the result type can't be qualified. 3248a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: this is the right thing for template instantiation, but 3249a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // probably not for other clients. 3250a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result->isFunctionType() || Result->isReferenceType()) 3251a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 32521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3253f85e193739c953358c865005855253af4f68a497John McCall // Suppress Objective-C lifetime qualifiers if they don't make sense for the 3254e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // resulting type. 3255e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor if (Quals.hasObjCLifetime()) { 3256e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor if (!Result->isObjCLifetimeType() && !Result->isDependentType()) 3257e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Quals.removeObjCLifetime(); 32584020caec546d221170072d2388b57d151cb26111Douglas Gregor else if (Result.getObjCLifetime()) { 3259e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // Objective-C ARC: 3260e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // A lifetime qualifier applied to a substituted template parameter 3261e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // overrides the lifetime qualifier from the template argument. 3262e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor if (const SubstTemplateTypeParmType *SubstTypeParam 3263e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor = dyn_cast<SubstTemplateTypeParmType>(Result)) { 3264e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor QualType Replacement = SubstTypeParam->getReplacementType(); 3265e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Qualifiers Qs = Replacement.getQualifiers(); 3266e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Qs.removeObjCLifetime(); 3267e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Replacement 3268e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), 3269e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Qs); 3270e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Result = SemaRef.Context.getSubstTemplateTypeParmType( 3271e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor SubstTypeParam->getReplacedParameter(), 3272e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Replacement); 3273e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor TLB.TypeWasModifiedSafely(Result); 3274e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } else { 32754020caec546d221170072d2388b57d151cb26111Douglas Gregor // Otherwise, complain about the addition of a qualifier to an 32764020caec546d221170072d2388b57d151cb26111Douglas Gregor // already-qualified type. 32774020caec546d221170072d2388b57d151cb26111Douglas Gregor SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange(); 3278b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant) 32794020caec546d221170072d2388b57d151cb26111Douglas Gregor << Result << R; 32804020caec546d221170072d2388b57d151cb26111Douglas Gregor 3281e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Quals.removeObjCLifetime(); 3282e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } 3283e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } 3284e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } 32852865474261a608c7873b87ba4af110d17907896dJohn McCall if (!Quals.empty()) { 32862865474261a608c7873b87ba4af110d17907896dJohn McCall Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); 32872865474261a608c7873b87ba4af110d17907896dJohn McCall TLB.push<QualifiedTypeLoc>(Result); 32882865474261a608c7873b87ba4af110d17907896dJohn McCall // No location information to preserve. 32892865474261a608c7873b87ba4af110d17907896dJohn McCall } 3290a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3291a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3292a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 3293a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 329443fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived> 3295b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTypeLoc 3296b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, 329743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 329843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *UnqualLookup, 3299b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor CXXScopeSpec &SS) { 3300b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor QualType T = TL.getType(); 330143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (getDerived().AlreadyTransformed(T)) 3302b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TL; 3303b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 330443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeLocBuilder TLB; 330543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result; 3306b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 330743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (isa<TemplateSpecializationType>(T)) { 3308b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TemplateSpecializationTypeLoc SpecTL 3309b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = cast<TemplateSpecializationTypeLoc>(TL); 3310b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 331143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template = 3312b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor getDerived().TransformTemplateName(SS, 3313b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL.getTypePtr()->getTemplateName(), 3314b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL.getTemplateNameLoc(), 331543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType, UnqualLookup); 3316b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor if (Template.isNull()) 3317b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TypeLoc(); 3318b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 3319b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, 3320b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Template); 332143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } else if (isa<DependentTemplateSpecializationType>(T)) { 3322b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor DependentTemplateSpecializationTypeLoc SpecTL 3323b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = cast<DependentTemplateSpecializationTypeLoc>(TL); 3324a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 3325b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TemplateName Template 3326b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = getDerived().RebuildTemplateName(SS, 3327b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor *SpecTL.getTypePtr()->getIdentifier(), 3328b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL.getNameLoc(), 3329b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor ObjectType, UnqualLookup); 3330a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (Template.isNull()) 3331b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TypeLoc(); 3332b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 3333b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Result = getDerived().TransformDependentTemplateSpecializationType(TLB, 3334b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL, 3335087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor Template, 3336087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor SS); 333743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } else { 333843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // Nothing special needs to be done for these. 3339b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Result = getDerived().TransformType(TLB, TL); 334043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } 3341b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 3342b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor if (Result.isNull()) 3343b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TypeLoc(); 3344b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 3345b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc(); 334643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall} 334743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 3348c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived> 3349b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTypeSourceInfo * 3350b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, 3351c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType, 3352c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *UnqualLookup, 3353c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor CXXScopeSpec &SS) { 3354c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // FIXME: Painfully copy-paste from the above! 3355c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3356b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor QualType T = TSInfo->getType(); 3357c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (getDerived().AlreadyTransformed(T)) 3358b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TSInfo; 3359c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3360c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TypeLocBuilder TLB; 3361c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType Result; 3362c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3363b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TypeLoc TL = TSInfo->getTypeLoc(); 3364c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (isa<TemplateSpecializationType>(T)) { 3365c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TemplateSpecializationTypeLoc SpecTL 3366c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast<TemplateSpecializationTypeLoc>(TL); 3367c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3368b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TemplateName Template 3369b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = getDerived().TransformTemplateName(SS, 3370fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SpecTL.getTypePtr()->getTemplateName(), 3371fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SpecTL.getTemplateNameLoc(), 3372c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor ObjectType, UnqualLookup); 3373c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (Template.isNull()) 3374b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return 0; 3375c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3376c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, 3377c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Template); 3378c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } else if (isa<DependentTemplateSpecializationType>(T)) { 3379c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor DependentTemplateSpecializationTypeLoc SpecTL 3380c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast<DependentTemplateSpecializationTypeLoc>(TL); 3381c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3382a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateName Template 3383fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = getDerived().RebuildTemplateName(SS, 33847c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor *SpecTL.getTypePtr()->getIdentifier(), 3385fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SpecTL.getNameLoc(), 33867c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor ObjectType, UnqualLookup); 3387a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (Template.isNull()) 3388b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return 0; 3389a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 3390c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Result = getDerived().TransformDependentTemplateSpecializationType(TLB, 3391a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor SpecTL, 3392087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor Template, 3393087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor SS); 3394c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } else { 3395c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // Nothing special needs to be done for these. 3396c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Result = getDerived().TransformType(TLB, TL); 3397c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 3398c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3399c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (Result.isNull()) 3400b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return 0; 3401c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3402b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TLB.getTypeSourceInfo(SemaRef.Context, Result); 3403c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor} 3404c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3405a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate <class TyLoc> static inline 3406a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { 3407a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TyLoc NewT = TLB.push<TyLoc>(T.getType()); 3408a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewT.setNameLoc(T.getNameLoc()); 3409a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return T.getType(); 3410a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 3411a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3412a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3413a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, 341443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall BuiltinTypeLoc T) { 3415ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); 3416ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor NewT.setBuiltinLoc(T.getBuiltinLoc()); 3417ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor if (T.needsExtraLocalData()) 3418ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); 3419ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return T.getType(); 3420577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3421577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 34221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3423a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, 342443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ComplexTypeLoc T) { 3425a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: recurse? 3426a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return TransformTypeSpecType(TLB, T); 3427a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 34281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3429a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3430a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, 343143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall PointerTypeLoc TL) { 3432c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt QualType PointeeType 3433c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt = getDerived().TransformType(TLB, TL.getPointeeLoc()); 343492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (PointeeType.isNull()) 343592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return QualType(); 343692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 343792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor QualType Result = TL.getType(); 3438c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (PointeeType->getAs<ObjCObjectType>()) { 343992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // A dependent pointer type 'T *' has is being transformed such 344092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // that an Objective-C class type is being replaced for 'T'. The 344192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // resulting pointer type is an ObjCObjectPointerType, not a 344292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // PointerType. 3443c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); 3444c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3445c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); 3446c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall NewT.setStarLoc(TL.getStarLoc()); 344792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return Result; 344892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 344943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 345092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (getDerived().AlwaysRebuild() || 345192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor PointeeType != TL.getPointeeLoc().getType()) { 345292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); 345392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (Result.isNull()) 345492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return QualType(); 345592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 3456f85e193739c953358c865005855253af4f68a497John McCall 3457f85e193739c953358c865005855253af4f68a497John McCall // Objective-C ARC can add lifetime qualifiers to the type that we're 3458f85e193739c953358c865005855253af4f68a497John McCall // pointing to. 3459f85e193739c953358c865005855253af4f68a497John McCall TLB.TypeWasModifiedSafely(Result->getPointeeType()); 3460f85e193739c953358c865005855253af4f68a497John McCall 346192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); 346292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor NewT.setSigilLoc(TL.getSigilLoc()); 3463c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return Result; 3464577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3465577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 34661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 34671eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3468a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, 346943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall BlockPointerTypeLoc TL) { 3470db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor QualType PointeeType 3471c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt = getDerived().TransformType(TLB, TL.getPointeeLoc()); 3472c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (PointeeType.isNull()) 3473c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return QualType(); 3474c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3475c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt QualType Result = TL.getType(); 3476c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (getDerived().AlwaysRebuild() || 3477c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt PointeeType != TL.getPointeeLoc().getType()) { 3478c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Result = getDerived().RebuildBlockPointerType(PointeeType, 3479db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor TL.getSigilLoc()); 3480db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor if (Result.isNull()) 3481db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor return QualType(); 3482db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor } 3483db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor 348439968adc66ab02275d2f561e372a20ae454bd4e7Douglas Gregor BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); 3485db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor NewT.setSigilLoc(TL.getSigilLoc()); 3486db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor return Result; 3487a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 34881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 348985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// Transforms a reference type. Note that somewhat paradoxically we 349085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// don't care whether the type itself is an l-value type or an r-value 349185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// type; we only care if the type was *written* as an l-value type 349285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// or an r-value type. 349385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCalltemplate<typename Derived> 349485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType 349585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, 349643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ReferenceTypeLoc TL) { 349785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall const ReferenceType *T = TL.getTypePtr(); 349885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 349985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall // Note that this works with the pointee-as-written. 350085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 350185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (PointeeType.isNull()) 350285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return QualType(); 350385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 350485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType Result = TL.getType(); 350585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (getDerived().AlwaysRebuild() || 350685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall PointeeType != T->getPointeeTypeAsWritten()) { 350785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Result = getDerived().RebuildReferenceType(PointeeType, 350885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->isSpelledAsLValue(), 350985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getSigilLoc()); 351085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (Result.isNull()) 351185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return QualType(); 351285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall } 351385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 3514f85e193739c953358c865005855253af4f68a497John McCall // Objective-C ARC can add lifetime qualifiers to the type that we're 3515f85e193739c953358c865005855253af4f68a497John McCall // referring to. 3516f85e193739c953358c865005855253af4f68a497John McCall TLB.TypeWasModifiedSafely( 3517f85e193739c953358c865005855253af4f68a497John McCall Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); 3518f85e193739c953358c865005855253af4f68a497John McCall 351985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall // r-value references can be rebuilt as l-value references. 352085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall ReferenceTypeLoc NewTL; 352185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (isa<LValueReferenceType>(Result)) 352285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL = TLB.push<LValueReferenceTypeLoc>(Result); 352385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall else 352485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL = TLB.push<RValueReferenceTypeLoc>(Result); 352585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL.setSigilLoc(TL.getSigilLoc()); 352685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 352785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return Result; 352885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall} 352985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 3530a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3531a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3532a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, 353343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall LValueReferenceTypeLoc TL) { 353443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TransformReferenceType(TLB, TL); 3535a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 35361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3537a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3538a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3539a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, 354043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall RValueReferenceTypeLoc TL) { 354143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TransformReferenceType(TLB, TL); 3542577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 35431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3544577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 35451eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3546a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, 354743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall MemberPointerTypeLoc TL) { 3548a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 3549577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (PointeeType.isNull()) 3550577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 35511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3552b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); 3553b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara TypeSourceInfo* NewClsTInfo = 0; 3554b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (OldClsTInfo) { 3555b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsTInfo = getDerived().TransformType(OldClsTInfo); 3556b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (!NewClsTInfo) 3557b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara return QualType(); 3558b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara } 3559b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara 3560b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara const MemberPointerType *T = TL.getTypePtr(); 3561b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara QualType OldClsType = QualType(T->getClass(), 0); 3562b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara QualType NewClsType; 3563b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (NewClsTInfo) 3564b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsType = NewClsTInfo->getType(); 3565b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara else { 3566b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsType = getDerived().TransformType(OldClsType); 3567b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (NewClsType.isNull()) 3568b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara return QualType(); 3569b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara } 35701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3571a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3572a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3573a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall PointeeType != T->getPointeeType() || 3574b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsType != OldClsType) { 3575b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, 357685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getStarLoc()); 3577a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3578a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3579a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3580577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3581a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); 3582a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSigilLoc(TL.getSigilLoc()); 3583b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewTL.setClassTInfo(NewClsTInfo); 3584a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3585a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3586577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3587577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 35881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 35891eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3590a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, 359143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ConstantArrayTypeLoc TL) { 3592f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const ConstantArrayType *T = TL.getTypePtr(); 3593a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3594577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3595577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 35961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3597a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3598a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3599a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3600a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildConstantArrayType(ElementType, 3601a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 3602a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSize(), 360385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->getIndexTypeCVRQualifiers(), 360485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3605a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3606a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3607a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3608457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman 3609457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman // We might have either a ConstantArrayType or a VariableArrayType now: 3610457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman // a ConstantArrayType is allowed to have an element type which is a 3611457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman // VariableArrayType if the type is dependent. Fortunately, all array 3612457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman // types have the same location layout. 3613457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); 3614a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3615a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 36161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3617a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Expr *Size = TL.getSizeExpr(); 3618a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Size) { 3619f6702a3927147655206ae729a84339c4fda4c651Richard Smith EnterExpressionEvaluationContext Unevaluated(SemaRef, 3620f6702a3927147655206ae729a84339c4fda4c651Richard Smith Sema::ConstantEvaluated); 3621a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); 3622a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3623a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(Size); 3624a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3625a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3626577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 36271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3628577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 3629577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformIncompleteArrayType( 3630a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 363143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall IncompleteArrayTypeLoc TL) { 3632f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const IncompleteArrayType *T = TL.getTypePtr(); 3633a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3634577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3635577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3637a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3638a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3639a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3640a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildIncompleteArrayType(ElementType, 3641a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 364285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->getIndexTypeCVRQualifiers(), 364385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3644a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3645a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3646a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3647c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3648a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); 3649a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3650a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 3651a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(0); 3652577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3653a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3654577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 36551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3656577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 3657a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3658a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, 365943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall VariableArrayTypeLoc TL) { 3660f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const VariableArrayType *T = TL.getTypePtr(); 3661a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3662577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3663577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 366560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SizeResult 3666a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall = getDerived().TransformExpr(T->getSizeExpr()); 3667a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (SizeResult.isInvalid()) 3668577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Size = SizeResult.take(); 3671a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3672a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3673a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3674a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType() || 3675a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Size != T->getSizeExpr()) { 3676a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildVariableArrayType(ElementType, 3677a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 36789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Size, 3679a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getIndexTypeCVRQualifiers(), 368085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3681a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3682a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3683577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 3684c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3685a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); 3686a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3687a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 3688a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(Size); 36891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3690a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3691577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 36921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3694a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3695a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, 369643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentSizedArrayTypeLoc TL) { 3697f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentSizedArrayType *T = TL.getTypePtr(); 3698a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3699577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3700577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 37011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3702f6702a3927147655206ae729a84339c4fda4c651Richard Smith // Array bounds are constant expressions. 3703f6702a3927147655206ae729a84339c4fda4c651Richard Smith EnterExpressionEvaluationContext Unevaluated(SemaRef, 3704f6702a3927147655206ae729a84339c4fda4c651Richard Smith Sema::ConstantEvaluated); 37051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Prefer the expression from the TypeLoc; the other may have been uniqued. 37073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Expr *origSize = TL.getSizeExpr(); 37083b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!origSize) origSize = T->getSizeExpr(); 37093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 37103b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExprResult sizeResult 37113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall = getDerived().TransformExpr(origSize); 37123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (sizeResult.isInvalid()) 3713577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 37141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37153b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Expr *size = sizeResult.get(); 3716a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3717a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3718a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3719a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType() || 37203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall size != origSize) { 3721a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildDependentSizedArrayType(ElementType, 3722a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 37233b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall size, 3724a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getIndexTypeCVRQualifiers(), 372585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3726a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3727a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3728577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 37291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3730a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // We might have any sort of array type now, but fortunately they 3731a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // all have the same location layout. 3732a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); 3733a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3734a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 37353b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall NewTL.setSizeExpr(size); 3736a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3737a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3738577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 37391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3741577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( 3742a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 374343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentSizedExtVectorTypeLoc TL) { 3744f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentSizedExtVectorType *T = TL.getTypePtr(); 3745a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3746a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: ext vector locs should be nested 3747577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3748577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3749577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 37501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3751f6702a3927147655206ae729a84339c4fda4c651Richard Smith // Vector sizes are constant expressions. 3752f6702a3927147655206ae729a84339c4fda4c651Richard Smith EnterExpressionEvaluationContext Unevaluated(SemaRef, 3753f6702a3927147655206ae729a84339c4fda4c651Richard Smith Sema::ConstantEvaluated); 3754670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor 375560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); 3756577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (Size.isInvalid()) 3757577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 37581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3759a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3760a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3761eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall ElementType != T->getElementType() || 3762eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall Size.get() != T->getSizeExpr()) { 3763a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, 37649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Size.take(), 3765577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor T->getAttributeLoc()); 3766a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3767a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3768a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3769a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3770a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Result might be dependent or not. 3771a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (isa<DependentSizedExtVectorType>(Result)) { 3772a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall DependentSizedExtVectorTypeLoc NewTL 3773a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall = TLB.push<DependentSizedExtVectorTypeLoc>(Result); 3774a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 3775a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } else { 3776a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); 3777a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 3778a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3779a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3780a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3781577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 37821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3784a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, 378543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall VectorTypeLoc TL) { 3786f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const VectorType *T = TL.getTypePtr(); 3787577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3788577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3789577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 3790577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3791a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3792a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3793a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 379482287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), 3795e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson T->getVectorKind()); 3796a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3797a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3798a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3799c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3800a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); 3801a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 38021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3803a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3804577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 38051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3807a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, 380843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ExtVectorTypeLoc TL) { 3809f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const VectorType *T = TL.getTypePtr(); 3810577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3811577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3812577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 38131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3814a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3815a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3816a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3817a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildExtVectorType(ElementType, 3818a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getNumElements(), 3819a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /*FIXME*/ SourceLocation()); 3820a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3821a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3822a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3823c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3824a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); 3825a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 38261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3827a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3828577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3829577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 38301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 383121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallParmVarDecl * 38326a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas GregorTreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm, 3833fb44de956f27875def889482b5393475060392afJohn McCall int indexAdjustment, 3834d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor llvm::Optional<unsigned> NumExpansions, 3835d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor bool ExpectParameterPack) { 383621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); 38376a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeSourceInfo *NewDI = 0; 38386a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 38396a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { 38406a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor // If we're substituting into a pack expansion type and we know the 3841d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor // length we want to expand to, just substitute for the pattern. 38426a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeLoc OldTL = OldDI->getTypeLoc(); 38436a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL); 38446a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 38456a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeLocBuilder TLB; 38466a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeLoc NewTL = OldDI->getTypeLoc(); 38476a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TLB.reserve(NewTL.getFullDataSize()); 38486a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 38496a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor QualType Result = getDerived().TransformType(TLB, 38506a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OldExpansionTL.getPatternLoc()); 38516a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor if (Result.isNull()) 38526a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor return 0; 38536a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 38546a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor Result = RebuildPackExpansionType(Result, 38556a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OldExpansionTL.getPatternLoc().getSourceRange(), 38566a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OldExpansionTL.getEllipsisLoc(), 38576a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NumExpansions); 38586a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor if (Result.isNull()) 38596a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor return 0; 38606a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 38616a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor PackExpansionTypeLoc NewExpansionTL 38626a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = TLB.push<PackExpansionTypeLoc>(Result); 38636a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); 38646a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); 38656a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor } else 38666a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NewDI = getDerived().TransformType(OldDI); 386721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall if (!NewDI) 386821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return 0; 386921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 3870fb44de956f27875def889482b5393475060392afJohn McCall if (NewDI == OldDI && indexAdjustment == 0) 387121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return OldParm; 3872fb44de956f27875def889482b5393475060392afJohn McCall 3873fb44de956f27875def889482b5393475060392afJohn McCall ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, 3874fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getDeclContext(), 3875fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getInnerLocStart(), 3876fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getLocation(), 3877fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getIdentifier(), 3878fb44de956f27875def889482b5393475060392afJohn McCall NewDI->getType(), 3879fb44de956f27875def889482b5393475060392afJohn McCall NewDI, 3880fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getStorageClass(), 3881fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getStorageClassAsWritten(), 3882fb44de956f27875def889482b5393475060392afJohn McCall /* DefArg */ NULL); 3883fb44de956f27875def889482b5393475060392afJohn McCall newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), 3884fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getFunctionScopeIndex() + indexAdjustment); 3885fb44de956f27875def889482b5393475060392afJohn McCall return newParm; 388621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall} 388721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 388821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived> 388921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallbool TreeTransform<Derived>:: 3890a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TransformFunctionTypeParams(SourceLocation Loc, 3891a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParmVarDecl **Params, unsigned NumParams, 3892a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor const QualType *ParamTypes, 3893686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<QualType> &OutParamTypes, 3894686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<ParmVarDecl*> *PVars) { 3895fb44de956f27875def889482b5393475060392afJohn McCall int indexAdjustment = 0; 3896fb44de956f27875def889482b5393475060392afJohn McCall 3897a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor for (unsigned i = 0; i != NumParams; ++i) { 3898a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (ParmVarDecl *OldParm = Params[i]) { 3899fb44de956f27875def889482b5393475060392afJohn McCall assert(OldParm->getFunctionScopeIndex() == i); 3900fb44de956f27875def889482b5393475060392afJohn McCall 39016a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor llvm::Optional<unsigned> NumExpansions; 3902406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor ParmVarDecl *NewParm = 0; 3903603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (OldParm->isParameterPack()) { 3904603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We have a function parameter pack that may need to be expanded. 3905686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<UnexpandedParameterPack, 2> Unexpanded; 3906603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3907603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Find the parameter packs that could be expanded. 3908c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); 3909c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL); 3910c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor TypeLoc Pattern = ExpansionTL.getPatternLoc(); 3911c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); 3912406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); 3913406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor 3914603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Determine whether we should expand the parameter packs. 3915603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor bool ShouldExpand = false; 3916d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 39176a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor llvm::Optional<unsigned> OrigNumExpansions 39186a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = ExpansionTL.getTypePtr()->getNumExpansions(); 39196a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NumExpansions = OrigNumExpansions; 3920c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), 3921c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor Pattern.getSourceRange(), 3922a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 3923d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ShouldExpand, 3924d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor RetainExpansion, 3925d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) { 3926603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 3927603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3928603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3929603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (ShouldExpand) { 3930603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Expand the function parameter pack into multiple, separate 3931603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // parameters. 393212c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor getDerived().ExpandingFunctionParameterPack(OldParm); 3933cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 3934603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 3935603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor ParmVarDecl *NewParm 39366a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = getDerived().TransformFunctionTypeParam(OldParm, 3937fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment++, 3938d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor OrigNumExpansions, 3939d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor /*ExpectParameterPack=*/false); 3940603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (!NewParm) 3941603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 3942603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3943a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewParm->getType()); 3944a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 3945a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(NewParm); 3946603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3947d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 3948d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 3949d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor // forgetting the partially-substituted parameter pack. 3950d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (RetainExpansion) { 3951d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 3952d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ParmVarDecl *NewParm 39536a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = getDerived().TransformFunctionTypeParam(OldParm, 3954fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment++, 3955d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor OrigNumExpansions, 3956d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor /*ExpectParameterPack=*/false); 3957d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (!NewParm) 3958d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor return true; 3959d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 3960d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor OutParamTypes.push_back(NewParm->getType()); 3961d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (PVars) 3962d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor PVars->push_back(NewParm); 3963d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor } 3964d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 3965fb44de956f27875def889482b5393475060392afJohn McCall // The next parameter should have the same adjustment as the 3966fb44de956f27875def889482b5393475060392afJohn McCall // last thing we pushed, but we post-incremented indexAdjustment 3967fb44de956f27875def889482b5393475060392afJohn McCall // on every push. Also, if we push nothing, the adjustment should 3968fb44de956f27875def889482b5393475060392afJohn McCall // go down by one. 3969fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment--; 3970fb44de956f27875def889482b5393475060392afJohn McCall 3971603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We're done with the pack expansion. 3972603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor continue; 3973603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3974603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3975603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We'll substitute the parameter now without expanding the pack 3976603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // expansion. 3977406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 3978406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewParm = getDerived().TransformFunctionTypeParam(OldParm, 3979fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment, 3980d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor NumExpansions, 3981d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor /*ExpectParameterPack=*/true); 3982406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor } else { 3983406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewParm = getDerived().TransformFunctionTypeParam(OldParm, 3984fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment, 3985d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor llvm::Optional<unsigned>(), 3986d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor /*ExpectParameterPack=*/false); 3987603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3988406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor 398921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall if (!NewParm) 399021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return true; 3991603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3992a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewParm->getType()); 3993a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 3994a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(NewParm); 3995603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor continue; 3996603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 3997a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3998a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Deal with the possibility that we don't have a parameter 3999a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // declaration for this parameter. 4000a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor QualType OldType = ParamTypes[i]; 4001603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor bool IsPackExpansion = false; 4002cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions; 4003406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor QualType NewType; 4004603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (const PackExpansionType *Expansion 4005603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor = dyn_cast<PackExpansionType>(OldType)) { 4006603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We have a function parameter pack that may need to be expanded. 4007603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor QualType Pattern = Expansion->getPattern(); 4008686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<UnexpandedParameterPack, 2> Unexpanded; 4009603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 4010603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4011603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Determine whether we should expand the parameter packs. 4012603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor bool ShouldExpand = false; 4013d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 4014a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), 4015a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 4016d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ShouldExpand, 4017d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor RetainExpansion, 4018d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) { 401921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return true; 4020603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4021603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4022603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (ShouldExpand) { 4023603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Expand the function parameter pack into multiple, separate 4024603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // parameters. 4025cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 4026603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 4027603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor QualType NewType = getDerived().TransformType(Pattern); 4028603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (NewType.isNull()) 4029603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 4030603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4031a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewType); 4032a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 4033a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(0); 4034603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4035603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4036603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We're done with the pack expansion. 4037603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor continue; 4038603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4039603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 40403cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 40413cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // forgetting the partially-substituted parameter pack. 40423cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (RetainExpansion) { 40433cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 40443cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor QualType NewType = getDerived().TransformType(Pattern); 40453cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (NewType.isNull()) 40463cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor return true; 40473cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 40483cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor OutParamTypes.push_back(NewType); 40493cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (PVars) 40503cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor PVars->push_back(0); 40513cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor } 4052d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 4053603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We'll substitute the parameter now without expanding the pack 4054603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // expansion. 4055603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor OldType = Expansion->getPattern(); 4056603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor IsPackExpansion = true; 4057406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 4058406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewType = getDerived().TransformType(OldType); 4059406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor } else { 4060406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewType = getDerived().TransformType(OldType); 4061a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4062603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4063603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (NewType.isNull()) 4064603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 40651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4066603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (IsPackExpansion) 4067cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NewType = getSema().Context.getPackExpansionType(NewType, 4068cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions); 4069603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4070a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewType); 4071a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 4072a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(0); 4073577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 40741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4075fb44de956f27875def889482b5393475060392afJohn McCall#ifndef NDEBUG 4076fb44de956f27875def889482b5393475060392afJohn McCall if (PVars) { 4077fb44de956f27875def889482b5393475060392afJohn McCall for (unsigned i = 0, e = PVars->size(); i != e; ++i) 4078fb44de956f27875def889482b5393475060392afJohn McCall if (ParmVarDecl *parm = (*PVars)[i]) 4079fb44de956f27875def889482b5393475060392afJohn McCall assert(parm->getFunctionScopeIndex() == i); 4080603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4081fb44de956f27875def889482b5393475060392afJohn McCall#endif 4082fb44de956f27875def889482b5393475060392afJohn McCall 4083fb44de956f27875def889482b5393475060392afJohn McCall return false; 4084fb44de956f27875def889482b5393475060392afJohn McCall} 408521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 408621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived> 408721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallQualType 408821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallTreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, 408943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FunctionProtoTypeLoc TL) { 40907e010a04fef171049291d8cb3047f118566da090Douglas Gregor // Transform the parameters and return type. 40917e010a04fef171049291d8cb3047f118566da090Douglas Gregor // 40927e010a04fef171049291d8cb3047f118566da090Douglas Gregor // We instantiate in source order, with the return type first followed by 40937e010a04fef171049291d8cb3047f118566da090Douglas Gregor // the parameters, because users tend to expect this (even if they shouldn't 40947e010a04fef171049291d8cb3047f118566da090Douglas Gregor // rely on it!). 40957e010a04fef171049291d8cb3047f118566da090Douglas Gregor // 4096dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // When the function has a trailing return type, we instantiate the 4097dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // parameters before the return type, since the return type can then refer 4098dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // to the parameters themselves (via decltype, sizeof, etc.). 4099dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // 4100686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<QualType, 4> ParamTypes; 4101686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<ParmVarDecl*, 4> ParamDecls; 4102f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const FunctionProtoType *T = TL.getTypePtr(); 41037e010a04fef171049291d8cb3047f118566da090Douglas Gregor 4104dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor QualType ResultType; 4105dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 4106dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (TL.getTrailingReturn()) { 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 ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 4115dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (ResultType.isNull()) 4116dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 4117dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor } 4118dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor else { 4119dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 4120dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (ResultType.isNull()) 4121dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 4122dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 4123a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), 4124a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getParmArray(), 4125a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getNumArgs(), 4126a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getTypePtr()->arg_type_begin(), 4127a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParamTypes, &ParamDecls)) 4128dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 4129dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor } 4130dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 4131a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4132a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4133a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ResultType != T->getResultType() || 4134bd5f9f708aa31920d3bd73aa10fcb5de424c657aDouglas Gregor T->getNumArgs() != ParamTypes.size() || 4135a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { 4136a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildFunctionProtoType(ResultType, 4137a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ParamTypes.data(), 4138a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ParamTypes.size(), 4139a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->isVariadic(), 4140fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman T->getTypeQuals(), 4141c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor T->getRefQualifier(), 4142fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman T->getExtInfo()); 4143a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4144a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4145a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 41461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4147a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); 4148796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); 4149796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); 4150dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor NewTL.setTrailingReturn(TL.getTrailingReturn()); 4151a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) 4152a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setArg(i, ParamDecls[i]); 4153a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4154a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4155577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 41561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4157577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4158577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformFunctionNoProtoType( 4159a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 416043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FunctionNoProtoTypeLoc TL) { 4161f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const FunctionNoProtoType *T = TL.getTypePtr(); 4162a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 4163a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (ResultType.isNull()) 4164a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4165a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4166a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4167a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4168a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ResultType != T->getResultType()) 4169a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildFunctionNoProtoType(ResultType); 4170a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4171a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); 4172796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); 4173796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); 4174dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor NewTL.setTrailingReturn(false); 4175a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4176a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4177577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 41781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4179ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> QualType 4180ed97649e9574b9d854fa4d6109c9333ae0993554John McCallTreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, 418143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall UnresolvedUsingTypeLoc TL) { 4182f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const UnresolvedUsingType *T = TL.getTypePtr(); 41837c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); 4184ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (!D) 4185ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return QualType(); 4186ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4187ed97649e9574b9d854fa4d6109c9333ae0993554John McCall QualType Result = TL.getType(); 4188ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (getDerived().AlwaysRebuild() || D != T->getDecl()) { 4189ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Result = getDerived().RebuildUnresolvedUsingType(D); 4190ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (Result.isNull()) 4191ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return QualType(); 4192ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 4193ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4194ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // We might get an arbitrary type spec type back. We should at 4195ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // least always get a type spec type, though. 4196ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); 4197ed97649e9574b9d854fa4d6109c9333ae0993554John McCall NewTL.setNameLoc(TL.getNameLoc()); 4198ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4199ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return Result; 4200ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 4201ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4202577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4203a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, 420443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypedefTypeLoc TL) { 4205f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const TypedefType *T = TL.getTypePtr(); 4206162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TypedefNameDecl *Typedef 4207162e1c1b487352434552147967c3dd296ebee2f7Richard Smith = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), 4208162e1c1b487352434552147967c3dd296ebee2f7Richard Smith T->getDecl())); 4209577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Typedef) 4210577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 42111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4212a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4213a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4214a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Typedef != T->getDecl()) { 4215a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildTypedefType(Typedef); 4216a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4217a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4218a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4219a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4220a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); 4221a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 42221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4223a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4224577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 42251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4226577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4227a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, 422843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeOfExprTypeLoc TL) { 4229670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // typeof expressions are not potentially evaluated contexts 4230f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 42311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 423260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); 4233577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (E.isInvalid()) 4234577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 4235577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 4236a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4237a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4238cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall E.get() != TL.getUnderlyingExpr()) { 42392a984cad5ac3fdceeff2bd99daa7b90979313475John McCall Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); 4240a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4241a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4242577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 4243a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall else E.take(); 42441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4245a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); 4246cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setTypeofLoc(TL.getTypeofLoc()); 4247cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setLParenLoc(TL.getLParenLoc()); 4248cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setRParenLoc(TL.getRParenLoc()); 4249a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4250a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4251577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 42521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4254a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, 425543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeOfTypeLoc TL) { 4256cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); 4257cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); 4258cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall if (!New_Under_TI) 4259577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 42601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4261a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4262cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { 4263cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); 4264a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4265a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4266a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 42671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4268a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); 4269cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setTypeofLoc(TL.getTypeofLoc()); 4270cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setLParenLoc(TL.getLParenLoc()); 4271cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setRParenLoc(TL.getRParenLoc()); 4272cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setUnderlyingTInfo(New_Under_TI); 4273a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4274a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4275577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 42761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4278a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, 427943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DecltypeTypeLoc TL) { 4280f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DecltypeType *T = TL.getTypePtr(); 4281a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4282670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // decltype expressions are not potentially evaluated contexts 4283f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 42841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 428560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); 4286577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (E.isInvalid()) 4287577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 42881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4289a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4290a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4291a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall E.get() != T->getUnderlyingExpr()) { 42922a984cad5ac3fdceeff2bd99daa7b90979313475John McCall Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); 4293a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4294a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4295577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 4296a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall else E.take(); 4297a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4298a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); 4299a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 43001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4301a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4302577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 4303577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 4304577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4305ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType TreeTransform<Derived>::TransformUnaryTransformType( 4306ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt TypeLocBuilder &TLB, 4307ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformTypeLoc TL) { 4308ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType Result = TL.getType(); 4309ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt if (Result->isDependentType()) { 4310ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt const UnaryTransformType *T = TL.getTypePtr(); 4311ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType NewBase = 4312ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); 4313ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Result = getDerived().RebuildUnaryTransformType(NewBase, 4314ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt T->getUTTKind(), 4315ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt TL.getKWLoc()); 4316ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt if (Result.isNull()) 4317ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return QualType(); 4318ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt } 4319ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 4320ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); 4321ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt NewTL.setKWLoc(TL.getKWLoc()); 4322ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt NewTL.setParensRange(TL.getParensRange()); 4323ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); 4324ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return Result; 4325ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt} 4326ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 4327ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunttemplate<typename Derived> 432834b41d939a1328f484511c6002ba2456db879a29Richard SmithQualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, 432934b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoTypeLoc TL) { 433034b41d939a1328f484511c6002ba2456db879a29Richard Smith const AutoType *T = TL.getTypePtr(); 433134b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType OldDeduced = T->getDeducedType(); 433234b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType NewDeduced; 433334b41d939a1328f484511c6002ba2456db879a29Richard Smith if (!OldDeduced.isNull()) { 433434b41d939a1328f484511c6002ba2456db879a29Richard Smith NewDeduced = getDerived().TransformType(OldDeduced); 433534b41d939a1328f484511c6002ba2456db879a29Richard Smith if (NewDeduced.isNull()) 433634b41d939a1328f484511c6002ba2456db879a29Richard Smith return QualType(); 433734b41d939a1328f484511c6002ba2456db879a29Richard Smith } 433834b41d939a1328f484511c6002ba2456db879a29Richard Smith 433934b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType Result = TL.getType(); 434034b41d939a1328f484511c6002ba2456db879a29Richard Smith if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) { 434134b41d939a1328f484511c6002ba2456db879a29Richard Smith Result = getDerived().RebuildAutoType(NewDeduced); 434234b41d939a1328f484511c6002ba2456db879a29Richard Smith if (Result.isNull()) 434334b41d939a1328f484511c6002ba2456db879a29Richard Smith return QualType(); 434434b41d939a1328f484511c6002ba2456db879a29Richard Smith } 434534b41d939a1328f484511c6002ba2456db879a29Richard Smith 434634b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); 434734b41d939a1328f484511c6002ba2456db879a29Richard Smith NewTL.setNameLoc(TL.getNameLoc()); 434834b41d939a1328f484511c6002ba2456db879a29Richard Smith 434934b41d939a1328f484511c6002ba2456db879a29Richard Smith return Result; 435034b41d939a1328f484511c6002ba2456db879a29Richard Smith} 435134b41d939a1328f484511c6002ba2456db879a29Richard Smith 435234b41d939a1328f484511c6002ba2456db879a29Richard Smithtemplate<typename Derived> 4353a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, 435443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall RecordTypeLoc TL) { 4355f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const RecordType *T = TL.getTypePtr(); 4356577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor RecordDecl *Record 43577c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), 43587c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor T->getDecl())); 4359577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Record) 4360577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 43611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4362a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4363a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4364a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Record != T->getDecl()) { 4365a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildRecordType(Record); 4366a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4367a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4368a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 43691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4370a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); 4371a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 4372a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4373a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4374577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 43751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 43761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4377a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, 437843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall EnumTypeLoc TL) { 4379f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const EnumType *T = TL.getTypePtr(); 4380577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor EnumDecl *Enum 43817c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), 43827c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor T->getDecl())); 4383577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Enum) 4384577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 43851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4386a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4387a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4388a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Enum != T->getDecl()) { 4389a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildEnumType(Enum); 4390a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4391a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4392a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4393a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4394a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); 4395a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 43961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4397a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4398577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 43997da2431c23ef1ee8acb114e39692246e1801afc2John McCall 44003cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCalltemplate<typename Derived> 44013cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallQualType TreeTransform<Derived>::TransformInjectedClassNameType( 44023cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TypeLocBuilder &TLB, 440343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall InjectedClassNameTypeLoc TL) { 44043cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall Decl *D = getDerived().TransformDecl(TL.getNameLoc(), 44053cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TL.getTypePtr()->getDecl()); 44063cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall if (!D) return QualType(); 44073cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 44083cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); 44093cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); 44103cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return T; 44113cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 44123cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 4413577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4414577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateTypeParmType( 4415a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 441643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateTypeParmTypeLoc TL) { 4417a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return TransformTypeSpecType(TLB, TL); 4418577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 4419577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 44201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 442149a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( 4422a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 442343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall SubstTemplateTypeParmTypeLoc TL) { 44240b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor const SubstTemplateTypeParmType *T = TL.getTypePtr(); 44250b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor 44260b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // Substitute into the replacement type, which itself might involve something 44270b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // that needs to be transformed. This only tends to occur with default 44280b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // template arguments of template template parameters. 44290b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); 44300b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor QualType Replacement = getDerived().TransformType(T->getReplacementType()); 44310b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor if (Replacement.isNull()) 44320b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor return QualType(); 44330b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor 44340b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // Always canonicalize the replacement type. 44350b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor Replacement = SemaRef.Context.getCanonicalType(Replacement); 44360b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor QualType Result 44370b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), 44380b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor Replacement); 44390b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor 44400b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // Propagate type-source information. 44410b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor SubstTemplateTypeParmTypeLoc NewTL 44420b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); 44430b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor NewTL.setNameLoc(TL.getNameLoc()); 44440b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor return Result; 44450b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor 444649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall} 444749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 444849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCalltemplate<typename Derived> 4449c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( 4450c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor TypeLocBuilder &TLB, 4451c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackTypeLoc TL) { 4452c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return TransformTypeSpecType(TLB, TL); 4453c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 4454c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 4455c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregortemplate<typename Derived> 4456833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallQualType TreeTransform<Derived>::TransformTemplateSpecializationType( 445743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeLocBuilder &TLB, 445843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateSpecializationTypeLoc TL) { 445943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall const TemplateSpecializationType *T = TL.getTypePtr(); 4460828bff2079b6a91ecd7ed5b842c59527d7682789John McCall 44611d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor // The nested-name-specifier never matters in a TemplateSpecializationType, 44621d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor // because we can't have a dependent nested-name-specifier anyway. 44631d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor CXXScopeSpec SS; 446443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template 44651d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor = getDerived().TransformTemplateName(SS, T->getTemplateName(), 44661d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor TL.getTemplateNameLoc()); 446743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (Template.isNull()) 446843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return QualType(); 4469833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 447043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); 4471dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor} 447243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 4473b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmantemplate<typename Derived> 4474b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli FriedmanQualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, 4475b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicTypeLoc TL) { 4476b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); 4477b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (ValueType.isNull()) 4478b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return QualType(); 4479b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4480b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType Result = TL.getType(); 4481b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (getDerived().AlwaysRebuild() || 4482b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman ValueType != TL.getValueLoc().getType()) { 4483b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); 4484b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (Result.isNull()) 4485b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return QualType(); 4486b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 4487b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4488b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); 4489b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman NewTL.setKWLoc(TL.getKWLoc()); 4490b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman NewTL.setLParenLoc(TL.getLParenLoc()); 4491b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman NewTL.setRParenLoc(TL.getRParenLoc()); 4492b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4493b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return Result; 4494b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman} 4495b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 44967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregornamespace { 44977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \brief Simple iterator that traverses the template arguments in a 44987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// container that provides a \c getArgLoc() member function. 44997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// 45007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// This iterator is intended to be used with the iterator form of 45017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \c TreeTransform<Derived>::TransformTemplateArguments(). 45027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor template<typename ArgLocContainer> 45037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class TemplateArgumentLocContainerIterator { 45047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgLocContainer *Container; 45057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor unsigned Index; 45067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 45087ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc value_type; 45097ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc reference; 45107ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef int difference_type; 45117ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef std::input_iterator_tag iterator_category; 45127ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class pointer { 45147ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Arg; 45157ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45167ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 45177ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } 45187ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45197ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLoc *operator->() const { 45207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return &Arg; 45217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 45227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 45237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator() {} 45267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator(ArgLocContainer &Container, 45287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor unsigned Index) 45297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor : Container(&Container), Index(Index) { } 45307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator &operator++() { 45327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++Index; 45337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return *this; 45347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 45357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator operator++(int) { 45377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator Old(*this); 45387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++(*this); 45397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Old; 45407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 45417ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc operator*() const { 45437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Container->getArgLoc(Index); 45447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 45457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor pointer operator->() const { 45477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return pointer(Container->getArgLoc(Index)); 45487ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 45497ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator==(const TemplateArgumentLocContainerIterator &X, 4551f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor const TemplateArgumentLocContainerIterator &Y) { 45527ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Container == Y.Container && X.Index == Y.Index; 45537ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 45547ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45557ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator!=(const TemplateArgumentLocContainerIterator &X, 4556f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor const TemplateArgumentLocContainerIterator &Y) { 45577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return !(X == Y); 45587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 45597ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 45607ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor} 45617ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 45627ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 456343fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate <typename Derived> 4564577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateSpecializationType( 4565833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TypeLocBuilder &TLB, 4566833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateSpecializationTypeLoc TL, 456743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template) { 4568d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo NewTemplateArgs; 4569d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 4570d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 45717ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> 45727ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgIterator; 45737ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 45747ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgIterator(TL, TL.getNumArgs()), 45757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor NewTemplateArgs)) 45767f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return QualType(); 45771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4578833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: maybe don't rebuild if all the template arguments are the same. 4579833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 4580833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall QualType Result = 4581833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall getDerived().RebuildTemplateSpecializationType(Template, 4582833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TL.getTemplateNameLoc(), 4583d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs); 45841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4585833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!Result.isNull()) { 45863e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // Specializations of template template parameters are represented as 45873e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // TemplateSpecializationTypes, and substitution of type alias templates 45883e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // within a dependent context can transform them into 45893e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // DependentTemplateSpecializationTypes. 45903e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (isa<DependentTemplateSpecializationType>(Result)) { 45913e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith DependentTemplateSpecializationTypeLoc NewTL 45923e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 45933e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setKeywordLoc(TL.getTemplateNameLoc()); 45943e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setQualifierLoc(NestedNameSpecifierLoc()); 45953e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setNameLoc(TL.getTemplateNameLoc()); 45963e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setLAngleLoc(TL.getLAngleLoc()); 45973e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setRAngleLoc(TL.getRAngleLoc()); 45983e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 45993e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 46003e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return Result; 46013e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 46023e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 4603833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateSpecializationTypeLoc NewTL 4604833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall = TLB.push<TemplateSpecializationTypeLoc>(Result); 4605833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 4606833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setLAngleLoc(TL.getLAngleLoc()); 4607833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setRAngleLoc(TL.getRAngleLoc()); 4608833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 4609833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 4610833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 46111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4612833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return Result; 4613577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 46141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4615a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregortemplate <typename Derived> 4616a88f09f34e86125ee4e6949a757aaed314012664Douglas GregorQualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( 4617a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TypeLocBuilder &TLB, 4618a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc TL, 4619087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor TemplateName Template, 4620087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor CXXScopeSpec &SS) { 4621a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateArgumentListInfo NewTemplateArgs; 4622a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 4623a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 4624a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor typedef TemplateArgumentLocContainerIterator< 4625a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc> ArgIterator; 4626a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 4627a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor ArgIterator(TL, TL.getNumArgs()), 4628a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs)) 4629a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return QualType(); 4630a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4631a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor // FIXME: maybe don't rebuild if all the template arguments are the same. 4632a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4633a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { 4634a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor QualType Result 4635a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = getSema().Context.getDependentTemplateSpecializationType( 4636a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TL.getTypePtr()->getKeyword(), 4637a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DTN->getQualifier(), 4638a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DTN->getIdentifier(), 4639a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs); 4640a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4641a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc NewTL 4642a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 4643a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setKeywordLoc(TL.getKeywordLoc()); 464494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 464594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); 4646a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setNameLoc(TL.getNameLoc()); 4647a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setLAngleLoc(TL.getLAngleLoc()); 4648a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setRAngleLoc(TL.getRAngleLoc()); 4649a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 4650a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 4651a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return Result; 4652a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor } 4653a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4654a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor QualType Result 4655a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = getDerived().RebuildTemplateSpecializationType(Template, 4656a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TL.getNameLoc(), 4657a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs); 4658a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4659a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (!Result.isNull()) { 4660a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor /// FIXME: Wrap this in an elaborated-type-specifier? 4661a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateSpecializationTypeLoc NewTL 4662a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = TLB.push<TemplateSpecializationTypeLoc>(Result); 4663a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setTemplateNameLoc(TL.getNameLoc()); 4664a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setLAngleLoc(TL.getLAngleLoc()); 4665a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setRAngleLoc(TL.getRAngleLoc()); 4666a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 4667a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 4668a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor } 4669a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4670a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return Result; 4671a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor} 4672a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 46731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4674a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 4675465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, 467643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ElaboratedTypeLoc TL) { 4677f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const ElaboratedType *T = TL.getTypePtr(); 4678465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 46799e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 4680465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara // NOTE: the qualifier in an ElaboratedType is optional. 46819e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor if (TL.getQualifierLoc()) { 46829e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc 46839e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 46849e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor if (!QualifierLoc) 4685465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return QualType(); 4686465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 46871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 468843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); 468943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (NamedT.isNull()) 469043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return QualType(); 4691a63db84b164d3f1c987a3ea6251e3092db4f317bDaniel Dunbar 46923e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // C++0x [dcl.type.elab]p2: 46933e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // If the identifier resolves to a typedef-name or the simple-template-id 46943e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // resolves to an alias template specialization, the 46953e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // elaborated-type-specifier is ill-formed. 46961804174e1591bf59118f317775b48edd0382c3f0Richard Smith if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { 46971804174e1591bf59118f317775b48edd0382c3f0Richard Smith if (const TemplateSpecializationType *TST = 46981804174e1591bf59118f317775b48edd0382c3f0Richard Smith NamedT->getAs<TemplateSpecializationType>()) { 46991804174e1591bf59118f317775b48edd0382c3f0Richard Smith TemplateName Template = TST->getTemplateName(); 47001804174e1591bf59118f317775b48edd0382c3f0Richard Smith if (TypeAliasTemplateDecl *TAT = 47011804174e1591bf59118f317775b48edd0382c3f0Richard Smith dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) { 47021804174e1591bf59118f317775b48edd0382c3f0Richard Smith SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), 47031804174e1591bf59118f317775b48edd0382c3f0Richard Smith diag::err_tag_reference_non_tag) << 4; 47041804174e1591bf59118f317775b48edd0382c3f0Richard Smith SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); 47051804174e1591bf59118f317775b48edd0382c3f0Richard Smith } 47063e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 47073e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 47083e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 4709a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4710a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 47119e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc != TL.getQualifierLoc() || 4712e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NamedT != T->getNamedType()) { 471321e413fe6305a198564d436ac515497716c47844John McCall Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(), 47149e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor T->getKeyword(), 47159e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc, NamedT); 4716a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4717a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4718a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4719577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 4720465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 4721e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setKeywordLoc(TL.getKeywordLoc()); 47229e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 4723a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4724577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 47251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 47261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 47279d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallQualType TreeTransform<Derived>::TransformAttributedType( 47289d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall TypeLocBuilder &TLB, 47299d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeLoc TL) { 47309d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall const AttributedType *oldType = TL.getTypePtr(); 47319d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); 47329d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (modifiedType.isNull()) 47339d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return QualType(); 47349d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 47359d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType result = TL.getType(); 47369d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 47379d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // FIXME: dependent operand expressions? 47389d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (getDerived().AlwaysRebuild() || 47399d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall modifiedType != oldType->getModifiedType()) { 47409d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // TODO: this is really lame; we should really be rebuilding the 47419d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // equivalent type from first principles. 47429d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType equivalentType 47439d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall = getDerived().TransformType(oldType->getEquivalentType()); 47449d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (equivalentType.isNull()) 47459d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return QualType(); 47469d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), 47479d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall modifiedType, 47489d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall equivalentType); 47499d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 47509d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 47519d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); 47529d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrNameLoc(TL.getAttrNameLoc()); 47539d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (TL.hasAttrOperand()) 47549d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); 47559d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (TL.hasAttrExprOperand()) 47569d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrExprOperand(TL.getAttrExprOperand()); 47579d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall else if (TL.hasAttrEnumOperand()) 47589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); 47599d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 47609d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return result; 47619d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall} 47629d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 47639d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCalltemplate<typename Derived> 4764075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType 4765075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraTreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, 4766075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenTypeLoc TL) { 4767075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); 4768075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (Inner.isNull()) 4769075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(); 4770075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 4771075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Result = TL.getType(); 4772075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (getDerived().AlwaysRebuild() || 4773075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Inner != TL.getInnerLoc().getType()) { 4774075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Result = getDerived().RebuildParenType(Inner); 4775075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (Result.isNull()) 4776075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(); 4777075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 4778075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 4779075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); 4780075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara NewTL.setLParenLoc(TL.getLParenLoc()); 4781075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara NewTL.setRParenLoc(TL.getRParenLoc()); 4782075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return Result; 4783075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 4784075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 4785075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaratemplate<typename Derived> 47864714c12a1ab759156b78be8f109ea4c12213af57Douglas GregorQualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, 478743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentNameTypeLoc TL) { 4788f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentNameType *T = TL.getTypePtr(); 4789833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 47902494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor NestedNameSpecifierLoc QualifierLoc 47912494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 47922494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor if (!QualifierLoc) 4793577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 47941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 479533500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Result 47962494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor = getDerived().RebuildDependentNameType(T->getKeyword(), 479733500955d731c73717af52088b7fc0e7a85681e7John McCall TL.getKeywordLoc(), 47982494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor QualifierLoc, 47992494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor T->getIdentifier(), 480033500955d731c73717af52088b7fc0e7a85681e7John McCall TL.getNameLoc()); 4801a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4802a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4803a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4804e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { 4805e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara QualType NamedT = ElabT->getNamedType(); 480633500955d731c73717af52088b7fc0e7a85681e7John McCall TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); 480733500955d731c73717af52088b7fc0e7a85681e7John McCall 4808e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 4809e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setKeywordLoc(TL.getKeywordLoc()); 48109e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 481133500955d731c73717af52088b7fc0e7a85681e7John McCall } else { 4812e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); 4813e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setKeywordLoc(TL.getKeywordLoc()); 48142494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 4815e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setNameLoc(TL.getNameLoc()); 4816e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 4817a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4818577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 48191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4820577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 482133500955d731c73717af52088b7fc0e7a85681e7John McCallQualType TreeTransform<Derived>:: 482233500955d731c73717af52088b7fc0e7a85681e7John McCall TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 482343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentTemplateSpecializationTypeLoc TL) { 482494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 482594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (TL.getQualifierLoc()) { 482694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualifierLoc 482794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 482894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (!QualifierLoc) 4829a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return QualType(); 4830a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor } 4831a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 483243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived() 483394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); 483443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall} 483543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 483643fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived> 483743fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>:: 483894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas GregorTransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 483994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor DependentTemplateSpecializationTypeLoc TL, 484094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NestedNameSpecifierLoc QualifierLoc) { 484194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor const DependentTemplateSpecializationType *T = TL.getTypePtr(); 484294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 484394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor TemplateArgumentListInfo NewTemplateArgs; 484494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 484594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 484694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 484794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor typedef TemplateArgumentLocContainerIterator< 484894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor DependentTemplateSpecializationTypeLoc> ArgIterator; 484994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 485094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor ArgIterator(TL, TL.getNumArgs()), 485194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs)) 485294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return QualType(); 485394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 485494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualType Result 485594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), 485694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualifierLoc, 485794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor T->getIdentifier(), 485894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor TL.getNameLoc(), 485994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs); 486094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (Result.isNull()) 486194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return QualType(); 486294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 486394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { 486494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualType NamedT = ElabT->getNamedType(); 486594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 486694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Copy information relevant to the template specialization. 486794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor TemplateSpecializationTypeLoc NamedTL 48680a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor = TLB.push<TemplateSpecializationTypeLoc>(NamedT); 4869a35d5d7700b519d713039afd31477e95e2da7aa7Chandler Carruth NamedTL.setTemplateNameLoc(TL.getNameLoc()); 487094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NamedTL.setLAngleLoc(TL.getLAngleLoc()); 487194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NamedTL.setRAngleLoc(TL.getRAngleLoc()); 4872944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 48730a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 487494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 487594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Copy information relevant to the elaborated type. 487694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 487794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTL.setKeywordLoc(TL.getKeywordLoc()); 487894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 48790a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor } else if (isa<DependentTemplateSpecializationType>(Result)) { 48800a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor DependentTemplateSpecializationTypeLoc SpecTL 48810a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 4882944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor SpecTL.setKeywordLoc(TL.getKeywordLoc()); 48830a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setQualifierLoc(QualifierLoc); 4884a35d5d7700b519d713039afd31477e95e2da7aa7Chandler Carruth SpecTL.setNameLoc(TL.getNameLoc()); 48850a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setLAngleLoc(TL.getLAngleLoc()); 48860a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setRAngleLoc(TL.getRAngleLoc()); 4887944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 48880a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 488994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor } else { 48900a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor TemplateSpecializationTypeLoc SpecTL 48910a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor = TLB.push<TemplateSpecializationTypeLoc>(Result); 4892a35d5d7700b519d713039afd31477e95e2da7aa7Chandler Carruth SpecTL.setTemplateNameLoc(TL.getNameLoc()); 48930a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setLAngleLoc(TL.getLAngleLoc()); 48940a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setRAngleLoc(TL.getRAngleLoc()); 4895944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 48960a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 489794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor } 489894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return Result; 489994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor} 490094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 490194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregortemplate<typename Derived> 49027536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas GregorQualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, 49037536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor PackExpansionTypeLoc TL) { 49042fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor QualType Pattern 49052fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor = getDerived().TransformType(TLB, TL.getPatternLoc()); 49062fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor if (Pattern.isNull()) 49072fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor return QualType(); 49082fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor 49092fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor QualType Result = TL.getType(); 49102fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor if (getDerived().AlwaysRebuild() || 49112fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor Pattern != TL.getPatternLoc().getType()) { 49122fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor Result = getDerived().RebuildPackExpansionType(Pattern, 49132fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor TL.getPatternLoc().getSourceRange(), 4914cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor TL.getEllipsisLoc(), 4915cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor TL.getTypePtr()->getNumExpansions()); 49162fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor if (Result.isNull()) 49172fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor return QualType(); 49182fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor } 49192fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor 49202fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); 49212fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor NewT.setEllipsisLoc(TL.getEllipsisLoc()); 49222fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor return Result; 49237536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor} 49247536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 49257536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregortemplate<typename Derived> 4926a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 4927a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, 492843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCInterfaceTypeLoc TL) { 4929ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor // ObjCInterfaceType is never dependent. 4930c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 4931c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return TL.getType(); 4932c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 4933c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 4934c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCalltemplate<typename Derived> 4935c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallQualType 4936c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallTreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, 493743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCObjectTypeLoc TL) { 4938c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // ObjCObjectType is never dependent. 4939c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 4940ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor return TL.getType(); 4941577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 49421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4944a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 4945a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, 494643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCObjectPointerTypeLoc TL) { 4947ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor // ObjCObjectPointerType is never dependent. 4948c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 4949ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor return TL.getType(); 495024fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis} 495124fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 4952577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 495343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor// Statement transformation 495443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===// 495543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 495660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 49571eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformNullStmt(NullStmt *S) { 49583fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 495943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 496043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 496143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 496260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 496343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { 496443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().TransformCompoundStmt(S, false); 496543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 496643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 496743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 496860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 49691eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, 497043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool IsStmtExpr) { 49717114cbab7eb6e8b714eb22f014327daf2c741c08John McCall bool SubStmtInvalid = false; 497243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool SubStmtChanged = false; 4973ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Stmt*> Statements(getSema()); 497443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); 497543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor B != BEnd; ++B) { 497660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Result = getDerived().TransformStmt(*B); 49777114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (Result.isInvalid()) { 49787114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // Immediately fail if this was a DeclStmt, since it's very 49797114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // likely that this will cause problems for future statements. 49807114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (isa<DeclStmt>(*B)) 49817114cbab7eb6e8b714eb22f014327daf2c741c08John McCall return StmtError(); 49827114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 49837114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // Otherwise, just keep processing substatements and fail later. 49847114cbab7eb6e8b714eb22f014327daf2c741c08John McCall SubStmtInvalid = true; 49857114cbab7eb6e8b714eb22f014327daf2c741c08John McCall continue; 49867114cbab7eb6e8b714eb22f014327daf2c741c08John McCall } 49871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 498843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SubStmtChanged = SubStmtChanged || Result.get() != *B; 498943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Statements.push_back(Result.takeAs<Stmt>()); 499043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 49911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49927114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (SubStmtInvalid) 49937114cbab7eb6e8b714eb22f014327daf2c741c08John McCall return StmtError(); 49947114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 499543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 499643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !SubStmtChanged) 49973fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 499843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 499943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildCompoundStmt(S->getLBracLoc(), 500043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor move_arg(Statements), 500143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getRBracLoc(), 500243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor IsStmtExpr); 500343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 50041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 500543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 500660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 50071eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { 500860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS, RHS; 5009264c1f8ec895952466eab59b84b8b06801e721faEli Friedman { 50106b3014b07c40a6ed8b0c8ed63950df02eeb82c28Eli Friedman EnterExpressionEvaluationContext Unevaluated(SemaRef, 50116b3014b07c40a6ed8b0c8ed63950df02eeb82c28Eli Friedman Sema::ConstantEvaluated); 50121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5013264c1f8ec895952466eab59b84b8b06801e721faEli Friedman // Transform the left-hand case value. 5014264c1f8ec895952466eab59b84b8b06801e721faEli Friedman LHS = getDerived().TransformExpr(S->getLHS()); 5015264c1f8ec895952466eab59b84b8b06801e721faEli Friedman if (LHS.isInvalid()) 5016f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5018264c1f8ec895952466eab59b84b8b06801e721faEli Friedman // Transform the right-hand case value (for the GNU case-range extension). 5019264c1f8ec895952466eab59b84b8b06801e721faEli Friedman RHS = getDerived().TransformExpr(S->getRHS()); 5020264c1f8ec895952466eab59b84b8b06801e721faEli Friedman if (RHS.isInvalid()) 5021f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5022264c1f8ec895952466eab59b84b8b06801e721faEli Friedman } 50231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 502443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Build the case statement. 502543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Case statements are always rebuilt so that they will attached to their 502643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transformed switch statement. 502760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), 50289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), 502943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getEllipsisLoc(), 50309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get(), 503143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getColonLoc()); 503243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Case.isInvalid()) 5033f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 503543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the statement following the case 503660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 503743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 5038f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 504043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Attach the body to the case statement 50419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); 504243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 504343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 504443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 504560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 50461eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { 504743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the statement following the default case 504860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 504943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 5050f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 505243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Default statements are always rebuilt 505343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), 50549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubStmt.get()); 505543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 50561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 505743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 505860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 50591eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { 506060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 506143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 5062f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 50631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 506457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), 506557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner S->getDecl()); 506657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner if (!LD) 506757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return StmtError(); 506857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 506957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 507043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // FIXME: Pass the real colon location in. 5071ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner return getDerived().RebuildLabelStmt(S->getIdentLoc(), 507257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner cast<LabelDecl>(LD), SourceLocation(), 507357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner SubStmt.get()); 507443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 50751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 507643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 507760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 50781eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIfStmt(IfStmt *S) { 507943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 508060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 50818cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor VarDecl *ConditionVar = 0; 50828cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor if (S->getConditionVariable()) { 5083c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 50848cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor = cast_or_null<VarDecl>( 5085aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5086aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5087aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 50888cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor if (!ConditionVar) 5089f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 509099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 50918cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 5092c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 509399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5094f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5095eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 5096eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor // Convert the condition to a boolean value. 5097afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 50988491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), 50998491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 5100afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 5101f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5102eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 51039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE.get(); 5104afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 510599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 5106c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 51079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 51089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 5109f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5110eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 511143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the "then" branch. 511260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Then = getDerived().TransformStmt(S->getThen()); 511343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Then.isInvalid()) 5114f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 511643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the "else" branch. 511760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Else = getDerived().TransformStmt(S->getElse()); 511843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Else.isInvalid()) 5119f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 512143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 51229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 512399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor ConditionVar == S->getConditionVariable() && 512443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Then.get() == S->getThen() && 512543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Else.get() == S->getElse()) 51263fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 51271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5128eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, 512944aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis Then.get(), 51309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall S->getElseLoc(), Else.get()); 513143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 513243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 513343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 513460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 51351eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { 513643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition. 513760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 5138d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor VarDecl *ConditionVar = 0; 5139d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor if (S->getConditionVariable()) { 5140c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 5141d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor = cast_or_null<VarDecl>( 5142aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5143aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5144aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 5145d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor if (!ConditionVar) 5146f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 514799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 5148d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 5149c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 515099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5151f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 515299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 51531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 515443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Rebuild the switch statement. 515560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Switch 51569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), 5157586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor ConditionVar); 515843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Switch.isInvalid()) 5159f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 516143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body of the switch statement. 516260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 516343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5164f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 516643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Complete the switch statement. 51679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), 51689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 516943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 51701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 517143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 517260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 51731eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { 517443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 517560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 51765656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor VarDecl *ConditionVar = 0; 51775656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor if (S->getConditionVariable()) { 5178c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 51795656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor = cast_or_null<VarDecl>( 5180aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5181aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5182aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 51835656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor if (!ConditionVar) 5184f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 518599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 51865656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 5187c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 518899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5189f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5190afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 5191afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 5192afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor // Convert the condition to a boolean value. 51938491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), 51948491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 5195afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 5196f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE; 5198afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 519999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 52001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 52029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 5203f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5204eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 520543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 520660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 520743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5208f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 521043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 52119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 521299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor ConditionVar == S->getConditionVariable() && 521343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 52149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Owned(S); 52151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5216eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, 52179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ConditionVar, Body.get()); 521843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 52191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 522043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 522160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 522243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformDoStmt(DoStmt *S) { 522343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 522460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 522543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5226f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5228eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor // Transform the condition 522960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(S->getCond()); 5230eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor if (Cond.isInvalid()) 5231f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5232eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 523343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 523443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Cond.get() == S->getCond() && 523543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 52363fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 52371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), 52399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall /*FIXME:*/S->getWhileLoc(), Cond.get(), 524043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getRParenLoc()); 524143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 52421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 524343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 524460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 52451eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformForStmt(ForStmt *S) { 524643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the initialization statement 524760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Init = getDerived().TransformStmt(S->getInit()); 524843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Init.isInvalid()) 5249f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 525143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 525260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 525399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor VarDecl *ConditionVar = 0; 525499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (S->getConditionVariable()) { 5255c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 525699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor = cast_or_null<VarDecl>( 5257aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5258aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5259aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 526099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (!ConditionVar) 5261f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 526299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 526399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 5264c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 526599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5266f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5267afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 5268afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 5269afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor // Convert the condition to a boolean value. 52708491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), 52718491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 5272afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 5273f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5274afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 52759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE.get(); 5276afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 527799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 52781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 52809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 5281f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5282eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 528343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the increment 528460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Inc = getDerived().TransformExpr(S->getInc()); 528543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Inc.isInvalid()) 5286f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get())); 52899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (S->getInc() && !FullInc.get()) 5290f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5291eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 529243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 529360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 529443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5295f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 529743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 529843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Init.get() == S->getInit() && 52999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 530043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Inc.get() == S->getInc() && 530143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 53023fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 53031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 530443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), 53059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init.get(), FullCond, ConditionVar, 53069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullInc, S->getRParenLoc(), Body.get()); 530743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 530843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 530943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 531060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 53111eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { 531257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), 531357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner S->getLabel()); 531457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner if (!LD) 531557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return StmtError(); 531657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 531743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Goto statements must always be rebuilt, to resolve the label. 53181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), 531957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner cast<LabelDecl>(LD)); 532043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 532143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 532243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 532360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 53241eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { 532560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Target = getDerived().TransformExpr(S->getTarget()); 532643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Target.isInvalid()) 5327f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5328d29975fd08713eb9d1777e60536addaa62df8995Eli Friedman Target = SemaRef.MaybeCreateExprWithCleanups(Target.take()); 53291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 533043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 533143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Target.get() == S->getTarget()) 53323fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 533343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 533443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), 53359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Target.get()); 533643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 533743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 533843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 533960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 53401eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { 53413fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 534243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 53431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 534443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 534560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 53461eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { 53473fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 534843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 53491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 535043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 535160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 53521eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { 535360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(S->getRetValue()); 535443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Result.isInvalid()) 5355f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 535643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 53571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // FIXME: We always rebuild the return statement because there is no way 535843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // to tell whether the return type of the function has changed. 53599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); 536043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 53611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 536243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 536360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 53641eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { 536543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool DeclChanged = false; 5366686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<Decl *, 4> Decls; 536743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); 536843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor D != DEnd; ++D) { 5369aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), 5370aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor *D); 537143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!Transformed) 5372f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 53731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 537443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Transformed != *D) 537543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor DeclChanged = true; 53761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 537743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Decls.push_back(Transformed); 537843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 53791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 538043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && !DeclChanged) 53813fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 53821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 53831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), 538443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getStartLoc(), S->getEndLoc()); 538543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 53861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 538743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 538860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 538943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { 5390c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5391ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Constraints(getSema()); 5392ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Exprs(getSema()); 5393686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<IdentifierInfo *, 4> Names; 5394a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson 539560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult AsmString; 5396ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Clobbers(getSema()); 5397703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5398703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool ExprsChanged = false; 5399c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5400703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the outputs. 5401703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { 5402ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson Names.push_back(S->getOutputIdentifier(I)); 5403c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5404703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the constraint literal. 54053fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Constraints.push_back(S->getOutputConstraintLiteral(I)); 5406c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5407703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Transform the output expr. 5408703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson Expr *OutputExpr = S->getOutputExpr(I); 540960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(OutputExpr); 5410703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (Result.isInvalid()) 5411f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5412c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5413703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson ExprsChanged |= Result.get() != OutputExpr; 5414c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 54159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs.push_back(Result.get()); 5416703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 5417c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5418703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the inputs. 5419703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { 5420ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson Names.push_back(S->getInputIdentifier(I)); 5421c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5422703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the constraint literal. 54233fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Constraints.push_back(S->getInputConstraintLiteral(I)); 5424c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5425703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Transform the input expr. 5426703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson Expr *InputExpr = S->getInputExpr(I); 542760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(InputExpr); 5428703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (Result.isInvalid()) 5429f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5430c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5431703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson ExprsChanged |= Result.get() != InputExpr; 5432c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 54339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs.push_back(Result.get()); 5434703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 5435c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5436703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (!getDerived().AlwaysRebuild() && !ExprsChanged) 54373fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 5438703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5439703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the clobbers. 5440703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) 54413fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Clobbers.push_back(S->getClobber(I)); 5442703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5443703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the asm string literal. 5444703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson AsmString = SemaRef.Owned(S->getAsmString()); 5445703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5446703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson return getDerived().RebuildAsmStmt(S->getAsmLoc(), 5447703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isSimple(), 5448703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isVolatile(), 5449703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getNumOutputs(), 5450703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getNumInputs(), 5451a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson Names.data(), 5452703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson move_arg(Constraints), 5453703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson move_arg(Exprs), 54549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall AsmString.get(), 5455703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson move_arg(Clobbers), 5456703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getRParenLoc(), 5457703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isMSAsm()); 545843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 545943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 546043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 546143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 546260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 54631eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { 54644dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the body of the @try. 546560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); 54664dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (TryBody.isInvalid()) 5467f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5468c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 54698f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor // Transform the @catch statements (if present). 54708f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor bool AnyCatchChanged = false; 5471ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Stmt*> CatchStmts(SemaRef); 54728f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { 547360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); 54744dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Catch.isInvalid()) 5475f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 54768f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor if (Catch.get() != S->getCatchStmt(I)) 54778f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor AnyCatchChanged = true; 54788f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor CatchStmts.push_back(Catch.release()); 54794dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 5480c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 54814dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the @finally statement (if present). 548260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Finally; 54834dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (S->getFinallyStmt()) { 54844dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Finally = getDerived().TransformStmt(S->getFinallyStmt()); 54854dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Finally.isInvalid()) 5486f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 54874dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 54884dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 54894dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // If nothing changed, just retain this statement. 54904dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (!getDerived().AlwaysRebuild() && 54914dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor TryBody.get() == S->getTryBody() && 54928f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor !AnyCatchChanged && 54934dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Finally.get() == S->getFinallyStmt()) 54943fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 5495c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 54964dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Build a new statement. 54979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), 54989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall move_arg(CatchStmts), Finally.get()); 549943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 55001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 550143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 550260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 55031eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { 5504be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor // Transform the @catch parameter, if there is one. 5505be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *Var = 0; 5506be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (VarDecl *FromVar = S->getCatchParamDecl()) { 5507be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TypeSourceInfo *TSInfo = 0; 5508be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (FromVar->getTypeSourceInfo()) { 5509be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); 5510be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (!TSInfo) 5511f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5512be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 5513c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5514be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor QualType T; 5515be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (TSInfo) 5516be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor T = TSInfo->getType(); 5517be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor else { 5518be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor T = getDerived().TransformType(FromVar->getType()); 5519be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (T.isNull()) 5520f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5521be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 5522c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5523be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); 5524be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (!Var) 5525f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5526be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 5527c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 552860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); 5529be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (Body.isInvalid()) 5530f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5531c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5532c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), 5533be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor S->getRParenLoc(), 55349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Var, Body.get()); 553543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 55361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 553743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 553860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 55391eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { 55404dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the body. 554160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); 55424dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Body.isInvalid()) 5543f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5544c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 55454dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // If nothing changed, just retain this statement. 55464dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (!getDerived().AlwaysRebuild() && 55474dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Body.get() == S->getFinallyBody()) 55483fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 55494dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 55504dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Build a new statement. 55514dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), 55529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 555343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 55541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 555543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 555660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 55571eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { 555860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Operand; 5559d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (S->getThrowExpr()) { 5560d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor Operand = getDerived().TransformExpr(S->getThrowExpr()); 5561d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (Operand.isInvalid()) 5562f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5563d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor } 5564c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5565d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (!getDerived().AlwaysRebuild() && 5566d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor Operand.get() == S->getThrowExpr()) 55673fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return getSema().Owned(S); 5568c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 55699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); 557043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 55711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 557243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 557360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 557443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCAtSynchronizedStmt( 55751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCAtSynchronizedStmt *S) { 55768fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Transform the object we are locking. 557760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); 55788fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (Object.isInvalid()) 5579f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 558007524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Object = 558107524039dce5c820f111a1b3f772b4261f004b4aJohn McCall getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), 558207524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Object.get()); 558307524039dce5c820f111a1b3f772b4261f004b4aJohn McCall if (Object.isInvalid()) 558407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall return StmtError(); 5585c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 55868fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Transform the body. 558760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); 55888fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (Body.isInvalid()) 5589f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5590c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 55918fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // If nothing change, just retain the current statement. 55928fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (!getDerived().AlwaysRebuild() && 55938fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor Object.get() == S->getSynchExpr() && 55948fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor Body.get() == S->getSynchBody()) 55953fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 55968fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor 55978fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Build a new statement. 55988fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), 55999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Object.get(), Body.get()); 560043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 560143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 560243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 560360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 5604f85e193739c953358c865005855253af4f68a497John McCallTreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( 5605f85e193739c953358c865005855253af4f68a497John McCall ObjCAutoreleasePoolStmt *S) { 5606f85e193739c953358c865005855253af4f68a497John McCall // Transform the body. 5607f85e193739c953358c865005855253af4f68a497John McCall StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); 5608f85e193739c953358c865005855253af4f68a497John McCall if (Body.isInvalid()) 5609f85e193739c953358c865005855253af4f68a497John McCall return StmtError(); 5610f85e193739c953358c865005855253af4f68a497John McCall 5611f85e193739c953358c865005855253af4f68a497John McCall // If nothing changed, just retain this statement. 5612f85e193739c953358c865005855253af4f68a497John McCall if (!getDerived().AlwaysRebuild() && 5613f85e193739c953358c865005855253af4f68a497John McCall Body.get() == S->getSubStmt()) 5614f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(S); 5615f85e193739c953358c865005855253af4f68a497John McCall 5616f85e193739c953358c865005855253af4f68a497John McCall // Build a new statement. 5617f85e193739c953358c865005855253af4f68a497John McCall return getDerived().RebuildObjCAutoreleasePoolStmt( 5618f85e193739c953358c865005855253af4f68a497John McCall S->getAtLoc(), Body.get()); 5619f85e193739c953358c865005855253af4f68a497John McCall} 5620f85e193739c953358c865005855253af4f68a497John McCall 5621f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived> 5622f85e193739c953358c865005855253af4f68a497John McCallStmtResult 562343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCForCollectionStmt( 56241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCForCollectionStmt *S) { 5625c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the element statement. 562660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Element = getDerived().TransformStmt(S->getElement()); 5627c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Element.isInvalid()) 5628f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5629c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5630c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the collection expression. 563160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Collection = getDerived().TransformExpr(S->getCollection()); 5632c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Collection.isInvalid()) 5633f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5634990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(), 5635990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall Collection.take()); 5636990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall if (Collection.isInvalid()) 5637990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall return StmtError(); 5638c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5639c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the body. 564060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 5641c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Body.isInvalid()) 5642f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5643c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5644c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // If nothing changed, just retain this statement. 5645c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (!getDerived().AlwaysRebuild() && 5646c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Element.get() == S->getElement() && 5647c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Collection.get() == S->getCollection() && 5648c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Body.get() == S->getBody()) 56493fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 5650c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5651c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Build a new statement. 5652c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), 5653c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /*FIXME:*/S->getForLoc(), 56549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Element.get(), 56559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Collection.get(), 5656c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor S->getRParenLoc(), 56579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 565843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 565943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 566043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 566143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 566260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 566343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { 566443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the exception declaration, if any. 566543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor VarDecl *Var = 0; 566643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (S->getExceptionDecl()) { 566743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor VarDecl *ExceptionDecl = S->getExceptionDecl(); 566883cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor TypeSourceInfo *T = getDerived().TransformType( 566983cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor ExceptionDecl->getTypeSourceInfo()); 567083cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor if (!T) 5671f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 56721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 567383cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, 5674ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getInnerLocStart(), 5675ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getLocation(), 5676ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getIdentifier()); 5677ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor if (!Var || Var->isInvalidDecl()) 5678f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 567943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 56801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 568143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the actual exception handler. 568260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); 5683ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor if (Handler.isInvalid()) 5684f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 56851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 568643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 568743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !Var && 568843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Handler.get() == S->getHandlerBlock()) 56893fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 569043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 569143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), 569243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Var, 56939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Handler.get()); 569443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 56951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 569643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 569760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 569843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { 569943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the try block itself. 570060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TryBlock 570143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor = getDerived().TransformCompoundStmt(S->getTryBlock()); 570243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (TryBlock.isInvalid()) 5703f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 57041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 570543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the handlers. 570643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool HandlerChanged = false; 5707ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Stmt*> Handlers(SemaRef); 570843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { 570960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Handler 571043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor = getDerived().TransformCXXCatchStmt(S->getHandler(I)); 571143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Handler.isInvalid()) 5712f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 57131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 571443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); 571543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Handlers.push_back(Handler.takeAs<Stmt>()); 571643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 57171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 571843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 571943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor TryBlock.get() == S->getTryBlock() && 572043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !HandlerChanged) 57213fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 572243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 57239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), 57241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump move_arg(Handlers)); 572543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 57261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5727ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate<typename Derived> 5728ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithStmtResult 5729ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithTreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { 5730ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); 5731ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Range.isInvalid()) 5732ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5733ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5734ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt()); 5735ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (BeginEnd.isInvalid()) 5736ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5737ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5738ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ExprResult Cond = getDerived().TransformExpr(S->getCond()); 5739ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Cond.isInvalid()) 5740ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5741c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman if (Cond.get()) 5742c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc()); 5743c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman if (Cond.isInvalid()) 5744c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman return StmtError(); 5745c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman if (Cond.get()) 5746c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take()); 5747ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5748ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ExprResult Inc = getDerived().TransformExpr(S->getInc()); 5749ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Inc.isInvalid()) 5750ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5751c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman if (Inc.get()) 5752c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take()); 5753ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5754ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); 5755ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (LoopVar.isInvalid()) 5756ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5757ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5758ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult NewStmt = S; 5759ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (getDerived().AlwaysRebuild() || 5760ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Range.get() != S->getRangeStmt() || 5761ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith BeginEnd.get() != S->getBeginEndStmt() || 5762ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Cond.get() != S->getCond() || 5763ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Inc.get() != S->getInc() || 5764ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith LoopVar.get() != S->getLoopVarStmt()) 5765ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), 5766ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getColonLoc(), Range.get(), 5767ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith BeginEnd.get(), Cond.get(), 5768ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Inc.get(), LoopVar.get(), 5769ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getRParenLoc()); 5770ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5771ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult Body = getDerived().TransformStmt(S->getBody()); 5772ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Body.isInvalid()) 5773ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5774ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5775ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith // Body has changed but we didn't rebuild the for-range statement. Rebuild 5776ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith // it now so we have a new statement to attach the body to. 5777ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Body.get() != S->getBody() && NewStmt.get() == S) 5778ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), 5779ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getColonLoc(), Range.get(), 5780ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith BeginEnd.get(), Cond.get(), 5781ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Inc.get(), LoopVar.get(), 5782ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getRParenLoc()); 5783ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5784ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (NewStmt.get() == S) 5785ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return SemaRef.Owned(S); 5786ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5787ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); 5788ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith} 5789ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 579028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 579128bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 5792ba0513de93d2fab6db5ab30b6927209fcc883078Douglas GregorTreeTransform<Derived>::TransformMSDependentExistsStmt( 5793ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor MSDependentExistsStmt *S) { 5794ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // Transform the nested-name-specifier, if any. 5795ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 5796ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (S->getQualifierLoc()) { 5797ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor QualifierLoc 5798ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); 5799ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (!QualifierLoc) 5800ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return StmtError(); 5801ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor } 5802ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5803ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // Transform the declaration name. 5804ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor DeclarationNameInfo NameInfo = S->getNameInfo(); 5805ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (NameInfo.getName()) { 5806ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 5807ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (!NameInfo.getName()) 5808ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return StmtError(); 5809ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor } 5810ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5811ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // Check whether anything changed. 5812ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (!getDerived().AlwaysRebuild() && 5813ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor QualifierLoc == S->getQualifierLoc() && 5814ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NameInfo.getName() == S->getNameInfo().getName()) 5815ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return S; 5816ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5817ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // Determine whether this name exists, if we can. 5818ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor CXXScopeSpec SS; 5819ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor SS.Adopt(QualifierLoc); 5820ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor bool Dependent = false; 5821ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) { 5822ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor case Sema::IER_Exists: 5823ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (S->isIfExists()) 5824ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor break; 5825ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5826ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return new (getSema().Context) NullStmt(S->getKeywordLoc()); 5827ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5828ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor case Sema::IER_DoesNotExist: 5829ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (S->isIfNotExists()) 5830ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor break; 5831ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5832ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return new (getSema().Context) NullStmt(S->getKeywordLoc()); 5833ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5834ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor case Sema::IER_Dependent: 5835ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor Dependent = true; 5836ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor break; 583765019acfc46ffb191fac4e781ac0c4b8d0c8434eDouglas Gregor 583865019acfc46ffb191fac4e781ac0c4b8d0c8434eDouglas Gregor case Sema::IER_Error: 583965019acfc46ffb191fac4e781ac0c4b8d0c8434eDouglas Gregor return StmtError(); 5840ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor } 5841ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5842ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // We need to continue with the instantiation, so do so now. 5843ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); 5844ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (SubStmt.isInvalid()) 5845ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return StmtError(); 5846ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5847ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // If we have resolved the name, just transform to the substatement. 5848ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (!Dependent) 5849ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return SubStmt; 5850ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5851ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // The name is still dependent, so build a dependent expression again. 5852ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), 5853ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor S->isIfExists(), 5854ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor QualifierLoc, 5855ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NameInfo, 5856ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor SubStmt.get()); 5857ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor} 5858ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5859ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregortemplate<typename Derived> 5860ba0513de93d2fab6db5ab30b6927209fcc883078Douglas GregorStmtResult 586128bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { 586228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock()); 586328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(TryBlock.isInvalid()) return StmtError(); 586428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 586528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); 586628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(!getDerived().AlwaysRebuild() && 586728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley TryBlock.get() == S->getTryBlock() && 586828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Handler.get() == S->getHandler()) 586928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return SemaRef.Owned(S); 587028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 587128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), 587228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley S->getTryLoc(), 587328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley TryBlock.take(), 587428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Handler.take()); 587528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 587628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 587728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 587828bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 587928bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { 588028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); 588128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(Block.isInvalid()) return StmtError(); 588228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 588328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), 588428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Block.take()); 588528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 588628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 588728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 588828bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 588928bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { 589028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); 589128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(FilterExpr.isInvalid()) return StmtError(); 589228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 589328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); 589428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(Block.isInvalid()) return StmtError(); 589528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 589628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), 589728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley FilterExpr.take(), 589828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Block.take()); 589928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 590028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 590128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 590228bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 590328bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { 590428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(isa<SEHFinallyStmt>(Handler)) 590528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); 590628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley else 590728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); 590828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 590928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 591043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===// 5911b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Expression transformation 5912577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 59131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 591460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5915454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { 59163fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 59171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 59181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 59191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 592060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5921454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { 592240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc; 592340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (E->getQualifierLoc()) { 592440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc 592540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 592640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!QualifierLoc) 5927f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5928a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 5929dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 5930dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *ND 59317c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), 59327c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getDecl())); 5933b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!ND) 5934f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 59351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5936ec8045d3f0375302eadaa63deb373bacaf25a569John McCall DeclarationNameInfo NameInfo = E->getNameInfo(); 5937ec8045d3f0375302eadaa63deb373bacaf25a569John McCall if (NameInfo.getName()) { 5938ec8045d3f0375302eadaa63deb373bacaf25a569John McCall NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 5939ec8045d3f0375302eadaa63deb373bacaf25a569John McCall if (!NameInfo.getName()) 5940f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5941ec8045d3f0375302eadaa63deb373bacaf25a569John McCall } 59422577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 59432577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!getDerived().AlwaysRebuild() && 594440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc == E->getQualifierLoc() && 5945a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor ND == E->getDecl() && 59462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getDecl()->getDeclName() && 5947096832c5ed5b9106fa177ebc148489760c3bc496John McCall !E->hasExplicitTemplateArgs()) { 59481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5949dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // Mark it referenced in the new context regardless. 5950dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // FIXME: this is a bit instantiation-specific. 59515f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkDeclRefReferenced(E); 5952a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 59533fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5954a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 5955dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 5956dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; 5957096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (E->hasExplicitTemplateArgs()) { 5958dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TemplateArgs = &TransArgs; 5959dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TransArgs.setLAngleLoc(E->getLAngleLoc()); 5960dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TransArgs.setRAngleLoc(E->getRAngleLoc()); 5961fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 5962fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 5963fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 5964fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 5965dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall } 5966dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 596740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, 596840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor TemplateArgs); 5969577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 59701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5971b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 597260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5973454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { 59743fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5975577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 59761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5977b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 597860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5979454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { 59803fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5981b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 59821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5983b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 598460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5985454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { 59863fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5987b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 59881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 59891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 599060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5991454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { 59923fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5993b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 59941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5995b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 599660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5997454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { 59983fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5999b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 60001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6001b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 600260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6003f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneTreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { 6004f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult ControllingExpr = 6005f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne getDerived().TransformExpr(E->getControllingExpr()); 6006f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (ControllingExpr.isInvalid()) 6007f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ExprError(); 6008f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 6009686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<Expr *, 4> AssocExprs; 6010686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<TypeSourceInfo *, 4> AssocTypes; 6011f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne for (unsigned i = 0; i != E->getNumAssocs(); ++i) { 6012f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); 6013f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (TS) { 6014f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo *AssocType = getDerived().TransformType(TS); 6015f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!AssocType) 6016f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ExprError(); 6017f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes.push_back(AssocType); 6018f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } else { 6019f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes.push_back(0); 6020f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 6021f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 6022f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); 6023f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (AssocExpr.isInvalid()) 6024f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ExprError(); 6025f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs.push_back(AssocExpr.release()); 6026f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 6027f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 6028f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), 6029f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E->getDefaultLoc(), 6030f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E->getRParenLoc(), 6031f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ControllingExpr.release(), 6032f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes.data(), 6033f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs.data(), 6034f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E->getNumAssocs()); 6035f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne} 6036f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 6037f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbournetemplate<typename Derived> 6038f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneExprResult 6039454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { 604060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 6041b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6042f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 60431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6044b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) 60453fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 60461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), 6048b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParen()); 6049b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6050b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 60511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 605260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6053454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { 605460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 6055b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6056f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 60571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6058b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) 60593fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 60601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6061b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), 6062b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOpcode(), 60639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get()); 6064b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 60651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6066b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 606760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 60688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorTreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { 60698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Transform the type. 60708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); 60718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (!Type) 6072f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6073c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 60748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Transform all of the components into components similar to what the 60758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // parser uses. 6076c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // FIXME: It would be slightly more efficient in the non-dependent case to 6077c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // just map FieldDecls, rather than requiring the rebuilder to look for 6078c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // the fields again. However, __builtin_offsetof is rare enough in 60798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // template code that we don't care. 60808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor bool ExprChanged = false; 6081f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall typedef Sema::OffsetOfComponent Component; 60828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor typedef OffsetOfExpr::OffsetOfNode Node; 6083686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<Component, 4> Components; 60848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { 60858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor const Node &ON = E->getComponent(I); 60868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Component Comp; 608772be24f39c162448e53dd73cf57cc6357114361eDouglas Gregor Comp.isBrackets = true; 608806dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara Comp.LocStart = ON.getSourceRange().getBegin(); 608906dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara Comp.LocEnd = ON.getSourceRange().getEnd(); 60908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor switch (ON.getKind()) { 60918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Array: { 60928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); 609360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Index = getDerived().TransformExpr(FromIndex); 60948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (Index.isInvalid()) 6095f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6096c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 60978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor ExprChanged = ExprChanged || Index.get() != FromIndex; 60988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.isBrackets = true; 60999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Comp.U.E = Index.get(); 61008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor break; 61018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 6102c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 61038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Field: 61048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Identifier: 61058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.isBrackets = false; 61068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.U.IdentInfo = ON.getFieldName(); 610729d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor if (!Comp.U.IdentInfo) 610829d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor continue; 6109c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 61108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor break; 6111c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6112cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor case Node::Base: 6113cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor // Will be recomputed during the rebuild. 6114cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor continue; 61158ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 6116c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 61178ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Components.push_back(Comp); 61188ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 6119c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 61208ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // If nothing changed, retain the existing expression. 61218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (!getDerived().AlwaysRebuild() && 61228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Type == E->getTypeSourceInfo() && 61238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor !ExprChanged) 61243fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6125c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 61268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Build a new offsetof expression. 61278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, 61288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Components.data(), Components.size(), 61298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor E->getRParenLoc()); 61307cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall} 61317cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall 61327cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCalltemplate<typename Derived> 61337cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallExprResult 61347cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallTreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { 61357cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall assert(getDerived().AlreadyTransformed(E->getType()) && 61367cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall "opaque value expression requires transformation"); 61377cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall return SemaRef.Owned(E); 61388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 61398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 61408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregortemplate<typename Derived> 614160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 61424b9c2d235fb9449e249d74f48ecfec601650de93John McCallTreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { 614301e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // Rebuild the syntactic form. The original syntactic form has 614401e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // opaque-value expressions in it, so strip those away and rebuild 614501e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // the result. This is a really awful way of doing this, but the 614601e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // better solution (rebuilding the semantic expressions and 614701e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // rebinding OVEs as necessary) doesn't work; we'd need 614801e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // TreeTransform to not strip away implicit conversions. 614901e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); 615001e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall ExprResult result = getDerived().TransformExpr(newSyntacticForm); 61514b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (result.isInvalid()) return ExprError(); 61524b9c2d235fb9449e249d74f48ecfec601650de93John McCall 61534b9c2d235fb9449e249d74f48ecfec601650de93John McCall // If that gives us a pseudo-object result back, the pseudo-object 61544b9c2d235fb9449e249d74f48ecfec601650de93John McCall // expression must have been an lvalue-to-rvalue conversion which we 61554b9c2d235fb9449e249d74f48ecfec601650de93John McCall // should reapply. 61564b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) 61574b9c2d235fb9449e249d74f48ecfec601650de93John McCall result = SemaRef.checkPseudoObjectRValue(result.take()); 61584b9c2d235fb9449e249d74f48ecfec601650de93John McCall 61594b9c2d235fb9449e249d74f48ecfec601650de93John McCall return result; 61604b9c2d235fb9449e249d74f48ecfec601650de93John McCall} 61614b9c2d235fb9449e249d74f48ecfec601650de93John McCall 61624b9c2d235fb9449e249d74f48ecfec601650de93John McCalltemplate<typename Derived> 61634b9c2d235fb9449e249d74f48ecfec601650de93John McCallExprResult 6164f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter CollingbourneTreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( 6165f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr *E) { 6166b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->isArgumentType()) { 6167a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *OldT = E->getArgumentTypeInfo(); 61685557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor 6169a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *NewT = getDerived().TransformType(OldT); 61705ab75172051a6d2ea71a80a79e81c65519fd3462John McCall if (!NewT) 6171f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61735ab75172051a6d2ea71a80a79e81c65519fd3462John McCall if (!getDerived().AlwaysRebuild() && OldT == NewT) 61743fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 61751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6176f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), 6177f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getKind(), 6178f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getSourceRange()); 6179b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 61801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 618160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr; 61821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump { 6183b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // C++0x [expr.sizeof]p1: 6184b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // The operand is either an expression, which is an unevaluated operand 6185b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // [...] 6186f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 61871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6188b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); 6189b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6190f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6192b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) 61933fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6194b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 61951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6196f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), 6197f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getOperatorLoc(), 6198f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getKind(), 6199f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getSourceRange()); 6200b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 62011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6202b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 620360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6204454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { 620560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6206b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6207f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 620960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6210b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6211f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6214b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6215b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6216b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 62173fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 62181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildArraySubscriptExpr(LHS.get(), 6220b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLHS()->getLocStart(), 62219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get(), 6222b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRBracketLoc()); 6223b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 62241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 622660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6227454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCallExpr(CallExpr *E) { 6228b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the callee. 622960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 6230b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Callee.isInvalid()) 6231f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6232b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6233b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform arguments. 6234b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgChanged = false; 6235ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 6236aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 6237aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgChanged)) 6238aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6239aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 6240b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6241b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Callee.get() == E->getCallee() && 6242b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgChanged) 624392be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E);; 62441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6245b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Wrong source location information for the '('. 62461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeLParenLoc 6247b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = ((Expr *)Callee.get())->getSourceRange().getBegin(); 62489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, 6249b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Args), 6250b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6251b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 62521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 625460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6255454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { 625660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 6257b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Base.isInvalid()) 6258f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 626040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc; 626183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor if (E->hasQualifier()) { 626240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc 626340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 626440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 626540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!QualifierLoc) 6266f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 626783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 6268e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); 62691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6270f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *Member 62717c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), 62727c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getMemberDecl())); 6273b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Member) 6274f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62766bb8017bb9e828d118e15e59d71c66bba323c364John McCall NamedDecl *FoundDecl = E->getFoundDecl(); 62776bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (FoundDecl == E->getMemberDecl()) { 62786bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl = Member; 62796bb8017bb9e828d118e15e59d71c66bba323c364John McCall } else { 62806bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl = cast_or_null<NamedDecl>( 62816bb8017bb9e828d118e15e59d71c66bba323c364John McCall getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); 62826bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!FoundDecl) 6283f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62846bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 62856bb8017bb9e828d118e15e59d71c66bba323c364John McCall 6286b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6287b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Base.get() == E->getBase() && 628840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc == E->getQualifierLoc() && 62898a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor Member == E->getMemberDecl() && 62906bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl == E->getFoundDecl() && 6291096832c5ed5b9106fa177ebc148489760c3bc496John McCall !E->hasExplicitTemplateArgs()) { 6292c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 62931f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson // Mark it referenced in the new context regardless. 62941f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson // FIXME: this is a bit instantiation-specific. 62955f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkMemberReferenced(E); 62965f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman 62973fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 62981f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson } 6299b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6300d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs; 6301096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (E->hasExplicitTemplateArgs()) { 6302d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TransArgs.setLAngleLoc(E->getLAngleLoc()); 6303d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TransArgs.setRAngleLoc(E->getRAngleLoc()); 6304fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 6305fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 6306fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 6307fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 63088a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor } 6309c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6310b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Bogus source location for the operator 6311b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeOperatorLoc 6312b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); 6313b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6314c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // FIXME: to do this check properly, we will need to preserve the 6315c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // first-qualifier-in-scope here, just in case we had a dependent 6316c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // base (and therefore couldn't do the check) and a 6317c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // nested-name-qualifier (and therefore could do the lookup). 6318c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall NamedDecl *FirstQualifierInScope = 0; 6319c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 63209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, 6321b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrow(), 632240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc, 6323e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateKWLoc, 63242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara E->getMemberNameInfo(), 63258a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor Member, 63266bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl, 6327096832c5ed5b9106fa177ebc148489760c3bc496John McCall (E->hasExplicitTemplateArgs() 6328d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall ? &TransArgs : 0), 6329c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall FirstQualifierInScope); 6330b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 63311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6332b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 633360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6334454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { 633560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6336b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6337f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 633960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6340b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6341f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6343b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6344b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6345b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 63463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 63471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6348b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), 63499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), RHS.get()); 6350b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6351b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 63521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 635360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6354b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCompoundAssignOperator( 6355454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CompoundAssignOperator *E) { 6356454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformBinaryOperator(E); 6357b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 63581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6359b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 636056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallExprResult TreeTransform<Derived>:: 636156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallTransformBinaryConditionalOperator(BinaryConditionalOperator *e) { 636256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // Just rebuild the common and RHS expressions and see whether we 636356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // get any changes. 636456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 636556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); 636656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (commonExpr.isInvalid()) 636756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return ExprError(); 636856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 636956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); 637056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (rhs.isInvalid()) 637156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return ExprError(); 637256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 637356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (!getDerived().AlwaysRebuild() && 637456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall commonExpr.get() == e->getCommon() && 637556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs.get() == e->getFalseExpr()) 637656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return SemaRef.Owned(e); 637756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 637856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return getDerived().RebuildConditionalOperator(commonExpr.take(), 637956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall e->getQuestionLoc(), 638056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 0, 638156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall e->getColonLoc(), 638256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs.get()); 638356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 638456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 638556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCalltemplate<typename Derived> 638660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6387454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { 638860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(E->getCond()); 6389b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Cond.isInvalid()) 6390f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 639260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6393b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6394f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 639660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6397b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6398f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6400b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6401b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Cond.get() == E->getCond() && 6402b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6403b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 64043fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 64051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 64069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildConditionalOperator(Cond.get(), 640747e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor E->getQuestionLoc(), 64089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), 640947e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor E->getColonLoc(), 64109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get()); 6411b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 64131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 641460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6415454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { 6416a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor // Implicit casts are eliminated during transformation, since they 6417a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor // will be recomputed by semantic analysis after transformation. 64186eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return getDerived().TransformExpr(E->getSubExprAsWritten()); 6419b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6421b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 642260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6423454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { 6424ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 6425ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 6426ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 6427ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor 642860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 64296eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 6430b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6431f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6433b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6434ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 6435b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 64363fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 64371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 64389d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), 6439ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type, 6440b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc(), 64419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get()); 6442b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6444b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 644560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6446454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { 644742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *OldT = E->getTypeSourceInfo(); 644842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *NewT = getDerived().TransformType(OldT); 644942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall if (!NewT) 6450f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 645260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Init = getDerived().TransformExpr(E->getInitializer()); 6453b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Init.isInvalid()) 6454f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6456b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 645742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall OldT == NewT && 6458b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Init.get() == E->getInitializer()) 645992be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 6460b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 64611d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // Note: the expression type doesn't necessarily match the 64621d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // type-as-written, but that's okay, because it should always be 64631d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // derivable from the initializer. 64641d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 646542f56b50062cd3b3c6b23fdb9053578ae9145664John McCall return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, 6466b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getInitializer()->getLocEnd(), 64679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init.get()); 6468b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6470b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 647160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6472454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { 647360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 6474b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Base.isInvalid()) 6475f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6477b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6478b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Base.get() == E->getBase()) 64793fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 64801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6481b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Bad source location 64821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeOperatorLoc 6483b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); 64849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, 6485b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getAccessorLoc(), 6486b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getAccessor()); 6487b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6489b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 649060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6491454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { 6492b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool InitChanged = false; 64931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6494ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*, 4> Inits(SemaRef); 6495aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, 6496aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Inits, &InitChanged)) 6497aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6498aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 6499b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && !InitChanged) 65003fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 65011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6502b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), 6503e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor E->getRBraceLoc(), E->getType()); 6504b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 65051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6506b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 650760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6508454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { 6509b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Designation Desig; 65101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 651143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transform the initializer value 651260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Init = getDerived().TransformExpr(E->getInit()); 6513b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Init.isInvalid()) 6514f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 651643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transform the designators. 6517ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef); 6518b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ExprChanged = false; 6519b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), 6520b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor DEnd = E->designators_end(); 6521b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D != DEnd; ++D) { 6522b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (D->isFieldDesignator()) { 6523b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Desig.AddDesignator(Designator::getField(D->getFieldName(), 6524b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getDotLoc(), 6525b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getFieldLoc())); 6526b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor continue; 6527b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 65281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6529b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (D->isArrayDesignator()) { 653060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); 6531b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Index.isInvalid()) 6532f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 65341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Desig.AddDesignator(Designator::getArray(Index.get(), 6535b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getLBracketLoc())); 65361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6537b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); 6538b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(Index.release()); 6539b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor continue; 6540b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 65411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6542b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor assert(D->isArrayRangeDesignator() && "New kind of designator?"); 654360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Start 6544b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = getDerived().TransformExpr(E->getArrayRangeStart(*D)); 6545b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Start.isInvalid()) 6546f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 654860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); 6549b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (End.isInvalid()) 6550f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 65521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Desig.AddDesignator(Designator::getArrayRange(Start.get(), 6553b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor End.get(), 6554b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getLBracketLoc(), 6555b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getEllipsisLoc())); 65561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6557b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || 6558b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor End.get() != E->getArrayRangeEnd(*D); 65591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6560b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(Start.release()); 6561b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(End.release()); 6562b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 65631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6564b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6565b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Init.get() == E->getInit() && 6566b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ExprChanged) 65673fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 65681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6569b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), 6570b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getEqualOrColonLoc(), 65719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall E->usesGNUSyntax(), Init.get()); 6572b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 65731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6574b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 657560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6576b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformImplicitValueInitExpr( 6577454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall ImplicitValueInitExpr *E) { 65785557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); 6579c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 65805557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor // FIXME: Will we ever have proper type location here? Will we actually 65815557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor // need to transform the type? 6582b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor QualType T = getDerived().TransformType(E->getType()); 6583b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (T.isNull()) 6584f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6586b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6587b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T == E->getType()) 65883fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 65891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6590b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildImplicitValueInitExpr(T); 6591b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 65921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6593b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 659460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6595454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { 65969bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); 65979bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor if (!TInfo) 6598f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 660060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 6601b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6602f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6604b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 66052cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TInfo == E->getWrittenTypeInfo() && 6606b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 66073fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 66081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 66099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), 66102cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TInfo, E->getRParenLoc()); 6611b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6612b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6613b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 661460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6615454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { 6616b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 6617ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*, 4> Inits(SemaRef); 6618aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, 6619aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 6620aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6621aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 6622b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildParenListExpr(E->getLParenLoc(), 6623b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Inits), 6624b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6625b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6627b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform an address-of-label expression. 6628b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 6629b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// By default, the transformation of an address-of-label expression always 6630b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// rebuilds the expression, so that the label identifier can be resolved to 6631b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// the corresponding label statement by semantic analysis. 6632b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 663360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6634454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { 663557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), 663657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner E->getLabel()); 663757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner if (!LD) 663857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return ExprError(); 663957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 6640b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), 664157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner cast<LabelDecl>(LD)); 6642b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 66441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 664560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6646454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { 664760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt 6648b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = getDerived().TransformCompoundStmt(E->getSubStmt(), true); 6649b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubStmt.isInvalid()) 6650f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6652b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6653b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubStmt.get() == E->getSubStmt()) 665492be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 66551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 66561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildStmtExpr(E->getLParenLoc(), 66579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubStmt.get(), 6658b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6659b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6661b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 666260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6663454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { 666460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(E->getCond()); 6665b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Cond.isInvalid()) 6666f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 666860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6669b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6670f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 667260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6674f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6677b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Cond.get() == E->getCond() && 6678b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6679b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 66803fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 66811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6682b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), 66839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond.get(), LHS.get(), RHS.get(), 6684b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6685b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6687b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 668860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6689454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { 66903fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6691b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6692b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6693b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 669460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6695454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { 6696668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor switch (E->getOperator()) { 6697668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_New: 6698668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Delete: 6699668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Array_New: 6700668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Array_Delete: 6701668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); 6702f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6703c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6704668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Call: { 6705668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // This is a call to an object's operator(). 6706668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); 6707668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6708668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Transform the object itself. 670960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Object = getDerived().TransformExpr(E->getArg(0)); 6710668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor if (Object.isInvalid()) 6711f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6712668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6713668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // FIXME: Poor location information 6714668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor SourceLocation FakeLParenLoc 6715668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor = SemaRef.PP.getLocForEndOfToken( 6716668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor static_cast<Expr *>(Object.get())->getLocEnd()); 6717668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6718668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Transform the call arguments. 6719ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 6720aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, 6721aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args)) 6722aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6723668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 67249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, 6725668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor move_arg(Args), 6726668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor E->getLocEnd()); 6727668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor } 6728668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6729668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ 6730668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_##Name: 6731668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) 6732668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#include "clang/Basic/OperatorKinds.def" 6733668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Subscript: 6734668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Handled below. 6735668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor break; 6736668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6737668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Conditional: 6738668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("conditional operator is not actually overloadable"); 6739f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6740668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6741668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_None: 6742668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case NUM_OVERLOADED_OPERATORS: 6743668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("not an overloaded operator?"); 6744f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6745668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor } 6746668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 674760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 6748b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Callee.isInvalid()) 6749f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 67501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 675160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult First = getDerived().TransformExpr(E->getArg(0)); 6752b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (First.isInvalid()) 6753f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6754b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 675560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Second; 6756b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->getNumArgs() == 2) { 6757b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Second = getDerived().TransformExpr(E->getArg(1)); 6758b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Second.isInvalid()) 6759f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6760b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 67611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6762b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6763b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Callee.get() == E->getCallee() && 6764b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor First.get() == E->getArg(0) && 67651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) 676692be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 67671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6768b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), 6769b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOperatorLoc(), 67709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Callee.get(), 67719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall First.get(), 67729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Second.get()); 6773b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 67741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6775b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 677660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6777454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { 6778454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCallExpr(E); 6779b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 67801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6781b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 6782e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneExprResult 6783e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneTreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { 6784e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // Transform the callee. 6785e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 6786e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (Callee.isInvalid()) 6787e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return ExprError(); 6788e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6789e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // Transform exec config. 6790e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); 6791e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (EC.isInvalid()) 6792e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return ExprError(); 6793e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6794e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // Transform arguments. 6795e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne bool ArgChanged = false; 6796e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ASTOwningVector<Expr*> Args(SemaRef); 6797e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 6798e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne &ArgChanged)) 6799e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return ExprError(); 6800e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6801e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (!getDerived().AlwaysRebuild() && 6802e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne Callee.get() == E->getCallee() && 6803e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne !ArgChanged) 680492be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 6805e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6806e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // FIXME: Wrong source location information for the '('. 6807e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne SourceLocation FakeLParenLoc 6808e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne = ((Expr *)Callee.get())->getSourceRange().getBegin(); 6809e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, 6810e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne move_arg(Args), 6811e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne E->getRParenLoc(), EC.get()); 6812e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne} 6813e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6814e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournetemplate<typename Derived> 681560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6816454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { 6817ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 6818ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 6819ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 6820ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor 682160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 68226eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 6823b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6824f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6826b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6827ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 6828b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 68293fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 68301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6831b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Poor source location information here. 68321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeLAngleLoc 6833b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); 6834b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); 6835b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeRParenLoc 6836b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken( 6837b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getSubExpr()->getSourceRange().getEnd()); 6838b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), 68391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump E->getStmtClass(), 6840b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeLAngleLoc, 6841ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type, 6842b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRAngleLoc, 6843b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRAngleLoc, 68449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 6845b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRParenLoc); 6846b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6848b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 684960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6850454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { 6851454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 6852b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6854b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 685560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6856454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { 6857454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 6858b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6860b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 686160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6862b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXReinterpretCastExpr( 6863454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXReinterpretCastExpr *E) { 6864454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 6865b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6867b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 686860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6869454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { 6870454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 6871b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6873b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 687460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6875b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXFunctionalCastExpr( 6876454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXFunctionalCastExpr *E) { 6877ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 6878ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 6879ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 68801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 688160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 68826eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 6883b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6884f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6886b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6887ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 6888b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 68893fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 68901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6891ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return getDerived().RebuildCXXFunctionalCastExpr(Type, 6892b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getSubExpr()->getLocStart(), 68939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 6894b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6895b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6897b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 689860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6899454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { 6900b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->isTypeOperand()) { 690157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TypeSourceInfo *TInfo 690257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor = getDerived().TransformType(E->getTypeOperandSourceInfo()); 690357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor if (!TInfo) 6904f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 69051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6906b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 690757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TInfo == E->getTypeOperandSourceInfo()) 69083fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 69091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 691057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return getDerived().RebuildCXXTypeidExpr(E->getType(), 691157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor E->getLocStart(), 691257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TInfo, 6913b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 6914b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 69151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6916ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman // We don't know whether the subexpression is potentially evaluated until 6917ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman // after we perform semantic analysis. We speculatively assume it is 6918ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman // unevaluated; it will get fixed later if the subexpression is in fact 6919b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // potentially evaluated. 6920ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 69211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 692260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); 6923b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6924f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 69251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6926b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6927b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getExprOperand()) 69283fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 69291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 693057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return getDerived().RebuildCXXTypeidExpr(E->getType(), 693157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor E->getLocStart(), 69329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 6933b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 6934b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6935b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6936b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 693760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 693801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetTreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { 693901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (E->isTypeOperand()) { 694001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TypeSourceInfo *TInfo 694101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet = getDerived().TransformType(E->getTypeOperandSourceInfo()); 694201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!TInfo) 694301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return ExprError(); 694401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 694501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!getDerived().AlwaysRebuild() && 694601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TInfo == E->getTypeOperandSourceInfo()) 69473fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 694801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 69493c52a218f41f091a17582d037663594d2b8dc708Douglas Gregor return getDerived().RebuildCXXUuidofExpr(E->getType(), 695001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocStart(), 695101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TInfo, 695201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocEnd()); 695301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 695401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 695501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 695601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 695701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); 695801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (SubExpr.isInvalid()) 695901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return ExprError(); 696001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 696101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!getDerived().AlwaysRebuild() && 696201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SubExpr.get() == E->getExprOperand()) 69633fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 696401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 696501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getDerived().RebuildCXXUuidofExpr(E->getType(), 696601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocStart(), 696701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SubExpr.get(), 696801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocEnd()); 696901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet} 697001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 697101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichettemplate<typename Derived> 697201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetExprResult 6973454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { 69743fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6975b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 69761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6977b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 697860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6979b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( 6980454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXNullPtrLiteralExpr *E) { 69813fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6982b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 69831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6984b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 698560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6986454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { 6987ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor DeclContext *DC = getSema().getFunctionLevelDeclContext(); 69887a614d8380297fcd2bc23986241905d97222948cRichard Smith QualType T; 69897a614d8380297fcd2bc23986241905d97222948cRichard Smith if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) 69907a614d8380297fcd2bc23986241905d97222948cRichard Smith T = MD->getThisType(getSema().Context); 69917a614d8380297fcd2bc23986241905d97222948cRichard Smith else 69927a614d8380297fcd2bc23986241905d97222948cRichard Smith T = getSema().Context.getPointerType( 69937a614d8380297fcd2bc23986241905d97222948cRichard Smith getSema().Context.getRecordType(cast<CXXRecordDecl>(DC))); 69941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6995ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!getDerived().AlwaysRebuild() && T == E->getType()) 69963fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 69971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6998828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); 6999b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 70001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7001b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 700260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7003454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { 700460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 7005b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 7006f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7008b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7009b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 70103fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7011b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7012bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), 7013bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor E->isThrownVariableInScope()); 7014b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 70151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7016b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 701760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7018454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { 70191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParmVarDecl *Param 70207c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), 70217c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getParam())); 7022b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Param) 7023f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 702553cb6f82c41397917b14fb8cdcb32e6c9bd07655Chandler Carruth if (!getDerived().AlwaysRebuild() && 7026b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Param == E->getParam()) 70273fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 70281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7029036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); 7030b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 70311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7032b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 703360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7034ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas GregorTreeTransform<Derived>::TransformCXXScalarValueInitExpr( 7035ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXScalarValueInitExpr *E) { 7036ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 7037ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 7038f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7039ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor 7040b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7041ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo()) 70423fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 70431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7044ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXScalarValueInitExpr(T, 7045ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /*FIXME:*/T->getTypeLoc().getEndLoc(), 7046ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor E->getRParenLoc()); 7047b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 70481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7049b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 705060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7051454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { 7052b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the type that we're allocating 70531bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *AllocTypeInfo 70541bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); 70551bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor if (!AllocTypeInfo) 7056f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7058b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the size of the array we're allocating (if any). 705960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); 7060b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (ArraySize.isInvalid()) 7061f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7063b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the placement arguments (if any). 7064b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 7065ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> PlacementArgs(SemaRef); 7066aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getPlacementArgs(), 7067aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor E->getNumPlacementArgs(), true, 7068aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor PlacementArgs, &ArgumentChanged)) 7069aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 70701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 70714e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor // Transform the constructor arguments (if any). 70724e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor // As an annoying corner case, we may have introduced an implicit value- 70734e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor // initialization expression when allocating a new array, which we implicitly 70744e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor // drop. It will be re-created during type checking. 7075ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> ConstructorArgs(SemaRef); 70764e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor if (!(E->isArray() && E->getNumConstructorArgs() == 1 && 70774e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor isa<ImplicitValueInitExpr>(E->getConstructorArgs()[0])) && 70784e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true, 7079aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor ConstructorArgs, &ArgumentChanged)) 7080aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 70811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 70821af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Transform constructor, new operator, and delete operator. 70831af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor CXXConstructorDecl *Constructor = 0; 70841af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getConstructor()) { 70851af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor Constructor = cast_or_null<CXXConstructorDecl>( 70867c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 70877c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 70881af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!Constructor) 7089f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70901af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 70911af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor 70921af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorNew = 0; 70931af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorNew()) { 70941af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorNew = cast_or_null<FunctionDecl>( 70957c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 70967c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorNew())); 70971af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorNew) 7098f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70991af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 71001af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor 71011af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorDelete = 0; 71021af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorDelete()) { 71031af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete = cast_or_null<FunctionDecl>( 71047c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 71057c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorDelete())); 71061af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorDelete) 7107f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 71081af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 7109c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7110b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 71111bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocTypeInfo == E->getAllocatedTypeSourceInfo() && 7112b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArraySize.get() == E->getArraySize() && 71131af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor Constructor == E->getConstructor() && 71141af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorNew == E->getOperatorNew() && 71151af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete == E->getOperatorDelete() && 71161af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor !ArgumentChanged) { 71171af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark any declarations we need as referenced. 71181af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: instantiation-specific. 71191af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (Constructor) 71205f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); 71211af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorNew) 71225f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew); 71231af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorDelete) 71245f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); 71252ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor 71262ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor if (E->isArray() && Constructor && 71272ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor !E->getAllocatedType()->isDependentType()) { 71282ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor QualType ElementType 71292ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor = SemaRef.Context.getBaseElementType(E->getAllocatedType()); 71302ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { 71312ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); 71322ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { 71335f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor); 71342ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor } 71352ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor } 71362ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor } 71372ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor 71383fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 71391af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 71401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71411bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor QualType AllocType = AllocTypeInfo->getType(); 71425b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (!ArraySize.get()) { 71435b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // If no array size was specified, but the new expression was 71445b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // instantiated with an array type (e.g., "new T" where T is 71455b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // instantiated with "int[4]"), extract the outer bound from the 71465b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // array type as our array size. We do this with constant and 71475b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // dependently-sized array types. 71485b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); 71495b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (!ArrayT) { 71505b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // Do nothing 71515b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } else if (const ConstantArrayType *ConsArrayT 71525b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor = dyn_cast<ConstantArrayType>(ArrayT)) { 7153c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ArraySize 71549996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, 71559996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis ConsArrayT->getSize(), 71569996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis SemaRef.Context.getSizeType(), 71579996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /*FIXME:*/E->getLocStart())); 71585b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor AllocType = ConsArrayT->getElementType(); 71595b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } else if (const DependentSizedArrayType *DepArrayT 71605b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor = dyn_cast<DependentSizedArrayType>(ArrayT)) { 71615b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (DepArrayT->getSizeExpr()) { 71623fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); 71635b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor AllocType = DepArrayT->getElementType(); 71645b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 71655b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 71665b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 71671bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor 7168b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXNewExpr(E->getLocStart(), 7169b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isGlobalNew(), 7170b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLocStart(), 7171b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(PlacementArgs), 7172b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLocStart(), 71734bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor E->getTypeIdParens(), 7174b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor AllocType, 71751bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocTypeInfo, 71769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ArraySize.get(), 71774e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor E->getConstructorLParen(), 7178b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(ConstructorArgs), 71794e8ea0b2e163aa9681e2f14ad75ab4990a69d39bDouglas Gregor E->getConstructorRParen()); 7180b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 71811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7182b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 718360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7184454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { 718560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Operand = getDerived().TransformExpr(E->getArgument()); 7186b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Operand.isInvalid()) 7187f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 71881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71891af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Transform the delete operator, if known. 71901af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorDelete = 0; 71911af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorDelete()) { 71921af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete = cast_or_null<FunctionDecl>( 71937c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 71947c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorDelete())); 71951af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorDelete) 7196f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 71971af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 7198c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7199b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 72001af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor Operand.get() == E->getArgument() && 72011af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete == E->getOperatorDelete()) { 72021af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark any declarations we need as referenced. 72031af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: instantiation-specific. 72041af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorDelete) 72055f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); 72065833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor 72075833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor if (!E->getArgument()->isTypeDependent()) { 72085833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor QualType Destroyed = SemaRef.Context.getBaseElementType( 72095833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor E->getDestroyedType()); 72105833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { 72115833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); 72125f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkFunctionReferenced(E->getLocStart(), 72135f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.LookupDestructor(Record)); 72145833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor } 72155833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor } 72165833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor 72173fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 72181af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 72191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7220b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), 7221b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isGlobalDelete(), 7222b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrayForm(), 72239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Operand.get()); 7224b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 72251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7226b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 722760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7228a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas GregorTreeTransform<Derived>::TransformCXXPseudoDestructorExpr( 7229454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXPseudoDestructorExpr *E) { 723060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 7231a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor if (Base.isInvalid()) 7232f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 72331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7234b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectTypePtr; 7235a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor bool MayBePseudoDestructor = false; 72369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), 7237a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getOperatorLoc(), 7238a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->isArrow()? tok::arrow : tok::period, 7239a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor ObjectTypePtr, 7240a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor MayBePseudoDestructor); 7241a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (Base.isInvalid()) 7242f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7243c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7244b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall QualType ObjectType = ObjectTypePtr.get(); 7245f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); 7246f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor if (QualifierLoc) { 7247f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor QualifierLoc 7248f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); 7249f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor if (!QualifierLoc) 725043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return ExprError(); 725143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } 7252f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor CXXScopeSpec SS; 7253f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SS.Adopt(QualifierLoc); 72541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7255a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed; 7256a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (E->getDestroyedTypeInfo()) { 7257a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor TypeSourceInfo *DestroyedTypeInfo 725843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), 7259b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor ObjectType, 0, SS); 7260a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (!DestroyedTypeInfo) 7261f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7262a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed = DestroyedTypeInfo; 72636b18e740495b67b439fa366367242110365cc4d9Douglas Gregor } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { 7264a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // We aren't likely to be able to resolve the identifier down to a type 7265a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // now anyway, so just retain the identifier. 7266a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), 7267a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc()); 7268a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } else { 7269a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // Look for a destructor known with the given name. 7270b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), 7271a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor *E->getDestroyedTypeIdentifier(), 7272a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc(), 7273a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /*Scope=*/0, 7274a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor SS, ObjectTypePtr, 7275a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor false); 7276a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (!T) 7277f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7278c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7279a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed 7280a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), 7281a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc()); 7282a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 728326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor 728426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor TypeSourceInfo *ScopeTypeInfo = 0; 728526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor if (E->getScopeTypeInfo()) { 728643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo()); 728726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor if (!ScopeTypeInfo) 7288f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7289a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor } 7290c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 72919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), 7292a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor E->getOperatorLoc(), 7293a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor E->isArrow(), 7294f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SS, 729526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor ScopeTypeInfo, 729626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor E->getColonColonLoc(), 7297fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor E->getTildeLoc(), 7298a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed); 7299a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor} 73001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7301a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregortemplate<typename Derived> 730260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7303ba13543329afac4a0d01304ec2ec4924d99306a6John McCallTreeTransform<Derived>::TransformUnresolvedLookupExpr( 7304454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall UnresolvedLookupExpr *Old) { 7305f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), 7306f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall Sema::LookupOrdinaryName); 7307f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7308f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Transform all the decls. 7309f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), 7310f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall E = Old->decls_end(); I != E; ++I) { 73117c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor NamedDecl *InstD = static_cast<NamedDecl*>( 73127c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(Old->getNameLoc(), 73137c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor *I)); 73149f54ad4381370c6b771424b53d219e661d6d6706John McCall if (!InstD) { 73159f54ad4381370c6b771424b53d219e661d6d6706John McCall // Silently ignore these if a UsingShadowDecl instantiated to nothing. 73169f54ad4381370c6b771424b53d219e661d6d6706John McCall // This can happen because of dependent hiding. 73179f54ad4381370c6b771424b53d219e661d6d6706John McCall if (isa<UsingShadowDecl>(*I)) 73189f54ad4381370c6b771424b53d219e661d6d6706John McCall continue; 73199f54ad4381370c6b771424b53d219e661d6d6706John McCall else 7320f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 73219f54ad4381370c6b771424b53d219e661d6d6706John McCall } 7322f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7323f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Expand using declarations. 7324f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (isa<UsingDecl>(InstD)) { 7325f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall UsingDecl *UD = cast<UsingDecl>(InstD); 7326f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall for (UsingDecl::shadow_iterator I = UD->shadow_begin(), 7327f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall E = UD->shadow_end(); I != E; ++I) 7328f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.addDecl(*I); 7329f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall continue; 7330f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 7331f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7332f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.addDecl(InstD); 7333f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 7334f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7335f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Resolve a kind, but don't do any further analysis. If it's 7336f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // ambiguous, the callee needs to deal with it. 7337f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.resolveKind(); 7338f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7339f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Rebuild the nested-name qualifier, if present. 7340f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall CXXScopeSpec SS; 73414c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (Old->getQualifierLoc()) { 73424c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc 73434c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); 73444c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (!QualifierLoc) 7345f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7346c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 73474c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor SS.Adopt(QualifierLoc); 7348c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt } 7349c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7350c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor if (Old->getNamingClass()) { 735166c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor CXXRecordDecl *NamingClass 735266c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( 735366c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNameLoc(), 735466c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNamingClass())); 735566c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor if (!NamingClass) 7356f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7357c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 735866c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor R.setNamingClass(NamingClass); 7359f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 7360f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7361e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); 7362e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 73639d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara // If we have neither explicit template arguments, nor the template keyword, 73649d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara // it's a normal declaration name. 73659d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) 7366f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); 7367f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7368f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // If we have template arguments, rebuild them, then rebuild the 7369f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // templateid expression. 7370f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); 7371fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), 7372fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor Old->getNumTemplateArgs(), 7373fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7374fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 7375f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7376e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, 73779d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara Old->requiresADL(), &TransArgs); 7378b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 73791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7380b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 738160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7382454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { 73833d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); 73843d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor if (!T) 7385f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 73861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7387b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 73883d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor T == E->getQueriedTypeSourceInfo()) 73893fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 73901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 73911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildUnaryTypeTrait(E->getTrait(), 7392b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocStart(), 7393b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T, 7394b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 7395b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 73961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7397b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 739860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 73996ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetTreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { 74006ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); 74016ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!LhsT) 74026ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return ExprError(); 74036ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 74046ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); 74056ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!RhsT) 74066ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return ExprError(); 74076ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 74086ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!getDerived().AlwaysRebuild() && 74096ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) 74106ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return SemaRef.Owned(E); 74116ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 74126ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return getDerived().RebuildBinaryTypeTrait(E->getTrait(), 74136ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet E->getLocStart(), 74146ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet LhsT, RhsT, 74156ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet E->getLocEnd()); 74166ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet} 74176ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 74186ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichettemplate<typename Derived> 74196ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetExprResult 742021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John WiegleyTreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { 742121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); 742221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (!T) 742321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return ExprError(); 742421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 742521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (!getDerived().AlwaysRebuild() && 742621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley T == E->getQueriedTypeSourceInfo()) 742721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return SemaRef.Owned(E); 742821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 742921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ExprResult SubExpr; 743021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley { 743121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 743221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); 743321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (SubExpr.isInvalid()) 743421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return ExprError(); 743521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 743621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) 743721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return SemaRef.Owned(E); 743821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 743921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 744021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return getDerived().RebuildArrayTypeTrait(E->getTrait(), 744121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley E->getLocStart(), 744221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley T, 744321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SubExpr.get(), 744421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley E->getLocEnd()); 744521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley} 744621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 744721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleytemplate<typename Derived> 744821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John WiegleyExprResult 7449552622067dc45013d240f73952fece703f5e63bdJohn WiegleyTreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { 7450552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExprResult SubExpr; 7451552622067dc45013d240f73952fece703f5e63bdJohn Wiegley { 7452552622067dc45013d240f73952fece703f5e63bdJohn Wiegley EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 7453552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); 7454552622067dc45013d240f73952fece703f5e63bdJohn Wiegley if (SubExpr.isInvalid()) 7455552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return ExprError(); 7456552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 7457552622067dc45013d240f73952fece703f5e63bdJohn Wiegley if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) 7458552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return SemaRef.Owned(E); 7459552622067dc45013d240f73952fece703f5e63bdJohn Wiegley } 7460552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 7461552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return getDerived().RebuildExpressionTrait( 7462552622067dc45013d240f73952fece703f5e63bdJohn Wiegley E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); 7463552622067dc45013d240f73952fece703f5e63bdJohn Wiegley} 7464552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 7465552622067dc45013d240f73952fece703f5e63bdJohn Wiegleytemplate<typename Derived> 7466552622067dc45013d240f73952fece703f5e63bdJohn WiegleyExprResult 7467865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformDependentScopeDeclRefExpr( 74682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DependentScopeDeclRefExpr *E) { 746900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc 747000cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 747100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor if (!QualifierLoc) 7472f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7473e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); 74741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 747543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // TODO: If this is a conversion-function-id, verify that the 747643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // destination type name (if present) resolves the same way after 747743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // instantiation as it did in the local scope. 747843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 74792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo 74802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); 74812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!NameInfo.getName()) 7482f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 74831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7484f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!E->hasExplicitTemplateArgs()) { 7485f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!getDerived().AlwaysRebuild() && 748600cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor QualifierLoc == E->getQualifierLoc() && 74872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // Note: it is sufficient to compare the Name component of NameInfo: 74882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // if name has not changed, DNLoc has not changed either. 74892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getDeclName()) 74903fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 74911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 749200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, 7493e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateKWLoc, 74942577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7495f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /*TemplateArgs*/ 0); 7496f17bb74e74aca9bb0525d2249041ab65c7d1fd48Douglas Gregor } 7497d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 7498d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); 7499fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 7500fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 7501fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7502fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 7503b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 750400cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, 7505e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateKWLoc, 75062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7507f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall &TransArgs); 7508b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7509b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7510b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 751160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7512454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { 7513321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor // CXXConstructExprs are always implicit, so when we have a 7514321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor // 1-argument construction we just transform that argument. 7515321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor if (E->getNumArgs() == 1 || 7516321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) 7517321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor return getDerived().TransformExpr(E->getArg(0)); 7518321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor 7519b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); 7520b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7521b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor QualType T = getDerived().TransformType(E->getType()); 7522b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (T.isNull()) 7523f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7524b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7525b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXConstructorDecl *Constructor 7526b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = cast_or_null<CXXConstructorDecl>( 75277c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 75287c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 7529b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Constructor) 7530f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 75311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7532b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 7533ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 7534aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 7535aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 7536aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 7537aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 7538b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7539b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T == E->getType() && 7540b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Constructor == E->getConstructor() && 7541c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor !ArgumentChanged) { 75421af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark the constructor as referenced. 75431af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: Instantiation-specific 75445f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); 75453fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7546c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor } 75471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 75484411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), 75494411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor Constructor, E->isElidable(), 75508c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor move_arg(Args), 75517cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara E->hadMultipleCandidates(), 75528c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor E->requiresZeroInitialization(), 7553428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth E->getConstructionKind(), 7554428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth E->getParenRange()); 7555b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 75561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7557b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform a C++ temporary-binding expression. 7558b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 75595132655e4296b780672e9a96b46a740135073534Douglas Gregor/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just 75605132655e4296b780672e9a96b46a740135073534Douglas Gregor/// transform the subexpression and return that. 7561b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 756260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7563454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { 75645132655e4296b780672e9a96b46a740135073534Douglas Gregor return getDerived().TransformExpr(E->getSubExpr()); 7565b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 75661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 75674765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// \brief Transform a C++ expression that contains cleanups that should 75684765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// be run after the expression is evaluated. 7569b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 75704765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Since ExprWithCleanups nodes are implicitly generated, we 75715132655e4296b780672e9a96b46a740135073534Douglas Gregor/// just transform the subexpression and return that. 7572b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 757360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 75744765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallTreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { 75755132655e4296b780672e9a96b46a740135073534Douglas Gregor return getDerived().TransformExpr(E->getSubExpr()); 7576b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 75771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7578b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 757960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7580b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXTemporaryObjectExpr( 7581ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXTemporaryObjectExpr *E) { 7582ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 7583ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 7584f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 75851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7586b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXConstructorDecl *Constructor 7587b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = cast_or_null<CXXConstructorDecl>( 7588c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt getDerived().TransformDecl(E->getLocStart(), 75897c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 7590b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Constructor) 7591f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 75921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7593b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 7594ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 7595b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Args.reserve(E->getNumArgs()); 7596aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 7597aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 7598aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 75991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7600b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7601ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo() && 7602b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Constructor == E->getConstructor() && 760391be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor !ArgumentChanged) { 760491be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor // FIXME: Instantiation-specific 76055f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); 76063fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.MaybeBindToTemporary(E); 760791be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor } 7608ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor 7609ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXTemporaryObjectExpr(T, 7610ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /*FIXME:*/T->getTypeLoc().getEndLoc(), 7611b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Args), 7612b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 7613b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 76141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7615b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 761660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7617b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( 7618454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXUnresolvedConstructExpr *E) { 7619ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 7620ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 7621f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 76221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7623b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 7624ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 7625aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args.reserve(E->arg_size()); 7626aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, 7627aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 7628aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 7629aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 7630b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7631ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo() && 7632b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgumentChanged) 76333fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 76341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7635b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: we're faking the locations of the commas 7636ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXUnresolvedConstructExpr(T, 7637b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLParenLoc(), 7638b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Args), 7639b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 7640b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 76411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7642b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 764360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7644865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( 76452577743c5650c646fb705df01403707e94f2df04Abramo Bagnara CXXDependentScopeMemberExpr *E) { 7646b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the base of the expression. 764760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base((Expr*) 0); 7648aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *OldBase; 7649aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType; 7650aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType ObjectType; 7651aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!E->isImplicitAccess()) { 7652aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OldBase = E->getBase(); 7653aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base = getDerived().TransformExpr(OldBase); 7654aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 7655f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 76561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7657aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall // Start the member reference and compute the object's type. 7658b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectTy; 7659d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor bool MayBePseudoDestructor = false; 76609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), 7661aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall E->getOperatorLoc(), 7662a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor E->isArrow()? tok::arrow : tok::period, 7663d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor ObjectTy, 7664d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor MayBePseudoDestructor); 7665aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 7666f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7667aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 7668b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ObjectType = ObjectTy.get(); 7669aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = ((Expr*) Base.get())->getType(); 7670aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } else { 7671aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OldBase = 0; 7672aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = getDerived().TransformType(E->getBaseType()); 7673aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); 7674aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 76751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76766cd219879ffce00920189ec1dcea927a42602961Douglas Gregor // Transform the first part of the nested-name-specifier that qualifies 76776cd219879ffce00920189ec1dcea927a42602961Douglas Gregor // the member name. 7678c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor NamedDecl *FirstQualifierInScope 76796cd219879ffce00920189ec1dcea927a42602961Douglas Gregor = getDerived().TransformFirstQualifierInScope( 76807c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor E->getFirstQualifierFoundInScope(), 76817c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor E->getQualifierLoc().getBeginLoc()); 76821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 76837c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 7684a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor if (E->getQualifier()) { 76857c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc 76867c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), 76877c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor ObjectType, 76887c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor FirstQualifierInScope); 76897c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor if (!QualifierLoc) 7690f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7691a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor } 76921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7693e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); 7694e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 769543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // TODO: If this is a conversion-function-id, verify that the 769643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // destination type name (if present) resolves the same way after 769743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // instantiation as it did in the local scope. 769843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 76992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo 770043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); 77012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!NameInfo.getName()) 7702f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 77031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7704aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!E->hasExplicitTemplateArgs()) { 77053b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor // This is a reference to a member without an explicitly-specified 77063b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor // template argument list. Optimize for this common case. 77073b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor if (!getDerived().AlwaysRebuild() && 7708aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base.get() == OldBase && 7709aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType == E->getBaseType() && 77107c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc == E->getQualifierLoc() && 77112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getMember() && 77123b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor FirstQualifierInScope == E->getFirstQualifierFoundInScope()) 77133fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 77141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 77159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), 7716aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 77173b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor E->isArrow(), 77183b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor E->getOperatorLoc(), 77197c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc, 7720e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateKWLoc, 7721129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall FirstQualifierInScope, 77222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7723129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /*TemplateArgs*/ 0); 77243b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 77253b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor 7726d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); 7727fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 7728fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 7729fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7730fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 77311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 77329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), 7733aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 7734b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrow(), 7735b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOperatorLoc(), 77367c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc, 7737e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateKWLoc, 77383b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor FirstQualifierInScope, 77392577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7740129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall &TransArgs); 7741129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall} 7742129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7743129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCalltemplate<typename Derived> 774460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7745454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { 7746129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Transform the base of the expression. 774760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base((Expr*) 0); 7748aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType; 7749aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!Old->isImplicitAccess()) { 7750aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base = getDerived().TransformExpr(Old->getBase()); 7751aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 7752f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 77539138b4e96429cbaae00c52c15c960f72b6645088Richard Smith Base = getSema().PerformMemberExprBaseConversion(Base.take(), 77549138b4e96429cbaae00c52c15c960f72b6645088Richard Smith Old->isArrow()); 77559138b4e96429cbaae00c52c15c960f72b6645088Richard Smith if (Base.isInvalid()) 77569138b4e96429cbaae00c52c15c960f72b6645088Richard Smith return ExprError(); 77579138b4e96429cbaae00c52c15c960f72b6645088Richard Smith BaseType = Base.get()->getType(); 7758aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } else { 7759aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = getDerived().TransformType(Old->getBaseType()); 7760aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 7761129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 77624c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 77634c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (Old->getQualifierLoc()) { 77644c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor QualifierLoc 77654c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); 77664c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (!QualifierLoc) 7767f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7768129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 7769129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7770e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); 7771e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 77722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LookupResult R(SemaRef, Old->getMemberNameInfo(), 7773129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Sema::LookupOrdinaryName); 7774129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7775129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Transform all the decls. 7776129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), 7777129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall E = Old->decls_end(); I != E; ++I) { 77787c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor NamedDecl *InstD = static_cast<NamedDecl*>( 77797c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(Old->getMemberLoc(), 77807c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor *I)); 77819f54ad4381370c6b771424b53d219e661d6d6706John McCall if (!InstD) { 77829f54ad4381370c6b771424b53d219e661d6d6706John McCall // Silently ignore these if a UsingShadowDecl instantiated to nothing. 77839f54ad4381370c6b771424b53d219e661d6d6706John McCall // This can happen because of dependent hiding. 77849f54ad4381370c6b771424b53d219e661d6d6706John McCall if (isa<UsingShadowDecl>(*I)) 77859f54ad4381370c6b771424b53d219e661d6d6706John McCall continue; 778634f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis else { 778734f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis R.clear(); 7788f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 778934f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis } 77909f54ad4381370c6b771424b53d219e661d6d6706John McCall } 7791129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7792129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Expand using declarations. 7793129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (isa<UsingDecl>(InstD)) { 7794129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall UsingDecl *UD = cast<UsingDecl>(InstD); 7795129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall for (UsingDecl::shadow_iterator I = UD->shadow_begin(), 7796129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall E = UD->shadow_end(); I != E; ++I) 7797129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.addDecl(*I); 7798129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall continue; 7799129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 7800129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7801129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.addDecl(InstD); 7802129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 7803129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7804129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.resolveKind(); 7805129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 7806c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor // Determine the naming class. 7807042d6f98ea73d781e43cc17077e8fc84a4201eefChandler Carruth if (Old->getNamingClass()) { 7808c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt CXXRecordDecl *NamingClass 7809c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( 781066c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getMemberLoc(), 781166c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNamingClass())); 781266c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor if (!NamingClass) 7813f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7814c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 781566c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor R.setNamingClass(NamingClass); 7816c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor } 7817c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7818129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TemplateArgumentListInfo TransArgs; 7819129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (Old->hasExplicitTemplateArgs()) { 7820129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TransArgs.setLAngleLoc(Old->getLAngleLoc()); 7821129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TransArgs.setRAngleLoc(Old->getRAngleLoc()); 7822fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), 7823fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor Old->getNumTemplateArgs(), 7824fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7825fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 7826129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 7827c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 7828c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // FIXME: to do this check properly, we will need to preserve the 7829c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // first-qualifier-in-scope here, just in case we had a dependent 7830c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // base (and therefore couldn't do the check) and a 7831c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // nested-name-qualifier (and therefore could do the lookup). 7832c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall NamedDecl *FirstQualifierInScope = 0; 7833c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 78349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildUnresolvedMemberExpr(Base.get(), 7835aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 7836129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Old->getOperatorLoc(), 7837129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Old->isArrow(), 78384c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor QualifierLoc, 7839e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateKWLoc, 7840c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall FirstQualifierInScope, 7841129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R, 7842129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall (Old->hasExplicitTemplateArgs() 7843129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall ? &TransArgs : 0)); 7844b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7845b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7846b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 784760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 78482e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlTreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { 7849eea06c609b73afc7bcfdf3e101efb8d9e7b3560cSean Hunt EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 78502e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); 78512e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl if (SubExpr.isInvalid()) 78522e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return ExprError(); 78532e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 78542e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) 78553fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 78562e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 78572e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); 78582e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl} 78592e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 78602e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redltemplate<typename Derived> 78612e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlExprResult 7862be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorTreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { 78634f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); 78644f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor if (Pattern.isInvalid()) 78654f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor return ExprError(); 78664f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor 78674f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) 78684f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor return SemaRef.Owned(E); 78694f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor 787067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), 787167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor E->getNumExpansions()); 7872be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor} 7873ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 7874ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregortemplate<typename Derived> 7875ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorExprResult 7876ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorTreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { 7877ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // If E is not value-dependent, then nothing will change when we transform it. 7878ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // Note: This is an instantiation-centric view. 7879ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor if (!E->isValueDependent()) 7880ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return SemaRef.Owned(E); 7881ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 7882ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // Note: None of the implementations of TryExpandParameterPacks can ever 7883ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // produce a diagnostic when given only a single unexpanded parameter pack, 7884ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // so 7885ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); 7886ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor bool ShouldExpand = false; 7887d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 7888cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions; 7889ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), 7890a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 7891d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ShouldExpand, RetainExpansion, 7892d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) 7893ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return ExprError(); 7894ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 7895089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor if (RetainExpansion) 7896ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return SemaRef.Owned(E); 7897089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor 7898089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor NamedDecl *Pack = E->getPack(); 7899089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor if (!ShouldExpand) { 7900089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(), 7901089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor Pack)); 7902089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor if (!Pack) 7903089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor return ExprError(); 7904089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor } 7905089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor 7906be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 7907ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // We now know the length of the parameter pack, so build a new expression 7908ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // that stores that length. 7909089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, 7910ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor E->getPackLoc(), E->getRParenLoc(), 7911089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor NumExpansions); 7912ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor} 7913ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 7914be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregortemplate<typename Derived> 7915be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorExprResult 7916c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorTreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( 7917c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor SubstNonTypeTemplateParmPackExpr *E) { 7918c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor // Default behavior is to do nothing with this transformation. 791991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return SemaRef.Owned(E); 792091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall} 792191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 792291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCalltemplate<typename Derived> 792391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallExprResult 792491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallTreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( 792591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall SubstNonTypeTemplateParmExpr *E) { 792691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall // Default behavior is to do nothing with this transformation. 7927c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor return SemaRef.Owned(E); 7928c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor} 7929c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor 7930c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregortemplate<typename Derived> 7931c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorExprResult 793203e80030515c800d1ab44125b9052dfffd1bd04cDouglas GregorTreeTransform<Derived>::TransformMaterializeTemporaryExpr( 793303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor MaterializeTemporaryExpr *E) { 793403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return getDerived().TransformExpr(E->GetTemporaryExpr()); 793503e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor} 793603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 793703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregortemplate<typename Derived> 793803e80030515c800d1ab44125b9052dfffd1bd04cDouglas GregorExprResult 7939454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { 79403fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7941b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7942b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 79431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 794460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7945454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { 794681d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *EncodedTypeInfo 794781d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor = getDerived().TransformType(E->getEncodedTypeSourceInfo()); 794881d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor if (!EncodedTypeInfo) 7949f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 79501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7951b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 795281d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedTypeInfo == E->getEncodedTypeSourceInfo()) 79533fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7954b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7955b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), 795681d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedTypeInfo, 7957b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 7958b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 79591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7960b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 7961f85e193739c953358c865005855253af4f68a497John McCallExprResult TreeTransform<Derived>:: 7962f85e193739c953358c865005855253af4f68a497John McCallTransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { 7963f85e193739c953358c865005855253af4f68a497John McCall ExprResult result = getDerived().TransformExpr(E->getSubExpr()); 7964f85e193739c953358c865005855253af4f68a497John McCall if (result.isInvalid()) return ExprError(); 7965f85e193739c953358c865005855253af4f68a497John McCall Expr *subExpr = result.take(); 7966f85e193739c953358c865005855253af4f68a497John McCall 7967f85e193739c953358c865005855253af4f68a497John McCall if (!getDerived().AlwaysRebuild() && 7968f85e193739c953358c865005855253af4f68a497John McCall subExpr == E->getSubExpr()) 7969f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(E); 7970f85e193739c953358c865005855253af4f68a497John McCall 7971f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(new(SemaRef.Context) 7972f85e193739c953358c865005855253af4f68a497John McCall ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy())); 7973f85e193739c953358c865005855253af4f68a497John McCall} 7974f85e193739c953358c865005855253af4f68a497John McCall 7975f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived> 7976f85e193739c953358c865005855253af4f68a497John McCallExprResult TreeTransform<Derived>:: 7977f85e193739c953358c865005855253af4f68a497John McCallTransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { 7978f85e193739c953358c865005855253af4f68a497John McCall TypeSourceInfo *TSInfo 7979f85e193739c953358c865005855253af4f68a497John McCall = getDerived().TransformType(E->getTypeInfoAsWritten()); 7980f85e193739c953358c865005855253af4f68a497John McCall if (!TSInfo) 7981f85e193739c953358c865005855253af4f68a497John McCall return ExprError(); 7982f85e193739c953358c865005855253af4f68a497John McCall 7983f85e193739c953358c865005855253af4f68a497John McCall ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); 7984f85e193739c953358c865005855253af4f68a497John McCall if (Result.isInvalid()) 7985f85e193739c953358c865005855253af4f68a497John McCall return ExprError(); 7986f85e193739c953358c865005855253af4f68a497John McCall 7987f85e193739c953358c865005855253af4f68a497John McCall if (!getDerived().AlwaysRebuild() && 7988f85e193739c953358c865005855253af4f68a497John McCall TSInfo == E->getTypeInfoAsWritten() && 7989f85e193739c953358c865005855253af4f68a497John McCall Result.get() == E->getSubExpr()) 7990f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(E); 7991f85e193739c953358c865005855253af4f68a497John McCall 7992f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), 7993f85e193739c953358c865005855253af4f68a497John McCall E->getBridgeKeywordLoc(), TSInfo, 7994f85e193739c953358c865005855253af4f68a497John McCall Result.get()); 7995f85e193739c953358c865005855253af4f68a497John McCall} 7996f85e193739c953358c865005855253af4f68a497John McCall 7997f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived> 799860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7999454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { 800092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Transform arguments. 800192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor bool ArgChanged = false; 8002ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 8003aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args.reserve(E->getNumArgs()); 8004aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, 8005aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgChanged)) 8006aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 8007aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 800892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (E->getReceiverKind() == ObjCMessageExpr::Class) { 800992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Class message: transform the receiver type. 801092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor TypeSourceInfo *ReceiverTypeInfo 801192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor = getDerived().TransformType(E->getClassReceiverTypeInfo()); 801292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!ReceiverTypeInfo) 8013f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8014c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 801592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // If nothing changed, just retain the existing message send. 801692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!getDerived().AlwaysRebuild() && 801792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) 801892be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 801992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 802092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Build a new class message send. 8021207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SmallVector<SourceLocation, 16> SelLocs; 8022207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis E->getSelectorLocs(SelLocs); 802392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, 802492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getSelector(), 8025207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocs, 802692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getMethodDecl(), 802792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getLeftLoc(), 802892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor move_arg(Args), 802992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getRightLoc()); 803092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 803192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 803292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Instance message: transform the receiver 803392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor assert(E->getReceiverKind() == ObjCMessageExpr::Instance && 803492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor "Only class and instance messages may be instantiated"); 803560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Receiver 803692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor = getDerived().TransformExpr(E->getInstanceReceiver()); 803792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (Receiver.isInvalid()) 8038f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 803992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 804092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // If nothing changed, just retain the existing message send. 804192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!getDerived().AlwaysRebuild() && 804292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Receiver.get() == E->getInstanceReceiver() && !ArgChanged) 804392be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 8044c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 804592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Build a new instance message send. 8046207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SmallVector<SourceLocation, 16> SelLocs; 8047207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis E->getSelectorLocs(SelLocs); 80489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCMessageExpr(Receiver.get(), 804992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getSelector(), 8050207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocs, 805192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getMethodDecl(), 805292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getLeftLoc(), 805392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor move_arg(Args), 805492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getRightLoc()); 8055b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8056b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 80571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 805860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8059454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { 80603fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8061b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8062b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 80631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 806460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8065454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { 80663fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8067b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8068b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 80691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 807060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8071454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { 8072f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // Transform the base expression. 807360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 8074f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Base.isInvalid()) 8075f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8076f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor 8077f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // We don't need to transform the ivar; it will never change. 8078c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8079f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // If nothing changed, just retain the existing expression. 8080f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (!getDerived().AlwaysRebuild() && 8081f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Base.get() == E->getBase()) 80823fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8083c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 80849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), 8085f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->getLocation(), 8086f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->isArrow(), E->isFreeIvar()); 8087b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8088b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 80891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 809060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8091454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { 809212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // 'super' and types never change. Property never changes. Just 809312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // retain the existing expression. 809412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (!E->isObjectReceiver()) 80953fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 80968ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian 8097e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // Transform the base expression. 809860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 8099e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (Base.isInvalid()) 8100f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8101c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8102e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // We don't need to transform the property; it will never change. 8103c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8104e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // If nothing changed, just retain the existing expression. 8105e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (!getDerived().AlwaysRebuild() && 8106e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor Base.get() == E->getBase()) 81073fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8108b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 810912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (E->isExplicitProperty()) 811012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getDerived().RebuildObjCPropertyRefExpr(Base.get(), 811112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getExplicitProperty(), 811212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getLocation()); 811312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 811412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getDerived().RebuildObjCPropertyRefExpr(Base.get(), 81153c3b7f90a863af43fa63043d396553ecf205351cJohn McCall SemaRef.Context.PseudoObjectTy, 811612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getImplicitPropertyGetter(), 811712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getImplicitPropertySetter(), 811812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getLocation()); 8119b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8120b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 81211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 812260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8123454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { 8124f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // Transform the base expression. 812560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 8126f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Base.isInvalid()) 8127f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8128c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8129f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // If nothing changed, just retain the existing expression. 8130f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (!getDerived().AlwaysRebuild() && 8131f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Base.get() == E->getBase()) 81323fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8133c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 81349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), 8135f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->isArrow()); 8136b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8137b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 81381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 813960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8140454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { 8141b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 8142ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> SubExprs(SemaRef); 8143aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor SubExprs.reserve(E->getNumSubExprs()); 8144aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, 8145aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor SubExprs, &ArgumentChanged)) 8146aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 81471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8148b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 8149b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgumentChanged) 81503fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 81511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8152b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), 8153b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(SubExprs), 8154b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 8155b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8156b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 81571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 815860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8159454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { 8160c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall BlockDecl *oldBlock = E->getBlockDecl(); 8161a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 8162c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); 8163c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall BlockScopeInfo *blockScope = SemaRef.getCurBlock(); 8164c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 8165c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); 81660586520acb2f368c874943353a222be7f00c3068Fariborz Jahanian blockScope->TheDecl->setBlockMissingReturnType( 81670586520acb2f368c874943353a222be7f00c3068Fariborz Jahanian oldBlock->blockMissingReturnType()); 8168ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian 8169686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<ParmVarDecl*, 4> params; 8170686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<QualType, 4> paramTypes; 8171a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 8172a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian // Parameter substitution. 8173c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), 8174c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldBlock->param_begin(), 8175c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldBlock->param_size(), 817600b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis 0, paramTypes, ¶ms)) { 817700b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); 817892be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return ExprError(); 817900b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis } 8180c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 8181c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall const FunctionType *exprFunctionType = E->getFunctionType(); 818284b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman QualType exprResultType = 818384b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman getDerived().TransformType(exprFunctionType->getResultType()); 8184a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 8185a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // Don't allow returning a objc interface by value. 818684b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman if (exprResultType->isObjCObjectType()) { 8187c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall getSema().Diag(E->getCaretLocation(), 8188a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor diag::err_object_cannot_be_passed_returned_by_value) 818984b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman << 0 << exprResultType; 819000b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); 8191a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor return ExprError(); 8192a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor } 8193711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 8194c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall QualType functionType = getDerived().RebuildFunctionProtoType( 819584b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman exprResultType, 8196c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall paramTypes.data(), 8197c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall paramTypes.size(), 8198c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldBlock->isVariadic(), 8199c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor 0, RQ_None, 8200c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall exprFunctionType->getExtInfo()); 8201c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->FunctionType = functionType; 8202711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 8203711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Set the parameters on the block decl. 8204c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (!params.empty()) 82054278c654b645402554eb52a48e9c7097c9f1233aDavid Blaikie blockScope->TheDecl->setParams(params); 820684b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman 820784b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman if (!oldBlock->blockMissingReturnType()) { 820884b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman blockScope->HasImplicitReturnType = false; 820984b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman blockScope->ReturnType = exprResultType; 821084b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman } 8211a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 8212711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Transform the body 8213c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall StmtResult body = getDerived().TransformStmt(E->getBody()); 821400b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis if (body.isInvalid()) { 821500b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); 8216711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return ExprError(); 821700b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis } 8218711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 8219c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#ifndef NDEBUG 8220c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall // In builds with assertions, make sure that we captured everything we 8221c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall // captured before. 8222fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor if (!SemaRef.getDiagnostics().hasErrorOccurred()) { 8223fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), 8224fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor e = oldBlock->capture_end(); i != e; ++i) { 8225fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor VarDecl *oldCapture = i->getVariable(); 8226fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor 8227fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor // Ignore parameter packs. 8228fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor if (isa<ParmVarDecl>(oldCapture) && 8229fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor cast<ParmVarDecl>(oldCapture)->isParameterPack()) 8230fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor continue; 8231c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 8232fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor VarDecl *newCapture = 8233fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), 8234fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor oldCapture)); 8235fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor assert(blockScope->CaptureMap.count(newCapture)); 8236fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor } 8237c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall } 8238c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#endif 8239c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 8240c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), 8241c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall /*Scope=*/0); 8242b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8243b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 82441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 824560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8246454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { 8247a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian ValueDecl *ND 8248a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), 8249a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian E->getDecl())); 8250a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian if (!ND) 8251f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 82522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 8253a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian if (!getDerived().AlwaysRebuild() && 8254a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian ND == E->getDecl()) { 8255a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian // Mark it referenced in the new context regardless. 8256a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian // FIXME: this is a bit instantiation-specific. 82575f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkBlockDeclRefReferenced(E); 8258a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 82593fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8260a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian } 8261a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 82622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation()); 826340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getDerived().RebuildDeclRefExpr(NestedNameSpecifierLoc(), 82642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ND, NameInfo, 0); 8265b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 82661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 826761eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattnertemplate<typename Derived> 826861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya LattnerExprResult 826961eee0ca33b29e102f11bab77c8b74cc00e2392bTanya LattnerTreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { 8270b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Cannot transform asType expressions yet"); 827161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner} 8272276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 8273276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmantemplate<typename Derived> 8274276b061970939293f1abaf694bd3ef05b2cbda79Eli FriedmanExprResult 8275276b061970939293f1abaf694bd3ef05b2cbda79Eli FriedmanTreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { 8276dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman QualType RetTy = getDerived().TransformType(E->getType()); 8277dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman bool ArgumentChanged = false; 8278dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ASTOwningVector<Expr*> SubExprs(SemaRef); 8279dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman SubExprs.reserve(E->getNumSubExprs()); 8280dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, 8281dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman SubExprs, &ArgumentChanged)) 8282dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman return ExprError(); 8283dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 8284dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (!getDerived().AlwaysRebuild() && 8285dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman !ArgumentChanged) 8286dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman return SemaRef.Owned(E); 8287dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 8288dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs), 8289dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman RetTy, E->getOp(), E->getRParenLoc()); 8290276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman} 829161eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 8292b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===// 8293b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Type reconstruction 8294b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===// 8295b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 82961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 829785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, 829885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Star) { 82992865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildPointerType(PointeeType, Star, 8300b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor getDerived().getBaseEntity()); 8301b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8302b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 83031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 830485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, 830585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Star) { 83062865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildBlockPointerType(PointeeType, Star, 8307b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor getDerived().getBaseEntity()); 8308b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8309b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 83101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 83111eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 831285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, 831385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall bool WrittenAsLValue, 831485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil) { 83152865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, 831685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Sigil, getDerived().getBaseEntity()); 8317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 83191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 83201eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 832185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, 832285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType ClassType, 832385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil) { 83242865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildMemberPointerType(PointeeType, ClassType, 832585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Sigil, getDerived().getBaseEntity()); 8326577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8327577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8328577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 83291eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 8330577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorTreeTransform<Derived>::RebuildArrayType(QualType ElementType, 8331577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 8332577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt *Size, 8333577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Expr *SizeExpr, 8334577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 8335577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 8336577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (SizeExpr || !Size) 8337577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, 8338577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange, 8339577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor getDerived().getBaseEntity()); 83401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 83411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Types[] = { 83421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, 83431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, 83441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty 8345577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor }; 8346577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const unsigned NumTypes = sizeof(Types) / sizeof(QualType); 8347577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType SizeType; 8348577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor for (unsigned I = 0; I != NumTypes; ++I) 8349577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { 8350577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SizeType = Types[I]; 8351577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor break; 8352577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 83531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 835401f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman // Note that we can return a VariableArrayType here in the case where 835501f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman // the element type was a dependent VariableArrayType. 835601f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman IntegerLiteral *ArraySize 835701f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, 835801f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman /*FIXME*/BracketsRange.getBegin()); 835901f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, 8360577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange, 83611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getDerived().getBaseEntity()); 8362577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 83631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8364577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 83651eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 83661eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, 8367577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 8368577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt &Size, 836985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 837085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange) { 83711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, 837285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall IndexTypeQuals, BracketsRange); 8373577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8374577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8375577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 83761eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 83771eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, 8378577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 837985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 838085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange) { 83811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, 838285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall IndexTypeQuals, BracketsRange); 8383577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 83841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8385577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 83861eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 83871eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, 8388577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 83899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 8390577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 8391577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 83921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 83939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SizeExpr, 8394577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange); 8395577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8396577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8397577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 83981eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 83991eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, 8400577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 84019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 8402577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 8403577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 84041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 84059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SizeExpr, 8406577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange); 8407577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8408577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8409577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8410577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, 8411e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson unsigned NumElements, 8412e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::VectorKind VecKind) { 8413577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor // FIXME: semantic checking! 8414e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); 8415577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 84161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8417577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8418577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, 8419577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumElements, 8420577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc) { 8421577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), 8422577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor NumElements, true); 8423577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IntegerLiteral *VectorSize 84249996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, 84259996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis AttributeLoc); 84269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); 8427577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 84281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8429577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 84301eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 84311eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, 84329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 8433577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc) { 84349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); 8435577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 84361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8437577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8438577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, 84391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType *ParamTypes, 8440577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumParamTypes, 84411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool Variadic, 8442fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman unsigned Quals, 8443c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind RefQualifier, 8444fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman const FunctionType::ExtInfo &Info) { 84451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, 8446c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor Quals, RefQualifier, 8447577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor getDerived().getBaseLocation(), 8448fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman getDerived().getBaseEntity(), 8449fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman Info); 8450577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 84511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8452577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8453a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { 8454a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return SemaRef.Context.getFunctionNoProtoType(T); 8455a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 8456a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 8457a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 8458ed97649e9574b9d854fa4d6109c9333ae0993554John McCallQualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { 8459ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(D && "no decl found"); 8460ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (D->isInvalidDecl()) return QualType(); 8461ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 846292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // FIXME: Doesn't account for ObjCInterfaceDecl! 8463ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TypeDecl *Ty; 8464ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (isa<UsingDecl>(D)) { 8465ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UsingDecl *Using = cast<UsingDecl>(D); 8466ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(Using->isTypeName() && 8467ed97649e9574b9d854fa4d6109c9333ae0993554John McCall "UnresolvedUsingTypenameDecl transformed to non-typename using"); 8468ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 8469ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // A valid resolved using typename decl points to exactly one type decl. 8470ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(++Using->shadow_begin() == Using->shadow_end()); 8471ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); 8472c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8473ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } else { 8474ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(isa<UnresolvedUsingTypenameDecl>(D) && 8475ed97649e9574b9d854fa4d6109c9333ae0993554John McCall "UnresolvedUsingTypenameDecl transformed to non-using decl"); 8476ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Ty = cast<UnresolvedUsingTypenameDecl>(D); 8477ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 8478ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 8479ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return SemaRef.Context.getTypeDeclType(Ty); 8480ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 8481ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 8482ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> 84832a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, 84842a984cad5ac3fdceeff2bd99daa7b90979313475John McCall SourceLocation Loc) { 84852a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return SemaRef.BuildTypeofExprType(E, Loc); 8486577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8487577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8488577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8489577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { 8490577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeOfType(Underlying); 8491577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8492577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8493577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 84942a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, 84952a984cad5ac3fdceeff2bd99daa7b90979313475John McCall SourceLocation Loc) { 84962a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return SemaRef.BuildDecltypeType(E, Loc); 8497577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8498577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8499577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8500ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, 8501ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType::UTTKind UKind, 8502ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt SourceLocation Loc) { 8503ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); 8504ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt} 8505ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 8506ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunttemplate<typename Derived> 8507577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTemplateSpecializationType( 8508833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateName Template, 8509833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation TemplateNameLoc, 851067714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor TemplateArgumentListInfo &TemplateArgs) { 8511d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); 8512577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 85131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8514dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived> 8515b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli FriedmanQualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, 8516b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman SourceLocation KWLoc) { 8517b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return SemaRef.BuildAtomicType(ValueType, KWLoc); 8518b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman} 8519b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 8520b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmantemplate<typename Derived> 85211eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 8522fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 8523d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor bool TemplateKW, 8524d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TemplateDecl *Template) { 8525fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, 8526d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor Template); 8527d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor} 8528d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor 8529d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived> 85301eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 8531fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 8532fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor const IdentifierInfo &Name, 8533fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 853443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 853543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope) { 8536fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor UnqualifiedId TemplateName; 8537fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName.setIdentifier(&Name, NameLoc); 8538d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Sema::TemplateTy Template; 8539e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. 8540d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor getSema().ActOnDependentTemplateName(/*Scope=*/0, 8541e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, TemplateKWLoc, TemplateName, 8542b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType::make(ObjectType), 8543d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor /*EnteringContext=*/false, 8544d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Template); 854543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return Template.get(); 8546d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor} 85471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8548b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 8549ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTemplateName 8550fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 8551ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor OverloadedOperatorKind Operator, 8552fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 8553ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor QualType ObjectType) { 8554ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId Name; 8555fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor // FIXME: Bogus location information. 8556e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; 8557fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); 8558e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. 8559d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Sema::TemplateTy Template; 8560d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor getSema().ActOnDependentTemplateName(/*Scope=*/0, 8561e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, TemplateKWLoc, Name, 8562b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType::make(ObjectType), 8563d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor /*EnteringContext=*/false, 8564d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Template); 8565d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor return Template.template getAsVal<TemplateName>(); 8566ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor} 8567c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8568ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregortemplate<typename Derived> 856960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8570b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, 8571b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 85729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *OrigCallee, 85739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *First, 85749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Second) { 85759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Callee = OrigCallee->IgnoreParenCasts(); 85769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); 85771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8578b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Determine whether this should be a builtin operation. 8579f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl if (Op == OO_Subscript) { 85809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType() && 85819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall !Second->getType()->isOverloadableType()) 85829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().CreateBuiltinArraySubscriptExpr(First, 85839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Callee->getLocStart(), 85849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Second, OpLoc); 85851a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman } else if (Op == OO_Arrow) { 85861a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman // -> is never a builtin operation. 85879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); 85889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall } else if (Second == 0 || isPostIncDec) { 85899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType()) { 8590b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // The argument is not of overloadable type, so try to create a 8591b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // built-in unary operation. 85922de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc 8593b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); 85941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 85959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); 8596b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 8597b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } else { 85989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType() && 85999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall !Second->getType()->isOverloadableType()) { 8600b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Neither of the arguments is an overloadable type, so try to 8601b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // create a built-in binary operation. 86022de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 860360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 86049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); 8605b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 8606f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 86071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8608b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return move(Result); 8609b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 8610b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 86111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 86121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Compute the transformed set of functions (and function templates) to be 8613b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // used during overload resolution. 86146e26689f5d513e24ad7783a4493201930fdeccc0John McCall UnresolvedSet<16> Functions; 86151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 86169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { 8617ba13543329afac4a0d01304ec2ec4924d99306a6John McCall assert(ULE->requiresADL()); 8618ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 8619ba13543329afac4a0d01304ec2ec4924d99306a6John McCall // FIXME: Do we have to check 8620ba13543329afac4a0d01304ec2ec4924d99306a6John McCall // IsAcceptableNonMemberOperatorCandidate for each of these? 86216e26689f5d513e24ad7783a4493201930fdeccc0John McCall Functions.append(ULE->decls_begin(), ULE->decls_end()); 8622ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } else { 86239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl()); 8624ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } 86251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8626b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Add any functions found via argument-dependent lookup. 86279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Args[2] = { First, Second }; 86289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall unsigned NumArgs = 1 + (Second != 0); 86291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8630b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Create the overloaded operator invocation for unary operators. 8631b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (NumArgs == 1 || isPostIncDec) { 86322de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc 8633b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); 86349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); 8635b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 86361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 86375b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor if (Op == OO_Subscript) { 86385b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor SourceLocation LBrace; 86395b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor SourceLocation RBrace; 86405b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor 86415b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { 86425b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo(); 86435b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor LBrace = SourceLocation::getFromRawEncoding( 86445b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor NameLoc.CXXOperatorName.BeginOpNameLoc); 86455b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor RBrace = SourceLocation::getFromRawEncoding( 86465b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor NameLoc.CXXOperatorName.EndOpNameLoc); 86475b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor } else { 86485b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor LBrace = Callee->getLocStart(); 86495b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor RBrace = OpLoc; 86505b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor } 86515b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor 86525b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, 86535b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor First, Second); 86545b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor } 8655f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl 8656b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Create the overloaded operator invocation for binary operators. 86572de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 865860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 8659b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); 8660b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 8661f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 86621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 86631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return move(Result); 8664b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 86651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 866626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregortemplate<typename Derived> 866760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 86689ae2f076ca5ab1feb3ba95629099ec2319833701John McCallTreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, 866926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SourceLocation OperatorLoc, 867026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor bool isArrow, 8671f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor CXXScopeSpec &SS, 867226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor TypeSourceInfo *ScopeType, 867326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SourceLocation CCLoc, 8674fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SourceLocation TildeLoc, 8675a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed) { 86769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall QualType BaseType = Base->getType(); 86779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (Base->isTypeDependent() || Destroyed.getIdentifier() || 867826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor (!isArrow && !BaseType->getAs<RecordType>()) || 8679c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt (isArrow && BaseType->getAs<PointerType>() && 8680bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif !BaseType->getAs<PointerType>()->getPointeeType() 8681bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif ->template getAs<RecordType>())){ 868226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor // This pseudo-destructor expression is still a pseudo-destructor. 86839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, 868426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor isArrow? tok::arrow : tok::period, 8685fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SS, ScopeType, CCLoc, TildeLoc, 8686a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed, 868726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /*FIXME?*/true); 868826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor } 86892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 8690a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); 86912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( 86922577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SemaRef.Context.getCanonicalType(DestroyedType->getType()))); 86932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); 86942577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.setNamedTypeInfo(DestroyedType); 86952577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 869626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor // FIXME: the ScopeType should be tacked onto SS. 86972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 8698e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. 86999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, BaseType, 870026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor OperatorLoc, isArrow, 8701e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, TemplateKWLoc, 8702e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /*FIXME: FirstQualifier*/ 0, 87032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 870426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /*TemplateArgs*/ 0); 870526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor} 870626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor 8707577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} // end namespace clang 8708577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8709577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H 8710