TreeTransform.h revision 5354e77e60e82828c7c2361f5c688c2667ab59cc
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; 1014a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 102d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor public: 103d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { 104d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Old = Self.ForgetPartiallySubstitutedPack(); 105d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor } 1064a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 107d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ~ForgetPartiallySubstitutedPackRAII() { 108d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Self.RememberPartiallySubstitutedPack(Old); 109d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor } 110d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor }; 1114a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 112577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorprotected: 113577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Sema &SemaRef; 1144a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 115dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// \brief The set of local declarations that have been transformed, for 116dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// cases where we are forced to build new declarations within the transformer 117dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// rather than in the subclass (e.g., lambda closure types). 118dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls; 1194a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 1201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 121577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Initializes a new tree transformer. 122b99268b3083c882103bd1bd08bdcc9a76a2b4795Douglas Gregor TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } 1231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 124577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Retrieves a reference to the derived class. 125577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Derived &getDerived() { return static_cast<Derived&>(*this); } 126577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 127577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Retrieves a reference to the derived class. 1281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Derived &getDerived() const { 1291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return static_cast<const Derived&>(*this); 130577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 131577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 13260d7b3a319d84d688752be3870615ac0f111fb16John McCall static inline ExprResult Owned(Expr *E) { return E; } 13360d7b3a319d84d688752be3870615ac0f111fb16John McCall static inline StmtResult Owned(Stmt *S) { return S; } 1349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall 135577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Retrieves a reference to the semantic analysis object used for 136577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// this tree transform. 137577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Sema &getSema() const { return SemaRef; } 1381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 139577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Whether the transformation should always rebuild AST nodes, even 140577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// if none of the children have changed. 141577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 142577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this function to specify when the transformation 143577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// should rebuild all AST nodes. 144577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor bool AlwaysRebuild() { return false; } 1451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 146577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Returns the location of the entity being transformed, if that 147577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// information was not available elsewhere in the AST. 148577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 1491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, returns no source-location information. Subclasses can 150577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// provide an alternative implementation that provides better location 151577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// information. 152577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation getBaseLocation() { return SourceLocation(); } 1531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 154577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Returns the name of the entity being transformed, if that 155577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// information was not available elsewhere in the AST. 156577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 157577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, returns an empty name. Subclasses can provide an alternative 158577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// implementation with a more precise name. 159577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor DeclarationName getBaseEntity() { return DeclarationName(); } 160577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 161b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Sets the "base" location and entity when that 162b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// information is known based on another transformation. 163b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 164b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, the source location and entity are ignored. Subclasses can 165b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// override this function to provide a customized implementation. 166b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor void setBase(SourceLocation Loc, DeclarationName Entity) { } 1671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 168b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief RAII object that temporarily sets the base location and entity 169b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// used for reporting diagnostics in types. 170b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor class TemporaryBase { 171b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TreeTransform &Self; 172b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OldLocation; 173b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor DeclarationName OldEntity; 1741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 175b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor public: 176b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TemporaryBase(TreeTransform &Self, SourceLocation Location, 1771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclarationName Entity) : Self(Self) { 178b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor OldLocation = Self.getDerived().getBaseLocation(); 179b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor OldEntity = Self.getDerived().getBaseEntity(); 1804a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 181ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor if (Location.isValid()) 182ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor Self.getDerived().setBase(Location, Entity); 183b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 185b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ~TemporaryBase() { 186b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Self.getDerived().setBase(OldLocation, OldEntity); 187b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 188b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor }; 1891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determine whether the given type \p T has already been 191577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// transformed. 192577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 193577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses can provide an alternative implementation of this routine 1941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// to short-circuit evaluation when it is known that a given type will 195577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// not change. For example, template instantiation need not traverse 196577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// non-dependent types. 197577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor bool AlreadyTransformed(QualType T) { 198577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return T.isNull(); 199577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 200577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 2016eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Determine whether the given call argument should be dropped, e.g., 2026eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// because it is a default argument. 2036eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// 2046eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// Subclasses can provide an alternative implementation of this routine to 2056eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// determine which kinds of call arguments get dropped. By default, 2066eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// CXXDefaultArgument nodes are dropped (prior to transformation). 2076eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor bool DropCallArgument(Expr *E) { 2086eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return E->isDefaultArgument(); 2096eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor } 2104a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \brief Determine whether we should expand a pack expansion with the 2128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// given set of parameter packs into separate arguments by repeatedly 2138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// transforming the pattern. 2148491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 215b99268b3083c882103bd1bd08bdcc9a76a2b4795Douglas Gregor /// By default, the transformer never tries to expand pack expansions. 2168491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// Subclasses can override this routine to provide different behavior. 2178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param EllipsisLoc The location of the ellipsis that identifies the 2198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// pack expansion. 2208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param PatternRange The source range that covers the entire pattern of 2228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// the pack expansion. 2238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2244a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier /// \param Unexpanded The set of unexpanded parameter packs within the 2258491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// pattern. 2268491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2278491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param ShouldExpand Will be set to \c true if the transformer should 2288491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// expand the corresponding pack expansions into separate arguments. When 2298491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// set, \c NumExpansions must also be set. 2308491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 231d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// \param RetainExpansion Whether the caller should add an unexpanded 232d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// pack expansion after all of the expanded arguments. This is used 233d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// when extending explicitly-specified template argument packs per 234d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// C++0x [temp.arg.explicit]p9. 235d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// 2368491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param NumExpansions The number of separate arguments that will be in 237cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// the expanded form of the corresponding pack expansion. This is both an 238cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// input and an output parameter, which can be set by the caller if the 239cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// number of expansions is known a priori (e.g., due to a prior substitution) 240cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// and will be set by the callee when the number of expansions is known. 241cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// The callee must set this value when \c ShouldExpand is \c true; it may 242cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor /// set this value in other cases. 2438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2444a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier /// \returns true if an error occurred (e.g., because the parameter packs 2454a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier /// are to be instantiated with arguments of different lengths), false 2464a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) 2478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// must be set. 2488491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor bool TryExpandParameterPacks(SourceLocation EllipsisLoc, 2498491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor SourceRange PatternRange, 250a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie llvm::ArrayRef<UnexpandedParameterPack> Unexpanded, 2518491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor bool &ShouldExpand, 252d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool &RetainExpansion, 253cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> &NumExpansions) { 2548491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ShouldExpand = false; 2558491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return false; 2568491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 2574a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 258d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// \brief "Forget" about the partially-substituted pack template argument, 259d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// when performing an instantiation that must preserve the parameter pack 260d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// use. 261d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// 262d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// This routine is meant to be overridden by the template instantiator. 263d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor TemplateArgument ForgetPartiallySubstitutedPack() { 264d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor return TemplateArgument(); 265d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor } 2664a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 267d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// \brief "Remember" the partially-substituted pack template argument 268d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// after performing an instantiation that must preserve the parameter pack 269d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// use. 270d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// 271d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// This routine is meant to be overridden by the template instantiator. 272d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor void RememberPartiallySubstitutedPack(TemplateArgument Arg) { } 2734a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 27412c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor /// \brief Note to the derived class when a function parameter pack is 27512c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor /// being expanded. 27612c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } 2774a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 278577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transforms the given type into another type. 279577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 280a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// By default, this routine transforms a type by creating a 281a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall /// TypeSourceInfo for it and delegating to the appropriate 282a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// function. This is expensive, but we don't mind, because 283a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// this method is deprecated anyway; all users should be 284a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall /// switched to storing TypeSourceInfos. 285577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 286577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \returns the transformed type. 28743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType TransformType(QualType T); 2881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 289a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// \brief Transforms the given type-with-location into a new 290a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// type-with-location. 291a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// 292a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// By default, this routine transforms a type by delegating to the 293a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// appropriate TransformXXXType to build a new type. Subclasses 294a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// may override this function (to take over all type 295a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// transformations) or some set of the TransformXXXType functions 296a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// to alter the transformation. 29743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeSourceInfo *TransformType(TypeSourceInfo *DI); 298a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 299a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// \brief Transform the given type-with-location into a new 300a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// type, collecting location information in the given builder 301a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// as necessary. 302577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 30343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); 3041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 305657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor /// \brief Transform the given statement. 306577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 3071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, this routine transforms a statement by delegating to the 30843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// appropriate TransformXXXStmt function to transform a specific kind of 30943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// statement or the TransformExpr() function to transform an expression. 31043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this function to transform statements using some 31143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// other mechanism. 31243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 31343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \returns the transformed statement. 31460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TransformStmt(Stmt *S); 3151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 316657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor /// \brief Transform the given expression. 317657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor /// 318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, this routine transforms an expression by delegating to the 319b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// appropriate TransformXXXExpr function to build a new expression. 320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this function to transform expressions using some 321b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// other mechanism. 322b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 323b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \returns the transformed expression. 32460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult TransformExpr(Expr *E); 3251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 326aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Transform the given list of expressions. 327aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 3284a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier /// This routine transforms a list of expressions by invoking 3294a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier /// \c TransformExpr() for each subexpression. However, it also provides 330aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// support for variadic templates by expanding any pack expansions (if the 331aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// derived class permits such expansion) along the way. When pack expansions 332aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// are present, the number of outputs may not equal the number of inputs. 333aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 334aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param Inputs The set of expressions to be transformed. 335aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 336aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param NumInputs The number of expressions in \c Inputs. 337aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 338aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param IsCall If \c true, then this transform is being performed on 3394a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier /// function-call arguments, and any arguments that should be dropped, will 340aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// be. 341aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 342aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param Outputs The transformed input expressions will be added to this 343aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// vector. 344aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 345aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param ArgChanged If non-NULL, will be set \c true if any argument changed 346aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// due to transformation. 347aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 348aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \returns true if an error occurred, false otherwise. 349aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, 350686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<Expr *> &Outputs, 351aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool *ArgChanged = 0); 3524a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 353577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transform the given declaration, which is referenced from a type 354577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// or expression. 355577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 356dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// By default, acts as the identity function on declarations, unless the 357dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// transformer has had to transform the declaration itself. Subclasses 358dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// may override this function to provide alternate behavior. 3594a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Decl *TransformDecl(SourceLocation Loc, Decl *D) { 360dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor llvm::DenseMap<Decl *, Decl *>::iterator Known 361dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor = TransformedLocalDecls.find(D); 362dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor if (Known != TransformedLocalDecls.end()) 363dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor return Known->second; 3644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 3654a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return D; 366dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor } 36743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 3684a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier /// \brief Transform the attributes associated with the given declaration and 369dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// place them on the new declaration. 370dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// 371dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// By default, this operation does nothing. Subclasses may override this 372dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// behavior to transform attributes. 373dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor void transformAttrs(Decl *Old, Decl *New) { } 3744a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 375dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// \brief Note that a local declaration has been transformed by this 376dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// transformer. 377dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// 3784a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier /// Local declarations are typically transformed via a call to 379dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// TransformDefinition. However, in some cases (e.g., lambda expressions), 380dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// the transformer itself has to transform the declarations. This routine 381dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// can be overridden by a subclass that keeps track of such mappings. 382dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor void transformedLocalDecl(Decl *Old, Decl *New) { 383dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor TransformedLocalDecls[Old] = New; 384dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor } 3854a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 38643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Transform the definition of the given declaration. 38743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 3881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, invokes TransformDecl() to transform the declaration. 38943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this function to provide alternate behavior. 3904a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Decl *TransformDefinition(SourceLocation Loc, Decl *D) { 3914a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return getDerived().TransformDecl(Loc, D); 3927c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor } 3931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3946cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// \brief Transform the given declaration, which was the first part of a 3956cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// nested-name-specifier in a member access expression. 3966cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// 3974a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier /// This specific declaration transformation only applies to the first 3986cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// identifier in a nested-name-specifier of a member access expression, e.g., 3996cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// the \c T in \c x->T::member 4006cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// 4016cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// By default, invokes TransformDecl() to transform the declaration. 4026cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// Subclasses may override this function to provide alternate behavior. 4034a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { 4044a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); 4056cd219879ffce00920189ec1dcea927a42602961Douglas Gregor } 4064a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 407c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// \brief Transform the given nested-name-specifier with source-location 408c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// information. 409c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// 410c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// By default, transforms all of the types and declarations within the 411c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// nested-name-specifier. Subclasses may override this function to provide 412c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor /// alternate behavior. 413c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc TransformNestedNameSpecifierLoc( 414c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc NNS, 415c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType = QualType(), 416c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *FirstQualifierInScope = 0); 417c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 41881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// \brief Transform the given declaration name. 41981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// 42081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// By default, transforms the types of conversion function, constructor, 42181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// and destructor names and then (if needed) rebuilds the declaration name. 42281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// Identifiers and selectors are returned unmodified. Sublcasses may 42381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// override this function to provide alternate behavior. 4242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo 42543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); 4261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 427577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transform the given template name. 4281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 429fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// \param SS The nested-name-specifier that qualifies the template 430fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// name. This nested-name-specifier must already have been transformed. 431fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// 432fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// \param Name The template name to transform. 433fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// 434fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// \param NameLoc The source location of the template name. 435fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// 4364a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier /// \param ObjectType If we're translating a template name within a member 437fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// access expression, this is the type of the object whose member template 438fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// is being referenced. 439fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// 440fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// \param FirstQualifierInScope If the first part of a nested-name-specifier 441fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// also refers to a name within the current (lexical) scope, this is the 442fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// declaration it refers to. 443fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// 444fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// By default, transforms the template name by transforming the declarations 445fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// and nested-name-specifiers that occur within the template name. 446fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// Subclasses may override this function to provide alternate behavior. 447fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName TransformTemplateName(CXXScopeSpec &SS, 448fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName Name, 449e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation NameLoc, 450fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor QualType ObjectType = QualType(), 451fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor NamedDecl *FirstQualifierInScope = 0); 452fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 453577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transform the given template argument. 454577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 4551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, this operation transforms the type, expression, or 4561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// declaration stored within the template argument and constructs a 457670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor /// new template argument from the transformed result. Subclasses may 458670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor /// override this function to provide alternate behavior. 459833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// 460833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// Returns true if there was an error. 461833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall bool TransformTemplateArgument(const TemplateArgumentLoc &Input, 462833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &Output); 463833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 464fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// \brief Transform the given set of template arguments. 465fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 4664a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier /// By default, this operation transforms all of the template arguments 467fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// in the input set using \c TransformTemplateArgument(), and appends 468fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// the transformed arguments to the output list. 469fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 4707ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// Note that this overload of \c TransformTemplateArguments() is merely 4717ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// a convenience function. Subclasses that wish to override this behavior 4727ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// should override the iterator-based member template version. 4737ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// 474fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// \param Inputs The set of template arguments to be transformed. 475fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 476fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// \param NumInputs The number of template arguments in \p Inputs. 477fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 478fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// \param Outputs The set of transformed template arguments output by this 479fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// routine. 480fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 481fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// Returns true if an error occurred. 482fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, 483fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor unsigned NumInputs, 4847ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentListInfo &Outputs) { 4857ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); 4867ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 4877f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 4887f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// \brief Transform the given set of template arguments. 4897f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// 4904a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier /// By default, this operation transforms all of the template arguments 4917f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// in the input set using \c TransformTemplateArgument(), and appends 4924a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier /// the transformed arguments to the output list. 4937f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// 4947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \param First An iterator to the first template argument. 4957ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// 4967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \param Last An iterator one step past the last template argument. 4977f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// 4987f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// \param Outputs The set of transformed template arguments output by this 4997f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// routine. 5007f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// 5017f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// Returns true if an error occurred. 5027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor template<typename InputIterator> 5037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor bool TransformTemplateArguments(InputIterator First, 5047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Last, 5057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentListInfo &Outputs); 5067f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 507833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. 508833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall void InventTemplateArgumentLoc(const TemplateArgument &Arg, 509833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &ArgLoc); 510833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 511a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall /// \brief Fakes up a TypeSourceInfo for a type. 512a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *InventTypeSourceInfo(QualType T) { 513a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall return SemaRef.Context.getTrivialTypeSourceInfo(T, 514833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall getDerived().getBaseLocation()); 515833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 5161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 517a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT) 518a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT) \ 51943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); 520a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def" 521577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 522cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor QualType TransformFunctionProtoType(TypeLocBuilder &TLB, 523cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor FunctionProtoTypeLoc TL, 524cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor CXXRecordDecl *ThisContext, 525cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor unsigned ThisTypeQuals); 526cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor 52728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult 52828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley TransformSEHHandler(Stmt *Handler); 52928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 5304a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier QualType 53143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TransformTemplateSpecializationType(TypeLocBuilder &TLB, 53243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateSpecializationTypeLoc TL, 53343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template); 53443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 5354a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier QualType 53643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 53743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentTemplateSpecializationTypeLoc TL, 538087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor TemplateName Template, 539087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor CXXScopeSpec &SS); 540a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 5414a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier QualType 542a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 54394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor DependentTemplateSpecializationTypeLoc TL, 54494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NestedNameSpecifierLoc QualifierLoc); 54594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 54621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// \brief Transforms the parameters of a function type into the 54721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// given vectors. 54821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// 54921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// The result vectors should be kept in sync; null entries in the 55021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// variables vector are acceptable. 55121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// 55221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// Return true on error. 553a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor bool TransformFunctionTypeParams(SourceLocation Loc, 554a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParmVarDecl **Params, unsigned NumParams, 555a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor const QualType *ParamTypes, 556686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<QualType> &PTypes, 557686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<ParmVarDecl*> *PVars); 55821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 55921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// \brief Transforms a single function-type parameter. Return null 56021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// on error. 561fb44de956f27875def889482b5393475060392afJohn McCall /// 562fb44de956f27875def889482b5393475060392afJohn McCall /// \param indexAdjustment - A number to add to the parameter's 563fb44de956f27875def889482b5393475060392afJohn McCall /// scope index; can be negative 5646a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm, 565fb44de956f27875def889482b5393475060392afJohn McCall int indexAdjustment, 566d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor llvm::Optional<unsigned> NumExpansions, 567d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor bool ExpectParameterPack); 56821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 56943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); 570833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 57160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); 57260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); 5731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 574612409ece080e814f79e06772c690d603f45fbd6Richard Smith /// \brief Transform the captures and body of a lambda expression. 575612409ece080e814f79e06772c690d603f45fbd6Richard Smith ExprResult TransformLambdaScope(LambdaExpr *E, CXXMethodDecl *CallOperator); 576612409ece080e814f79e06772c690d603f45fbd6Richard Smith 57743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) \ 57860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Transform##Node(Node *S); 579b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent) \ 58060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Transform##Node(Node *E); 5817381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 5824bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 5831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 584577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new pointer type given its pointee type. 585577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 586577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the pointer type. 587577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 58885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); 589577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 590577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new block pointer type given its pointee type. 591577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 5921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, performs semantic analysis when building the block pointer 593577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// type. Subclasses may override this routine to provide different behavior. 59485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); 595577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 59685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// \brief Build a new reference type given the type it references. 597577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 59885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// By default, performs semantic analysis when building the 59985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// reference type. Subclasses may override this routine to provide 60085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// different behavior. 601577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 60285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// \param LValue whether the type was written with an lvalue sigil 60385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// or an rvalue sigil. 60485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildReferenceType(QualType ReferentType, 60585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall bool LValue, 60685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil); 6071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 608577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new member pointer type given the pointee type and the 609577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// class type it refers into. 610577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 611577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the member pointer 612577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// type. Subclasses may override this routine to provide different behavior. 61385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, 61485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil); 6151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 616577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new array type given the element type, size 617577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// modifier, size of the array (if known), size expression, and index type 618577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// qualifiers. 619577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 620577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 621577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Also by default, all of the other Rebuild*Array 623577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildArrayType(QualType ElementType, 624577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 625577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt *Size, 626577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Expr *SizeExpr, 627577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 628577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange); 6291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 630577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new constant array type given the element type, size 631577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// modifier, (known) size of the array, and index type qualifiers. 632577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 633577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 634577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildConstantArrayType(QualType ElementType, 636577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 637577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt &Size, 63885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 63985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange); 640577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 641577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new incomplete array type given the element type, size 642577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// modifier, and index type qualifiers. 643577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 644577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 645577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildIncompleteArrayType(QualType ElementType, 647577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 64885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 64985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange); 650577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 6511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new variable-length array type given the element type, 652577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// size modifier, size expression, and index type qualifiers. 653577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 654577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 655577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildVariableArrayType(QualType ElementType, 657577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 6589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 659577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 660577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange); 661577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 6621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new dependent-sized array type given the element type, 663577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// size modifier, size expression, and index type qualifiers. 664577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 665577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 666577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildDependentSizedArrayType(QualType ElementType, 668577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 6699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 670577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 671577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange); 672577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 673577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new vector type given the element type and 674577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// number of elements. 675577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 676577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the vector type. 677577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 67882287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson QualType RebuildVectorType(QualType ElementType, unsigned NumElements, 679e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::VectorKind VecKind); 6801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 681577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new extended vector type given the element type and 682577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// number of elements. 683577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 684577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the vector type. 685577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 686577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, 687577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc); 6881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new potentially dependently-sized extended vector type 690577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// given the element type and number of elements. 691577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 692577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the vector type. 693577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildDependentSizedExtVectorType(QualType ElementType, 6959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 696577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc); 6971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 698577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new function type. 699577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 700577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the function type. 701577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 702577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildFunctionProtoType(QualType T, 7031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType *ParamTypes, 704577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumParamTypes, 705eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith bool Variadic, bool HasTrailingReturn, 706eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith unsigned Quals, 707c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind RefQualifier, 708fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman const FunctionType::ExtInfo &Info); 7091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 710a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// \brief Build a new unprototyped function type. 711a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType RebuildFunctionNoProtoType(QualType ResultType); 712a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 713ed97649e9574b9d854fa4d6109c9333ae0993554John McCall /// \brief Rebuild an unresolved typename type, given the decl that 714ed97649e9574b9d854fa4d6109c9333ae0993554John McCall /// the UnresolvedUsingTypenameDecl was transformed to. 715ed97649e9574b9d854fa4d6109c9333ae0993554John McCall QualType RebuildUnresolvedUsingType(Decl *D); 716ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 717577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new typedef type. 718162e1c1b487352434552147967c3dd296ebee2f7Richard Smith QualType RebuildTypedefType(TypedefNameDecl *Typedef) { 719577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeDeclType(Typedef); 720577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 721577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 722577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new class/struct/union type. 723577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildRecordType(RecordDecl *Record) { 724577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeDeclType(Record); 725577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 726577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 727577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new Enum type. 728577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildEnumType(EnumDecl *Enum) { 729577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeDeclType(Enum); 730577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 7317da2431c23ef1ee8acb114e39692246e1801afc2John McCall 7321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new typeof(expr) type. 733577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 734577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the typeof type. 735577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 7362a984cad5ac3fdceeff2bd99daa7b90979313475John McCall QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); 737577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 7381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new typeof(type) type. 739577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 740577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, builds a new TypeOfType with the given underlying type. 741577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildTypeOfType(QualType Underlying); 742577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 743ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt /// \brief Build a new unary transform type. 744ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType RebuildUnaryTransformType(QualType BaseType, 745ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType::UTTKind UKind, 746ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt SourceLocation Loc); 747ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 7481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new C++0x decltype type. 749577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 750577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the decltype type. 751577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 7522a984cad5ac3fdceeff2bd99daa7b90979313475John McCall QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); 7531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 75434b41d939a1328f484511c6002ba2456db879a29Richard Smith /// \brief Build a new C++0x auto type. 75534b41d939a1328f484511c6002ba2456db879a29Richard Smith /// 75634b41d939a1328f484511c6002ba2456db879a29Richard Smith /// By default, builds a new AutoType with the given deduced type. 75734b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType RebuildAutoType(QualType Deduced) { 75834b41d939a1328f484511c6002ba2456db879a29Richard Smith return SemaRef.Context.getAutoType(Deduced); 75934b41d939a1328f484511c6002ba2456db879a29Richard Smith } 76034b41d939a1328f484511c6002ba2456db879a29Richard Smith 761577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new template specialization type. 762577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 763577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the template 764577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// specialization type. Subclasses may override this routine to provide 765577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// different behavior. 766577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildTemplateSpecializationType(TemplateName Template, 767833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation TemplateLoc, 76867714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor TemplateArgumentListInfo &Args); 7691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 770075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// \brief Build a new parenthesized type. 771075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// 772075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// By default, builds a new ParenType type from the inner type. 773075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// Subclasses may override this routine to provide different behavior. 774075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType RebuildParenType(QualType InnerType) { 775075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return SemaRef.Context.getParenType(InnerType); 776075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 777075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 778577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new qualified name type. 779577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 780465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// By default, builds a new ElaboratedType type from the keyword, 781465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// the nested-name-specifier and the named type. 782465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// Subclasses may override this routine to provide different behavior. 78321e413fe6305a198564d436ac515497716c47844John McCall QualType RebuildElaboratedType(SourceLocation KeywordLoc, 78421e413fe6305a198564d436ac515497716c47844John McCall ElaboratedTypeKeyword Keyword, 7859e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 7869e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualType Named) { 7874a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return SemaRef.Context.getElaboratedType(Keyword, 7884a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier QualifierLoc.getNestedNameSpecifier(), 7899e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor Named); 7901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 791577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 792577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new typename type that refers to a template-id. 793577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 794e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// By default, builds a new DependentNameType type from the 795e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// nested-name-specifier and the given type. Subclasses may override 796e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// this routine to provide different behavior. 79733500955d731c73717af52088b7fc0e7a85681e7John McCall QualType RebuildDependentTemplateSpecializationType( 79894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor ElaboratedTypeKeyword Keyword, 79994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 80094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor const IdentifierInfo *Name, 80194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor SourceLocation NameLoc, 80267714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor TemplateArgumentListInfo &Args) { 80394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Rebuild the template name. 80494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // TODO: avoid TemplateName abstraction 805fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor CXXScopeSpec SS; 806fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SS.Adopt(QualifierLoc); 8074a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier TemplateName InstName 808fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0); 8094a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 81094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (InstName.isNull()) 81194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return QualType(); 8124a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 81394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // If it's still dependent, make a dependent specialization. 81494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (InstName.getAsDependentTemplateName()) 8154a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, 8164a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier QualifierLoc.getNestedNameSpecifier(), 8174a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Name, 81894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor Args); 8194a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 82094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Otherwise, make an elaborated type wrapping a non-dependent 82194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // specialization. 82294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualType T = 82394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); 82494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (T.isNull()) return QualType(); 8254a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 82694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0) 82794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return T; 8284a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8294a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return SemaRef.Context.getElaboratedType(Keyword, 8304a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier QualifierLoc.getNestedNameSpecifier(), 83194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor T); 83294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor } 83394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 834577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new typename type that refers to an identifier. 835577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 836577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the typename type 837e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// (or elaborated type). Subclasses may override this routine to provide 838577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// different behavior. 839e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, 840e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SourceLocation KeywordLoc, 8412494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 8422494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor const IdentifierInfo *Id, 843e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SourceLocation IdLoc) { 8444033642464e8ba0982f88f34cffad808d247b393Douglas Gregor CXXScopeSpec SS; 8452494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor SS.Adopt(QualifierLoc); 846e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara 8472494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { 8484033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // If the name is still dependent, just build a new dependent name type. 8494033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (!SemaRef.computeDeclContext(SS)) 8504a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return SemaRef.Context.getDependentNameType(Keyword, 8514a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier QualifierLoc.getNestedNameSpecifier(), 8522494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor Id); 8534033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 8544033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 855465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara if (Keyword == ETK_None || Keyword == ETK_Typename) 8562494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, 857e29425bd22fbb9200bbec7b743197b9c6dad3e40Douglas Gregor *Id, IdLoc); 858465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 859465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); 860465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 861e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara // We had a dependent elaborated-type-specifier that has been transformed 8624033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // into a non-dependent elaborated-type-specifier. Find the tag we're 8634033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // referring to. 864e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); 8654033642464e8ba0982f88f34cffad808d247b393Douglas Gregor DeclContext *DC = SemaRef.computeDeclContext(SS, false); 8664033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (!DC) 8674033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 8684033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 8695613876991c80a684595fe8de1f039296a0657ffJohn McCall if (SemaRef.RequireCompleteDeclContext(SS, DC)) 8705613876991c80a684595fe8de1f039296a0657ffJohn McCall return QualType(); 8715613876991c80a684595fe8de1f039296a0657ffJohn McCall 8724033642464e8ba0982f88f34cffad808d247b393Douglas Gregor TagDecl *Tag = 0; 8734033642464e8ba0982f88f34cffad808d247b393Douglas Gregor SemaRef.LookupQualifiedName(Result, DC); 8744033642464e8ba0982f88f34cffad808d247b393Douglas Gregor switch (Result.getResultKind()) { 8754033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::NotFound: 8764033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::NotFoundInCurrentInstantiation: 8774033642464e8ba0982f88f34cffad808d247b393Douglas Gregor break; 8784a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8794033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::Found: 8804033642464e8ba0982f88f34cffad808d247b393Douglas Gregor Tag = Result.getAsSingle<TagDecl>(); 8814033642464e8ba0982f88f34cffad808d247b393Douglas Gregor break; 8824a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8834033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::FoundOverloaded: 8844033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::FoundUnresolvedValue: 8854033642464e8ba0982f88f34cffad808d247b393Douglas Gregor llvm_unreachable("Tag lookup cannot find non-tags"); 8864a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8874033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::Ambiguous: 8884033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // Let the LookupResult structure handle ambiguities. 8894033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 8904033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 8914033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 8924033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (!Tag) { 893446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky // Check where the name exists but isn't a tag type and use that to emit 894446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky // better diagnostics. 895446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); 896446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.LookupQualifiedName(Result, DC); 897446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky switch (Result.getResultKind()) { 898446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky case LookupResult::Found: 899446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky case LookupResult::FoundOverloaded: 900446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky case LookupResult::FoundUnresolvedValue: { 9013e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NamedDecl *SomeDecl = Result.getRepresentativeDecl(); 902446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky unsigned Kind = 0; 903446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky if (isa<TypedefDecl>(SomeDecl)) Kind = 1; 904162e1c1b487352434552147967c3dd296ebee2f7Richard Smith else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2; 905162e1c1b487352434552147967c3dd296ebee2f7Richard Smith else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3; 906446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; 907446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); 908446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky break; 9093e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 910446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky default: 911446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky // FIXME: Would be nice to highlight just the source range. 912446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) 913446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky << Kind << Id << DC; 914446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky break; 915446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky } 9164033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 9174033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 918465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 919bbf34c024398e7bae825686dcff4c3b901ec9f89Richard Trieu if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, 920bbf34c024398e7bae825686dcff4c3b901ec9f89Richard Trieu IdLoc, *Id)) { 921e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; 9224033642464e8ba0982f88f34cffad808d247b393Douglas Gregor SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); 9234033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 9244033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 9254033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 9264033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // Build the elaborated-type-specifier type. 9274033642464e8ba0982f88f34cffad808d247b393Douglas Gregor QualType T = SemaRef.Context.getTypeDeclType(Tag); 9284a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return SemaRef.Context.getElaboratedType(Keyword, 9294a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier QualifierLoc.getNestedNameSpecifier(), 9302494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor T); 931dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor } 9321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9332fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// \brief Build a new pack expansion type. 9342fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// 9352fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// By default, builds a new PackExpansionType type from the given pattern. 9362fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// Subclasses may override this routine to provide different behavior. 9374a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier QualType RebuildPackExpansionType(QualType Pattern, 9382fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor SourceRange PatternRange, 939cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor SourceLocation EllipsisLoc, 940cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 941cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, 942cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions); 9432fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor } 9442fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor 945b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman /// \brief Build a new atomic type given its value type. 946b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman /// 947b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman /// By default, performs semantic analysis when building the atomic type. 948b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman /// Subclasses may override this routine to provide different behavior. 949b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); 950b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 951d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// \brief Build a new template name given a nested name specifier, a flag 952d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// indicating whether the "template" keyword was provided, and the template 953d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// that the template name refers to. 954d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// 955d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// By default, builds the new template name directly. Subclasses may override 956d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// this routine to provide different behavior. 957fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName RebuildTemplateName(CXXScopeSpec &SS, 958d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor bool TemplateKW, 959d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TemplateDecl *Template); 960d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor 961d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// \brief Build a new template name given a nested name specifier and the 962d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// name that is referred to as a template. 963d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// 964d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// By default, performs semantic analysis to determine whether the name can 965d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// be resolved to a specific template, then builds the appropriate kind of 966d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// template name. Subclasses may override this routine to provide different 967d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// behavior. 968fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName RebuildTemplateName(CXXScopeSpec &SS, 969fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor const IdentifierInfo &Name, 970fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 97143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 97243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope); 9731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 974ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// \brief Build a new template name given a nested name specifier and the 975ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// overloaded operator name that is referred to as a template. 976ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// 977ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// By default, performs semantic analysis to determine whether the name can 978ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// be resolved to a specific template, then builds the appropriate kind of 979ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// template name. Subclasses may override this routine to provide different 980ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// behavior. 981fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName RebuildTemplateName(CXXScopeSpec &SS, 982ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor OverloadedOperatorKind Operator, 983fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 984ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor QualType ObjectType); 9851aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 9861aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// \brief Build a new template name given a template template parameter pack 9874a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier /// and the 9881aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// 9891aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// By default, performs semantic analysis to determine whether the name can 9901aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// be resolved to a specific template, then builds the appropriate kind of 9911aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// template name. Subclasses may override this routine to provide different 9921aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// behavior. 9931aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, 9941aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor const TemplateArgument &ArgPack) { 9951aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); 9961aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor } 9971aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 99843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new compound statement. 99943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 100043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 100143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 100260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, 100343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor MultiStmtArg Statements, 100443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation RBraceLoc, 100543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool IsStmtExpr) { 10069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, 100743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor IsStmtExpr); 100843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 100943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 101043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new case statement. 101143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 101243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 101343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 101460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCaseStmt(SourceLocation CaseLoc, 10159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *LHS, 101643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation EllipsisLoc, 10179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *RHS, 101843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation ColonLoc) { 10199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, 102043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor ColonLoc); 102143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 102343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Attach the body to a new case statement. 102443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 102543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 102643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 102760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { 10289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall getSema().ActOnCaseStmtBody(S, Body); 10299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return S; 103043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 103243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new default statement. 103343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 103443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 103543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 103660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, 103743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation ColonLoc, 10389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *SubStmt) { 10399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, 104043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /*CurScope=*/0); 104143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 104343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new label statement. 104443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 104543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 104643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 104757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, 104857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner SourceLocation ColonLoc, Stmt *SubStmt) { 104957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); 105043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1052534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith /// \brief Build a new label statement. 1053534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith /// 1054534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith /// By default, performs semantic analysis to build the new statement. 1055534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith /// Subclasses may override this routine to provide different behavior. 10564990890fc9428f98bef90ba349203a648c592778Alexander Kornienko StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, 10574990890fc9428f98bef90ba349203a648c592778Alexander Kornienko ArrayRef<const Attr*> Attrs, 1058534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith Stmt *SubStmt) { 1059534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt); 1060534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith } 1061534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 106243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new "if" statement. 106343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 106443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 106543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 106660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, 10674a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier VarDecl *CondVar, Stmt *Then, 106857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner SourceLocation ElseLoc, Stmt *Else) { 106944aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); 107043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 107243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Start building a new switch statement. 107343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 107443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 107543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 107660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, 107757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Expr *Cond, VarDecl *CondVar) { 10784a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, 1079d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall CondVar); 108043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 108243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Attach the body to the switch statement. 108343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 108443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 108543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 108660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, 108757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Stmt *Switch, Stmt *Body) { 10889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); 108943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 109043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 109143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new while statement. 109243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 109343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 109443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 109557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, 109657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner VarDecl *CondVar, Stmt *Body) { 10979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); 109843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 110043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new do-while statement. 110143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 110243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 110343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 110460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, 1105ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation WhileLoc, SourceLocation LParenLoc, 1106ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner Expr *Cond, SourceLocation RParenLoc) { 11079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, 11089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond, RParenLoc); 110943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 111043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 111143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new for statement. 111243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 111343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 111443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1115ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, 11164a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Stmt *Init, Sema::FullExprArg Cond, 1117ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner VarDecl *CondVar, Sema::FullExprArg Inc, 1118ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation RParenLoc, Stmt *Body) { 11194a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, 1120ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner CondVar, Inc, RParenLoc, Body); 112143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 11221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 112343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new goto statement. 112443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 112543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 112643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1127ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, 1128ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *Label) { 112957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); 113043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 113143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 113243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new indirect goto statement. 113343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 113443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 113543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 113660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, 1137ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation StarLoc, 1138ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner Expr *Target) { 11399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); 114043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 11411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 114243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new return statement. 114343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 114443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 114543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1146ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { 11479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnReturnStmt(ReturnLoc, Result); 114843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 11491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 115043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new declaration statement. 115143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 115243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 115343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 115460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, 11551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation StartLoc, 115643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation EndLoc) { 1157406c38e8c1f105acfd438f94dfbc17af817aa4a5Richard Smith Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls); 1158406c38e8c1f105acfd438f94dfbc17af817aa4a5Richard Smith return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); 115943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 11601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1161703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// \brief Build a new inline asm statement. 1162703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// 1163703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// By default, performs semantic analysis to build the new statement. 1164703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// Subclasses may override this routine to provide different behavior. 116560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildAsmStmt(SourceLocation AsmLoc, 1166703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool IsSimple, 1167703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool IsVolatile, 1168703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson unsigned NumOutputs, 1169703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson unsigned NumInputs, 1170ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo **Names, 1171703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson MultiExprArg Constraints, 1172703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson MultiExprArg Exprs, 11739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *AsmString, 1174703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson MultiExprArg Clobbers, 1175df4ee102aa909e2f40c294701bfeffac63e8d29bChad Rosier SourceLocation RParenLoc) { 11764a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, 11773fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer NumInputs, Names, Constraints, 11789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs, AsmString, Clobbers, 1179df4ee102aa909e2f40c294701bfeffac63e8d29bChad Rosier RParenLoc); 1180703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 11814dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 11828cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier /// \brief Build a new MS style inline asm statement. 11838cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier /// 11848cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier /// By default, performs semantic analysis to build the new statement. 11858cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier /// Subclasses may override this routine to provide different behavior. 11868cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, 11877bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier SourceLocation LBraceLoc, 118879efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier ArrayRef<Token> AsmToks, 11898cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier SourceLocation EndLoc) { 11907bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, EndLoc); 11918cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier } 11928cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 1193699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett /// \brief Build a new Objective-C \@try statement. 11944dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// 11954dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// By default, performs semantic analysis to build the new statement. 11964dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 119760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, 11989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *TryBody, 11998f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor MultiStmtArg CatchStmts, 12009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Finally) { 12013fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts, 12029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Finally); 12034dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 12044dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 1205be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// \brief Rebuild an Objective-C exception declaration. 1206be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// 1207be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// By default, performs semantic analysis to build the new declaration. 1208be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1209be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, 1210be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TypeSourceInfo *TInfo, QualType T) { 1211ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara return getSema().BuildObjCExceptionDecl(TInfo, T, 1212ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getInnerLocStart(), 1213ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getLocation(), 1214ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getIdentifier()); 1215be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 12164a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 1217699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett /// \brief Build a new Objective-C \@catch statement. 1218be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// 1219be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// By default, performs semantic analysis to build the new statement. 1220be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// Subclasses may override this routine to provide different behavior. 122160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, 1222be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor SourceLocation RParenLoc, 1223be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *Var, 12249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Body) { 1225be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, 12269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Var, Body); 1227be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 12284a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 1229699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett /// \brief Build a new Objective-C \@finally statement. 12304dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// 12314dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// By default, performs semantic analysis to build the new statement. 12324dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 123360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, 12349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Body) { 12359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); 12364dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 12374a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 1238699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett /// \brief Build a new Objective-C \@throw statement. 1239d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor /// 1240d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor /// By default, performs semantic analysis to build the new statement. 1241d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor /// Subclasses may override this routine to provide different behavior. 124260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, 12439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand) { 12449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); 1245d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor } 12464a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 1247699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett /// \brief Rebuild the operand to an Objective-C \@synchronized statement. 124807524039dce5c820f111a1b3f772b4261f004b4aJohn McCall /// 124907524039dce5c820f111a1b3f772b4261f004b4aJohn McCall /// By default, performs semantic analysis to build the new statement. 125007524039dce5c820f111a1b3f772b4261f004b4aJohn McCall /// Subclasses may override this routine to provide different behavior. 125107524039dce5c820f111a1b3f772b4261f004b4aJohn McCall ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, 125207524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Expr *object) { 125307524039dce5c820f111a1b3f772b4261f004b4aJohn McCall return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); 125407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall } 125507524039dce5c820f111a1b3f772b4261f004b4aJohn McCall 1256699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett /// \brief Build a new Objective-C \@synchronized statement. 12578fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// 12588fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// By default, performs semantic analysis to build the new statement. 12598fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// Subclasses may override this routine to provide different behavior. 126060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, 126107524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Expr *Object, Stmt *Body) { 126207524039dce5c820f111a1b3f772b4261f004b4aJohn McCall return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); 12638fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor } 1264c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor 1265699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett /// \brief Build a new Objective-C \@autoreleasepool statement. 1266f85e193739c953358c865005855253af4f68a497John McCall /// 1267f85e193739c953358c865005855253af4f68a497John McCall /// By default, performs semantic analysis to build the new statement. 1268f85e193739c953358c865005855253af4f68a497John McCall /// Subclasses may override this routine to provide different behavior. 1269f85e193739c953358c865005855253af4f68a497John McCall StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, 1270f85e193739c953358c865005855253af4f68a497John McCall Stmt *Body) { 1271f85e193739c953358c865005855253af4f68a497John McCall return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); 1272f85e193739c953358c865005855253af4f68a497John McCall } 1273990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall 1274c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// \brief Build a new Objective-C fast enumeration statement. 1275c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// 1276c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// By default, performs semantic analysis to build the new statement. 1277c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// Subclasses may override this routine to provide different behavior. 127860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, 1279f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *Element, 1280f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Expr *Collection, 1281f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall SourceLocation RParenLoc, 1282f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *Body) { 1283bc20bbb0bf90446a469848c658ca376832f43dc8Sam Panzer StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc, 1284a1eec4bd198b96ef40a7c15cd0e131ca94511ad8Fariborz Jahanian Element, 12859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Collection, 1286a1eec4bd198b96ef40a7c15cd0e131ca94511ad8Fariborz Jahanian RParenLoc); 1287a1eec4bd198b96ef40a7c15cd0e131ca94511ad8Fariborz Jahanian if (ForEachStmt.isInvalid()) 1288a1eec4bd198b96ef40a7c15cd0e131ca94511ad8Fariborz Jahanian return StmtError(); 1289a1eec4bd198b96ef40a7c15cd0e131ca94511ad8Fariborz Jahanian 1290a1eec4bd198b96ef40a7c15cd0e131ca94511ad8Fariborz Jahanian return getSema().FinishObjCForCollectionStmt(ForEachStmt.take(), Body); 1291c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor } 12924a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 129343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new C++ exception declaration. 129443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 129543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new decaration. 129643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1297ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, 1298a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Declarator, 1299ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation StartLoc, 1300ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation IdLoc, 1301ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara IdentifierInfo *Id) { 1302efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator, 1303efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor StartLoc, IdLoc, Id); 1304efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor if (Var) 1305efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor getSema().CurContext->addDecl(Var); 1306efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor return Var; 130743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 130843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 130943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new C++ catch statement. 131043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 131143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 131243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 131360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, 1314f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall VarDecl *ExceptionDecl, 1315f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *Handler) { 13169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, 13179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Handler)); 131843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 13191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 132043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new C++ try statement. 132143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 132243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 132343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 132460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, 1325f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *TryBlock, 1326f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiStmtArg Handlers) { 13273fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers); 132843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 13291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1330ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// \brief Build a new C++0x range-based for statement. 1331ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// 1332ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// By default, performs semantic analysis to build the new statement. 1333ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// Subclasses may override this routine to provide different behavior. 1334ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, 1335ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith SourceLocation ColonLoc, 1336ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Stmt *Range, Stmt *BeginEnd, 1337ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Expr *Cond, Expr *Inc, 1338ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Stmt *LoopVar, 1339ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith SourceLocation RParenLoc) { 1340ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd, 1341e1715b66a878bcab315513351e5df68bfc010d2eSam Panzer Cond, Inc, LoopVar, RParenLoc, false); 1342ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 1343ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 1344ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor /// \brief Build a new C++0x range-based for statement. 1345ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor /// 1346ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor /// By default, performs semantic analysis to build the new statement. 1347ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor /// Subclasses may override this routine to provide different behavior. 13484a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, 1349ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor bool IsIfExists, 1350ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 1351ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor DeclarationNameInfo NameInfo, 1352ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor Stmt *Nested) { 1353ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, 1354ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor QualifierLoc, NameInfo, Nested); 1355ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor } 1356ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 1357ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// \brief Attach body to a C++0x range-based for statement. 1358ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// 1359ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// By default, performs semantic analysis to finish the new statement. 1360ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// Subclasses may override this routine to provide different behavior. 1361ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { 1362ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return getSema().FinishCXXForRangeStmt(ForRange, Body); 1363ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 13644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 136528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult RebuildSEHTryStmt(bool IsCXXTry, 136628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation TryLoc, 136728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *TryBlock, 136828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Handler) { 136928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler); 137028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 137128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 137228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult RebuildSEHExceptStmt(SourceLocation Loc, 137328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Expr *FilterExpr, 137428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block) { 137528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block); 137628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 137728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 137828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, 137928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block) { 138028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getSema().ActOnSEHFinallyBlock(Loc,Block); 138128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 138228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 1383b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression that references a declaration. 1384b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1385b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1386b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 138760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, 1388f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall LookupResult &R, 1389f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall bool RequiresADL) { 1390f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); 1391f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 1392f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 1393f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 1394f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// \brief Build a new expression that references a declaration. 1395f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// 1396f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// By default, performs semantic analysis to build the new expression. 1397f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// Subclasses may override this routine to provide different behavior. 139840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, 1399f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall ValueDecl *VD, 1400f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall const DeclarationNameInfo &NameInfo, 1401f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TemplateArgumentListInfo *TemplateArgs) { 1402a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor CXXScopeSpec SS; 140340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor SS.Adopt(QualifierLoc); 1404dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 1405dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // FIXME: loses template args. 14062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 14072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); 1408b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 14091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1410b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression in parentheses. 14111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1412b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1413b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 141460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, 1415b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParen) { 14169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnParenExpr(LParen, RParen, SubExpr); 1417b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1418b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1419a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief Build a new pseudo-destructor expression. 14201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1421a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1422a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// Subclasses may override this routine to provide different behavior. 142360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, 1424f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SourceLocation OperatorLoc, 1425f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor bool isArrow, 1426f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor CXXScopeSpec &SS, 1427f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor TypeSourceInfo *ScopeType, 1428f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SourceLocation CCLoc, 1429f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SourceLocation TildeLoc, 1430a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed); 14311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1432b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new unary operator expression. 14331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1434b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1435b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 143660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildUnaryOperator(SourceLocation OpLoc, 14372de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc, 14389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr) { 14399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); 1440b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 14411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14428ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Build a new builtin offsetof expression. 14438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// 14448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// By default, performs semantic analysis to build the new expression. 14458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// Subclasses may override this routine to provide different behavior. 144660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, 14478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *Type, 1448f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::OffsetOfComponent *Components, 14498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComponents, 14508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) { 14518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, 14528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor NumComponents, RParenLoc); 14538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 14544a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 14554a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier /// \brief Build a new sizeof, alignof or vec_step expression with a 1456f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne /// type argument. 14571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1458b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1459b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1460f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, 1461f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation OpLoc, 1462f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTrait ExprKind, 1463f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceRange R) { 1464f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); 1465b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1466b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1467f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne /// \brief Build a new sizeof, alignof or vec step expression with an 1468f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne /// expression argument. 14691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1470b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1471b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1472f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, 1473f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTrait ExprKind, 1474f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceRange R) { 147560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 1476e72c55b9a11be9f00fa3f66f7ad6b73b2814e963Chandler Carruth = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); 1477b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 1478f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 14791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14803fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer return Result; 1481b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 14821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1483b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new array subscript expression. 14841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1485b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1486b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 148760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildArraySubscriptExpr(Expr *LHS, 1488b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LBracketLoc, 14899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *RHS, 1490b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RBracketLoc) { 14919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, 14929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LBracketLoc, RHS, 1493b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RBracketLoc); 1494b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1495b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1496b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new call expression. 14971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1498b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1499b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 150060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, 1501b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg Args, 1502e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne SourceLocation RParenLoc, 1503e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne Expr *ExecConfig = 0) { 15049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, 15053fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer Args, RParenLoc, ExecConfig); 1506b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1507b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1508b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new member access expression. 15091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1510b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1511b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 151260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, 1513f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall bool isArrow, 151440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 1515e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 1516f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const DeclarationNameInfo &MemberNameInfo, 1517f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ValueDecl *Member, 1518f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall NamedDecl *FoundDecl, 1519d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *ExplicitTemplateArgs, 1520f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall NamedDecl *FirstQualifierInScope) { 15219138b4e96429cbaae00c52c15c960f72b6645088Richard Smith ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, 15229138b4e96429cbaae00c52c15c960f72b6645088Richard Smith isArrow); 1523d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson if (!Member->getDeclName()) { 1524f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // We have a reference to an unnamed field. This is always the 1525f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // base of an anonymous struct/union member access, i.e. the 1526f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // field is always of record type. 152740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); 1528f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall assert(Member->getType()->isRecordType() && 1529f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall "unnamed member not of record type?"); 15301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15319138b4e96429cbaae00c52c15c960f72b6645088Richard Smith BaseResult = 15329138b4e96429cbaae00c52c15c960f72b6645088Richard Smith getSema().PerformObjectMemberConversion(BaseResult.take(), 1533429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley QualifierLoc.getNestedNameSpecifier(), 1534429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley FoundDecl, Member); 1535429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (BaseResult.isInvalid()) 1536f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 1537429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley Base = BaseResult.take(); 1538f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); 15391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump MemberExpr *ME = 15409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall new (getSema().Context) MemberExpr(Base, isArrow, 15412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Member, MemberNameInfo, 1542f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall cast<FieldDecl>(Member)->getType(), 1543f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall VK, OK_Ordinary); 1544d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson return getSema().Owned(ME); 1545d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson } 15461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 154783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor CXXScopeSpec SS; 154840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor SS.Adopt(QualifierLoc); 154983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 1550429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley Base = BaseResult.take(); 15519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall QualType BaseType = Base->getType(); 1552aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 15536bb8017bb9e828d118e15e59d71c66bba323c364John McCall // FIXME: this involves duplicating earlier analysis in a lot of 15546bb8017bb9e828d118e15e59d71c66bba323c364John McCall // cases; we should avoid this when possible. 15552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); 15566bb8017bb9e828d118e15e59d71c66bba323c364John McCall R.addDecl(FoundDecl); 1557c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R.resolveKind(); 1558c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 15599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, 1560e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, TemplateKWLoc, 1561e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara FirstQualifierInScope, 1562c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R, ExplicitTemplateArgs); 1563b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1565b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new binary operator expression. 15661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1567b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1568b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 156960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildBinaryOperator(SourceLocation OpLoc, 15702de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc, 15719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *LHS, Expr *RHS) { 15729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); 1573b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1574b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1575b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new conditional operator expression. 15761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1577b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1578b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 157960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildConditionalOperator(Expr *Cond, 158056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation QuestionLoc, 158156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *LHS, 158256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation ColonLoc, 158356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *RHS) { 15849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, 15859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS, RHS); 1586b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1587b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1588b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C-style cast expression. 15891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1590b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1591b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 159260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, 15939d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1594b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc, 15959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr) { 1596b042fdfc9460e0018276412257e3c3226f9ea96eJohn McCall return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, 15979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr); 1598b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1600b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new compound literal expression. 16011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1602b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1603b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 160460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, 160542f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *TInfo, 1606b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc, 16079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Init) { 160842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, 16099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init); 1610b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1612b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new extended vector element access expression. 16131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1614b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1615b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 161660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildExtVectorElementExpr(Expr *Base, 1617b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 1618b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation AccessorLoc, 1619b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor IdentifierInfo &Accessor) { 1620aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 1621129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall CXXScopeSpec SS; 16222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); 16239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, Base->getType(), 1624129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall OpLoc, /*IsArrow*/ false, 1625e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, SourceLocation(), 1626e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /*FirstQualifierInScope*/ 0, 16272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 1628129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /* TemplateArgs */ 0); 1629b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1631b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new initializer list 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 RebuildInitList(SourceLocation LBraceLoc, 1636c8fc90a854b4ccba21c85884676a80334159dd94John McCall MultiExprArg Inits, 1637c8fc90a854b4ccba21c85884676a80334159dd94John McCall SourceLocation RBraceLoc, 1638c8fc90a854b4ccba21c85884676a80334159dd94John McCall QualType ResultTy) { 163960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 16403fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc); 1641e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor if (Result.isInvalid() || ResultTy->isDependentType()) 16423fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer return Result; 16434a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 1644e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor // Patch in the result type we were given, which may have been computed 1645e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor // when the initial InitListExpr was built. 1646e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); 1647e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor ILE->setType(ResultTy); 16483fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer return Result; 1649b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1651b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new designated initializer expression. 16521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1653b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1654b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 165560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildDesignatedInitExpr(Designation &Desig, 1656b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg ArrayExprs, 1657b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation EqualOrColonLoc, 1658b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool GNUSyntax, 16599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Init) { 166060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 1661b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, 16629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init); 1663b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 1664f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 16651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 16663fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer return Result; 1667b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1669b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new value-initialized expression. 16701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1671b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds the implicit value initialization without performing 1672b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// any semantic analysis. Subclasses may override this routine to provide 1673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// different behavior. 167460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildImplicitValueInitExpr(QualType T) { 1675b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); 1676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1678b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new \c va_arg expression. 16791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1680b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 168260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, 16839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, TypeSourceInfo *TInfo, 16842cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara SourceLocation RParenLoc) { 16852cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara return getSema().BuildVAArgExpr(BuiltinLoc, 16869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, TInfo, 16872cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara RParenLoc); 1688b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1689b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1690b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression list in parentheses. 16911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1692b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1693b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 169460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildParenListExpr(SourceLocation LParenLoc, 16955b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl MultiExprArg SubExprs, 16965b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl SourceLocation RParenLoc) { 16973fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs); 1698b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1700b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new address-of-label expression. 17011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 17021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, performs semantic analysis, using the name of the label 1703b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// rather than attempting to map the label statement itself. 1704b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 170560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, 1706ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation LabelLoc, LabelDecl *Label) { 170757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); 1708b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1710b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new GNU statement expression. 17111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1712b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1713b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 171460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildStmtExpr(SourceLocation LParenLoc, 17159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *SubStmt, 1716b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 17179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); 1718b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1720b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new __builtin_choose_expr expression. 1721b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1722b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1723b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 172460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, 17259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Cond, Expr *LHS, Expr *RHS, 1726b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1727b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.ActOnChooseExpr(BuiltinLoc, 17289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond, LHS, RHS, 1729b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 1730b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1732f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// \brief Build a new generic selection expression. 1733f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// 1734f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// By default, performs semantic analysis to build the new expression. 1735f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// Subclasses may override this routine to provide different behavior. 1736f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, 1737f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation DefaultLoc, 1738f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 1739f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *ControllingExpr, 1740f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **Types, 1741f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr **Exprs, 1742f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs) { 1743f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, 1744f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ControllingExpr, Types, Exprs, 1745f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne NumAssocs); 1746f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 1747f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 1748b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new overloaded operator call expression. 1749b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1750b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1751b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// The semantic analysis provides the behavior of template instantiation, 1752b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// copying with transformations that turn what looks like an overloaded 17531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// operator call into a use of a builtin operator, performing 1754b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// argument-dependent lookup, etc. Subclasses may override this routine to 1755b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// provide different behavior. 175660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, 1757b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 17589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Callee, 17599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *First, 17609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Second); 17611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new C++ "named" cast expression, such as static_cast or 1763b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// reinterpret_cast. 1764b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1765b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, this routine dispatches to one of the more-specific routines 17661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). 1767b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 176860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, 1769b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Stmt::StmtClass Class, 1770b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 17719d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1772b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1773b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 17749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1775b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1776b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor switch (Class) { 1777b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXStaticCastExprClass: 17789d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, 17791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 1781b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1782b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXDynamicCastExprClass: 17839d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, 17841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 17861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1787b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXReinterpretCastExprClass: 17889d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, 17891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, 1791b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 17921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1793b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXConstCastExprClass: 17949d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, 17951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 17971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1798b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor default: 1799b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Invalid C++ named cast"); 1800b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1801b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1803b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ static_cast expression. 1804b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1805b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1806b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 180760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, 1808b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 18099d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1810b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1811b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 18129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1813b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1814c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, 18159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1816c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1817c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1818b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1819b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1820b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ dynamic_cast expression. 1821b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1822b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1823b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 182460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, 1825b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 18269d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1827b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1828b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 18299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1830b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1831c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, 18329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1833c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1834c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1835b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1836b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1837b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ reinterpret_cast expression. 1838b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1839b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1840b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 184160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, 1842b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 18439d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1844b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1845b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 18469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1847b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1848c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, 18499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1850c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1851c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1852b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1853b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1854b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ const_cast expression. 1855b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1856b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1857b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 185860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, 1859b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 18609d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1861b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1862b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 18639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1864b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1865c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, 18669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1867c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1868c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1869b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1871b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ functional-style cast expression. 1872b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1873b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1874b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1875ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, 1876ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 1877ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor Expr *Sub, 1878ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 1879ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, 1880f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiExprArg(&Sub, 1), 1881b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 1882b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1884b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ typeid(type) expression. 1885b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1886b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1887b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 188860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, 188957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor SourceLocation TypeidLoc, 189057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TypeSourceInfo *Operand, 1891b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 18924a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, 189357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor RParenLoc); 1894b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 189601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 1897b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ typeid(expr) expression. 1898b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1899b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1900b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 190160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, 190257fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor SourceLocation TypeidLoc, 19039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand, 1904b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 19059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, 190657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor RParenLoc); 19071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 19081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 190901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Build a new C++ __uuidof(type) expression. 191001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// 191101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// By default, performs semantic analysis to build the new expression. 191201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// Subclasses may override this routine to provide different behavior. 191301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, 191401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation TypeidLoc, 191501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TypeSourceInfo *Operand, 191601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation RParenLoc) { 19174a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, 191801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet RParenLoc); 191901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 192001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 192101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Build a new C++ __uuidof(expr) expression. 192201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// 192301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// By default, performs semantic analysis to build the new expression. 192401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// Subclasses may override this routine to provide different behavior. 192501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, 192601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation TypeidLoc, 192701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Expr *Operand, 192801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation RParenLoc) { 192901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, 193001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet RParenLoc); 193101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 193201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 1933b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "this" expression. 1934b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1935b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds a new "this" expression without performing any 19361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// semantic analysis. Subclasses may override this routine to provide 1937b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// different behavior. 193860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, 1939ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor QualType ThisType, 1940ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor bool isImplicit) { 1941b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman getSema().CheckCXXThisCapture(ThisLoc); 1942b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getSema().Owned( 1943828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, 1944828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor isImplicit)); 1945b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1946b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1947b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ throw expression. 1948b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1949b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1950b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1951bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, 1952bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor bool IsThrownVariableInScope) { 1953bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); 1954b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1955b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1956b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ default-argument expression. 1957b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1958b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds a new default-argument expression, which does not 1959b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// require any semantic analysis. Subclasses may override this routine to 1960b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// provide different behavior. 19614a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, 1962036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor ParmVarDecl *Param) { 1963036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, 1964036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor Param)); 1965b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1966b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1967b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ zero-initialization expression. 1968b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1969b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1970b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1971ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, 1972ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 1973ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 1974ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, 19755354e77e60e82828c7c2361f5c688c2667ab59ccBenjamin Kramer MultiExprArg(), RParenLoc); 1976b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 19771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1978b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "new" expression. 1979b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1980b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1981b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 198260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, 19831bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor bool UseGlobal, 19841bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation PlacementLParen, 19851bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor MultiExprArg PlacementArgs, 19861bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation PlacementRParen, 19871bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceRange TypeIdParens, 19881bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor QualType AllocatedType, 19891bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *AllocatedTypeInfo, 19901bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor Expr *ArraySize, 19912aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl SourceRange DirectInitRange, 19922aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl Expr *Initializer) { 19931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getSema().BuildCXXNew(StartLoc, UseGlobal, 1994b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor PlacementLParen, 19953fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer PlacementArgs, 1996b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor PlacementRParen, 19974bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor TypeIdParens, 19981bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocatedType, 19991bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocatedTypeInfo, 20009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ArraySize, 20012aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl DirectInitRange, 20022aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl Initializer); 2003b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 20041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2005b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "delete" expression. 2006b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2007b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2008b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 200960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, 2010b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool IsGlobalDelete, 2011b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool IsArrayForm, 20129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand) { 2013b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, 20149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Operand); 2015b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 20161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2017b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new unary type trait expression. 2018b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2019b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2020b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 202160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, 20223d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor SourceLocation StartLoc, 20233d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *T, 20243d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor SourceLocation RParenLoc) { 20253d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); 2026b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2027b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 20286ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// \brief Build a new binary type trait expression. 20296ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// 20306ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// By default, performs semantic analysis to build the new expression. 20316ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// Subclasses may override this routine to provide different behavior. 20326ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, 20336ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation StartLoc, 20346ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *LhsT, 20356ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *RhsT, 20366ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation RParenLoc) { 20376ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); 20386ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 20396ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20404ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief Build a new type trait expression. 20414ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// 20424ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// By default, performs semantic analysis to build the new expression. 20434ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// Subclasses may override this routine to provide different behavior. 20444ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ExprResult RebuildTypeTrait(TypeTrait Trait, 20454ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor SourceLocation StartLoc, 20464ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ArrayRef<TypeSourceInfo *> Args, 20474ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor SourceLocation RParenLoc) { 20484ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); 20494ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 20504a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 205121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// \brief Build a new array type trait expression. 205221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// 205321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// By default, performs semantic analysis to build the new expression. 205421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// Subclasses may override this routine to provide different behavior. 205521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, 205621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SourceLocation StartLoc, 205721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *TSInfo, 205821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Expr *DimExpr, 205921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SourceLocation RParenLoc) { 206021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); 206121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 206221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 2063552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// \brief Build a new expression trait expression. 2064552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// 2065552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// By default, performs semantic analysis to build the new expression. 2066552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// Subclasses may override this routine to provide different behavior. 2067552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExprResult RebuildExpressionTrait(ExpressionTrait Trait, 2068552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation StartLoc, 2069552622067dc45013d240f73952fece703f5e63bdJohn Wiegley Expr *Queried, 2070552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation RParenLoc) { 2071552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); 2072552622067dc45013d240f73952fece703f5e63bdJohn Wiegley } 2073552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 20741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new (previously unresolved) declaration reference 2075b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// expression. 2076b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2077b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2078b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 207900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor ExprResult RebuildDependentScopeDeclRefExpr( 208000cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 2081e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 20822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2083f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall const TemplateArgumentListInfo *TemplateArgs) { 2084b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXScopeSpec SS; 208500cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor SS.Adopt(QualifierLoc); 2086f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 20879d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara if (TemplateArgs || TemplateKWLoc.isValid()) 2088e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, 20899d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara NameInfo, TemplateArgs); 2090f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 20919d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo); 2092b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2093b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2094b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new template-id 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. 209860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, 2099e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 2100e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara LookupResult &R, 2101e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool RequiresADL, 21029d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara const TemplateArgumentListInfo *TemplateArgs) { 2103e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, 2104e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateArgs); 2105b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2106b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2107b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 2108b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2109b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2110b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 211160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXConstructExpr(QualType T, 21127cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara SourceLocation Loc, 21137cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara CXXConstructorDecl *Constructor, 21147cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool IsElidable, 21157cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara MultiExprArg Args, 21167cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates, 21177cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool RequiresZeroInit, 2118428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth CXXConstructExpr::ConstructionKind ConstructKind, 21197cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara SourceRange ParenRange) { 21204e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer SmallVector<Expr*, 8> ConvertedArgs; 21213fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer if (getSema().CompleteConstructorCall(Constructor, Args, Loc, 21224411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor ConvertedArgs)) 2123f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 21244a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 21254411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, 21263fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer ConvertedArgs, 21277cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HadMultipleCandidates, 2128428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth RequiresZeroInit, ConstructKind, 2129428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth ParenRange); 2130b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2131b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2132b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 2133b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2134b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2135b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 2136ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, 2137ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 2138ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor MultiExprArg Args, 2139ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 2140ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, 2141b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LParenLoc, 21423fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer Args, 2143b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 2144b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2145b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2146b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 2147b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2148b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2149b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 2150ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, 2151ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 2152ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor MultiExprArg Args, 2153ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 2154ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, 2155b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LParenLoc, 21563fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer Args, 2157b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 2158b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 21591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2160b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new member reference expression. 2161b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2162b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2163b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 216460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, 21657c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualType BaseType, 21667c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor bool IsArrow, 21677c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor SourceLocation OperatorLoc, 21687c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2169e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 2170129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall NamedDecl *FirstQualifierInScope, 21712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &MemberNameInfo, 2172129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall const TemplateArgumentListInfo *TemplateArgs) { 2173b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXScopeSpec SS; 21747c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor SS.Adopt(QualifierLoc); 21751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, 2177aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OperatorLoc, IsArrow, 2178e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, TemplateKWLoc, 2179e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara FirstQualifierInScope, 21802577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberNameInfo, 21812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TemplateArgs); 2182b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2183b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2184129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Build a new member reference expression. 21853b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// 21863b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// By default, performs semantic analysis to build the new expression. 21873b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// Subclasses may override this routine to provide different behavior. 21889138b4e96429cbaae00c52c15c960f72b6645088Richard Smith ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, 21899138b4e96429cbaae00c52c15c960f72b6645088Richard Smith SourceLocation OperatorLoc, 21909138b4e96429cbaae00c52c15c960f72b6645088Richard Smith bool IsArrow, 21919138b4e96429cbaae00c52c15c960f72b6645088Richard Smith NestedNameSpecifierLoc QualifierLoc, 2192e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 21939138b4e96429cbaae00c52c15c960f72b6645088Richard Smith NamedDecl *FirstQualifierInScope, 21949138b4e96429cbaae00c52c15c960f72b6645088Richard Smith LookupResult &R, 2195129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall const TemplateArgumentListInfo *TemplateArgs) { 21963b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor CXXScopeSpec SS; 21974c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor SS.Adopt(QualifierLoc); 21981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, 2200aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OperatorLoc, IsArrow, 2201e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, TemplateKWLoc, 2202e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara FirstQualifierInScope, 2203c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R, TemplateArgs); 22043b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 22051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22062e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// \brief Build a new noexcept expression. 22072e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// 22082e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// By default, performs semantic analysis to build the new expression. 22092e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// Subclasses may override this routine to provide different behavior. 22102e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { 22112e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); 22122e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl } 22132e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 2214ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Build a new expression to compute the length of a parameter pack. 22154a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, 22164a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier SourceLocation PackLoc, 2217ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation RParenLoc, 2218089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor llvm::Optional<unsigned> Length) { 2219089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor if (Length) 22204a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), 22214a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier OperatorLoc, Pack, PackLoc, 2222089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor RParenLoc, *Length); 22234a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 22244a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), 22254a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier OperatorLoc, Pack, PackLoc, 2226089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor RParenLoc); 2227ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor } 2228ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2229eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard /// \brief Build a new Objective-C boxed expression. 2230eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard /// 2231eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard /// By default, performs semantic analysis to build the new expression. 2232eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard /// Subclasses may override this routine to provide different behavior. 2233eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { 2234eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard return getSema().BuildObjCBoxedExpr(SR, ValueExpr); 2235eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard } 22364a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2237ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Build a new Objective-C array literal. 2238ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// 2239ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// By default, performs semantic analysis to build the new expression. 2240ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// Subclasses may override this routine to provide different behavior. 2241ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult RebuildObjCArrayLiteral(SourceRange Range, 2242ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr **Elements, unsigned NumElements) { 22434a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return getSema().BuildObjCArrayLiteral(Range, 2244ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek MultiExprArg(Elements, NumElements)); 2245ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 22464a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 22474a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, 2248ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *Base, Expr *Key, 2249ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getterMethod, 2250ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *setterMethod) { 2251ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return getSema().BuildObjCSubscriptExpression(RB, Base, Key, 2252ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek getterMethod, setterMethod); 2253ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 2254ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2255ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Build a new Objective-C dictionary literal. 2256ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// 2257ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// By default, performs semantic analysis to build the new expression. 2258ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// Subclasses may override this routine to provide different behavior. 2259ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, 2260ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCDictionaryElement *Elements, 2261ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned NumElements) { 2262ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements); 2263ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 22644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2265699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett /// \brief Build a new Objective-C \@encode expression. 2266b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2267b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2268b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 226960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, 227081d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *EncodeTypeInfo, 2271b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 227281d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, 2273b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc)); 22741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 2275b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 227692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /// \brief Build a new Objective-C class message. 227760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, 227892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Selector Sel, 2279207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelectorLocs, 228092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ObjCMethodDecl *Method, 22814a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier SourceLocation LBracLoc, 228292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor MultiExprArg Args, 228392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor SourceLocation RBracLoc) { 228492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return SemaRef.BuildClassMessage(ReceiverTypeInfo, 228592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ReceiverTypeInfo->getType(), 228692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /*SuperLoc=*/SourceLocation(), 2287207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Sel, Method, LBracLoc, SelectorLocs, 22883fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer RBracLoc, Args); 228992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 229092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 229192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /// \brief Build a new Objective-C instance message. 229260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCMessageExpr(Expr *Receiver, 229392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Selector Sel, 2294207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelectorLocs, 229592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ObjCMethodDecl *Method, 22964a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier SourceLocation LBracLoc, 229792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor MultiExprArg Args, 229892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor SourceLocation RBracLoc) { 22999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildInstanceMessage(Receiver, 23009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Receiver->getType(), 230192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /*SuperLoc=*/SourceLocation(), 2302207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Sel, Method, LBracLoc, SelectorLocs, 23033fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer RBracLoc, Args); 230492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 230592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 2306f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// \brief Build a new Objective-C ivar reference expression. 2307f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// 2308f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// By default, performs semantic analysis to build the new expression. 2309f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// Subclasses may override this routine to provide different behavior. 231060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, 2311f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor SourceLocation IvarLoc, 2312f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor bool IsArrow, bool IsFreeIvar) { 2313f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // FIXME: We lose track of the IsFreeIvar bit. 2314f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor CXXScopeSpec SS; 2315429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Base = getSema().Owned(BaseArg); 2316f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, 2317f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Sema::LookupMemberName); 231860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2319f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FIME:*/IvarLoc, 2320d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, 2321ad00b7705f9bbee81beeac428e7c6587734ab5a6John McCall false); 2322429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Result.isInvalid() || Base.isInvalid()) 2323f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 23244a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2325f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Result.get()) 23263fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer return Result; 23274a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2328429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), 2329e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /*FIXME:*/IvarLoc, IsArrow, 2330e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, SourceLocation(), 2331f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FirstQualifierInScope=*/0, 23324a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier R, 2333f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*TemplateArgs=*/0); 2334f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor } 2335e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor 2336e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// \brief Build a new Objective-C property reference expression. 2337e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// 2338e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2339e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 23404a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, 23413c3b7f90a863af43fa63043d396553ecf205351cJohn McCall ObjCPropertyDecl *Property, 23423c3b7f90a863af43fa63043d396553ecf205351cJohn McCall SourceLocation PropertyLoc) { 2343e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor CXXScopeSpec SS; 2344429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Base = getSema().Owned(BaseArg); 2345e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, 2346e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor Sema::LookupMemberName); 2347e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor bool IsArrow = false; 234860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2349e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*FIME:*/PropertyLoc, 2350d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, false); 2351429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Result.isInvalid() || Base.isInvalid()) 2352f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 23534a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2354e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (Result.get()) 23553fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer return Result; 23564a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2357429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), 23584a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier /*FIXME:*/PropertyLoc, IsArrow, 2359e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, SourceLocation(), 2360e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*FirstQualifierInScope=*/0, 23614a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier R, 2362e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*TemplateArgs=*/0); 2363e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor } 23644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 236512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// \brief Build a new Objective-C property reference expression. 23669cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor /// 23679cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor /// By default, performs semantic analysis to build the new expression. 236812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// Subclasses may override this routine to provide different behavior. 236912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, 237012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *Getter, 237112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *Setter, 237212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation PropertyLoc) { 237312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // Since these expressions can only be value-dependent, we do not 237412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // need to perform semantic analysis again. 237512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return Owned( 237612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, 237712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall VK_LValue, OK_ObjCProperty, 237812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall PropertyLoc, Base)); 23799cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor } 23809cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor 2381f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// \brief Build a new Objective-C "isa" expression. 2382f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// 2383f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// By default, performs semantic analysis to build the new expression. 2384f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// Subclasses may override this routine to provide different behavior. 238560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, 2386f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor bool IsArrow) { 2387f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor CXXScopeSpec SS; 2388429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Base = getSema().Owned(BaseArg); 2389f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, 2390f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Sema::LookupMemberName); 239160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2392f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FIME:*/IsaLoc, 2393d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, false); 2394429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Result.isInvalid() || Base.isInvalid()) 2395f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 23964a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2397f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Result.get()) 23983fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer return Result; 23994a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2400429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), 2401e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /*FIXME:*/IsaLoc, IsArrow, 2402e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, SourceLocation(), 2403f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FirstQualifierInScope=*/0, 24044a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier R, 2405f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*TemplateArgs=*/0); 2406f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor } 24074a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2408b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new shuffle vector expression. 2409b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2410b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2411b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 241260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, 2413f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall MultiExprArg SubExprs, 2414f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation RParenLoc) { 2415b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Find the declaration for __builtin_shufflevector 24161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const IdentifierInfo &Name 2417b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.Context.Idents.get("__builtin_shufflevector"); 2418b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); 2419b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); 2420b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); 24211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2422b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Build a reference to the __builtin_shufflevector builtin 2423b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); 2424429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Callee 2425f4b88a45902af1802a1cb42ba48b1c474474f228John McCall = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false, 2426f4b88a45902af1802a1cb42ba48b1c474474f228John McCall Builtin->getType(), 2427429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley VK_LValue, BuiltinLoc)); 2428429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley Callee = SemaRef.UsualUnaryConversions(Callee.take()); 2429429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Callee.isInvalid()) 2430429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return ExprError(); 24311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Build the CallExpr 2433b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor unsigned NumSubExprs = SubExprs.size(); 24345354e77e60e82828c7c2361f5c688c2667ab59ccBenjamin Kramer Expr **Subs = SubExprs.data(); 2435429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult TheCall = SemaRef.Owned( 2436429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(), 2437b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Subs, NumSubExprs, 24385291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor Builtin->getCallResultType(), 2439f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr::getValueKindForType(Builtin->getResultType()), 2440429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley RParenLoc)); 24411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2442b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Type-check the __builtin_shufflevector expression. 2443429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take())); 2444b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 244543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 24468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \brief Build a new template argument pack expansion. 24478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 24488491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// By default, performs semantic analysis to build a new pack expansion 24494a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier /// for a template argument. Subclasses may override this routine to provide 24508491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// different behavior. 24518491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, 2452cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor SourceLocation EllipsisLoc, 2453cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 24548491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor switch (Pattern.getArgument().getKind()) { 24557a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor case TemplateArgument::Expression: { 24567a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor ExprResult Result 245767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor = getSema().CheckPackExpansion(Pattern.getSourceExpression(), 245867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor EllipsisLoc, NumExpansions); 24597a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor if (Result.isInvalid()) 24607a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor return TemplateArgumentLoc(); 24614a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 24627a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor return TemplateArgumentLoc(Result.get(), Result.get()); 24637a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor } 24644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 24658491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Template: 2466a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor return TemplateArgumentLoc(TemplateArgument( 2467a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor Pattern.getArgument().getAsTemplate(), 24682be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor NumExpansions), 2469b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Pattern.getTemplateQualifierLoc(), 2470a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor Pattern.getTemplateNameLoc(), 2471a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor EllipsisLoc); 24724a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 24738491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Null: 24748491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Integral: 24758491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Declaration: 24768491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Pack: 2477a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 24788491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor llvm_unreachable("Pack expansion pattern has no parameter packs"); 24794a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 24808491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Type: 24814a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (TypeSourceInfo *Expansion 24828491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), 2483cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor EllipsisLoc, 2484cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions)) 24858491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), 24868491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Expansion); 24878491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor break; 24888491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 24894a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 24908491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return TemplateArgumentLoc(); 24918491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 24924a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2493dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// \brief Build a new expression pack expansion. 2494dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// 2495dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// By default, performs semantic analysis to build a new pack expansion 24964a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier /// for an expression. Subclasses may override this routine to provide 2497dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// different behavior. 249867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, 249967fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> NumExpansions) { 250067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); 2501dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2502dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 2503dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman /// \brief Build a new atomic operation expression. 2504dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman /// 2505dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman /// By default, performs semantic analysis to build the new expression. 2506dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman /// Subclasses may override this routine to provide different behavior. 2507dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, 2508dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman MultiExprArg SubExprs, 2509dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman QualType RetTy, 2510dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman AtomicExpr::AtomicOp Op, 2511dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman SourceLocation RParenLoc) { 2512dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman // Just create the expression; there is not any interesting semantic 2513dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman // analysis here because we can't actually build an AtomicExpr until 2514dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman // we are sure it is semantically sound. 2515dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman unsigned NumSubExprs = SubExprs.size(); 25165354e77e60e82828c7c2361f5c688c2667ab59ccBenjamin Kramer Expr **Subs = SubExprs.data(); 2517dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs, 2518dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman NumSubExprs, RetTy, Op, 2519dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman RParenLoc); 2520dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman } 2521dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 252243fed0de4f5bc189e45562491f83d5193eb8dac0John McCallprivate: 2523c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TypeLoc TransformTypeInObjectScope(TypeLoc TL, 2524c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType, 2525c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *FirstQualifierInScope, 2526c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor CXXScopeSpec &SS); 2527b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 2528b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, 2529b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor QualType ObjectType, 2530b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor NamedDecl *FirstQualifierInScope, 2531b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor CXXScopeSpec &SS); 2532577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}; 2533b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 253443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 253560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { 253643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!S) 253743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return SemaRef.Owned(S); 25381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 253943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor switch (S->getStmtClass()) { 254043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor case Stmt::NoStmtClass: break; 25411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 254243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform individual statement nodes 254343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) \ 254443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); 254563c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define ABSTRACT_STMT(Node) 254643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) 25474bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 25481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 254943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform expressions by calling TransformExpr. 255043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) 25517381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 255243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) case Stmt::Node##Class: 25534bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 255443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor { 255560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); 255643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (E.isInvalid()) 2557f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 25581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take())); 256043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 25611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 25621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25633fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 256443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 25651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2567670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregortemplate<typename Derived> 256860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { 2569b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!E) 2570b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.Owned(E); 2571b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2572b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor switch (E->getStmtClass()) { 2573b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::NoStmtClass: break; 2574b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define STMT(Node, Parent) case Stmt::Node##Class: break; 25757381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 2576b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent) \ 2577454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); 25784bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 25791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 25801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25813fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 2582657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor} 2583657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor 2584657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregortemplate<typename Derived> 25854a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosierbool TreeTransform<Derived>::TransformExprs(Expr **Inputs, 25864a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier unsigned NumInputs, 2587aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool IsCall, 2588686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<Expr *> &Outputs, 2589aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool *ArgChanged) { 2590aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor for (unsigned I = 0; I != NumInputs; ++I) { 2591aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor // If requested, drop call arguments that need to be dropped. 2592aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (IsCall && getDerived().DropCallArgument(Inputs[I])) { 2593aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (ArgChanged) 2594aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor *ArgChanged = true; 25954a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2596aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor break; 2597aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 25984a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2599dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { 2600dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Expr *Pattern = Expansion->getPattern(); 26014a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2602686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<UnexpandedParameterPack, 2> Unexpanded; 2603dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 2604dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 26054a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2606dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // Determine whether the set of unexpanded parameter packs can and should 2607dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // be expanded. 2608dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor bool Expand = true; 2609d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 261067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> OrigNumExpansions 261167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor = Expansion->getNumExpansions(); 261267fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; 2613dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), 2614dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Pattern->getSourceRange(), 2615a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 2616d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Expand, RetainExpansion, 2617d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) 2618dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 26194a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2620dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (!Expand) { 2621dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // The transform has determined that we should perform a simple 26224a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier // transformation on the pack expansion, producing another pack 2623dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // expansion. 2624dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 2625dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult OutPattern = getDerived().TransformExpr(Pattern); 2626dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (OutPattern.isInvalid()) 2627dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 26284a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 26294a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), 263067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor Expansion->getEllipsisLoc(), 263167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor NumExpansions); 2632dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (Out.isInvalid()) 2633dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 26344a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2635dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (ArgChanged) 2636dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor *ArgChanged = true; 2637dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Outputs.push_back(Out.get()); 2638dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor continue; 2639dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2640c8fc90a854b4ccba21c85884676a80334159dd94John McCall 2641c8fc90a854b4ccba21c85884676a80334159dd94John McCall // Record right away that the argument was changed. This needs 2642c8fc90a854b4ccba21c85884676a80334159dd94John McCall // to happen even if the array expands to nothing. 2643c8fc90a854b4ccba21c85884676a80334159dd94John McCall if (ArgChanged) *ArgChanged = true; 26444a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2645dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // The transform has determined that we should perform an elementwise 2646dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // expansion of the pattern. Do so. 2647cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 2648dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 2649dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult Out = getDerived().TransformExpr(Pattern); 2650dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (Out.isInvalid()) 2651dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2652dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 265377d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.get()->containsUnexpandedParameterPack()) { 265467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), 265567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor OrigNumExpansions); 265677d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.isInvalid()) 265777d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor return true; 265877d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor } 26594a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2660dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Outputs.push_back(Out.get()); 2661dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 26624a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2663dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor continue; 2664dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 26654a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2666aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor ExprResult Result = getDerived().TransformExpr(Inputs[I]); 2667aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (Result.isInvalid()) 2668aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return true; 26694a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2670aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (Result.get() != Inputs[I] && ArgChanged) 2671aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor *ArgChanged = true; 26724a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 26734a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Outputs.push_back(Result.get()); 2674aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 26754a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2676aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return false; 2677aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor} 2678aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2679aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregortemplate<typename Derived> 2680c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorNestedNameSpecifierLoc 2681c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorTreeTransform<Derived>::TransformNestedNameSpecifierLoc( 2682c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc NNS, 2683c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType, 2684c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *FirstQualifierInScope) { 2685686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; 26864a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; 2687c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Qualifier = Qualifier.getPrefix()) 2688c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Qualifiers.push_back(Qualifier); 2689c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2690c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor CXXScopeSpec SS; 2691c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor while (!Qualifiers.empty()) { 2692c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); 2693c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); 26944a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2695c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor switch (QNNS->getKind()) { 2696c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::Identifier: 26974a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0, 2698c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor *QNNS->getAsIdentifier(), 26994a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Q.getLocalBeginLoc(), 2700c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalEndLoc(), 27014a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ObjectType, false, SS, 2702c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor FirstQualifierInScope, false)) 2703c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(); 27044a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2705c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 27064a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2707c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::Namespace: { 2708c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamespaceDecl *NS 2709c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast_or_null<NamespaceDecl>( 2710c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor getDerived().TransformDecl( 2711c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalBeginLoc(), 2712c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QNNS->getAsNamespace())); 2713c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); 2714c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2715c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 27164a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2717c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::NamespaceAlias: { 2718c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamespaceAliasDecl *Alias 2719c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast_or_null<NamespaceAliasDecl>( 2720c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor getDerived().TransformDecl(Q.getLocalBeginLoc(), 2721c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QNNS->getAsNamespaceAlias())); 27224a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), 2723c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalEndLoc()); 2724c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2725c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 27264a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2727c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::Global: 2728c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // There is no meaningful transformation that one could perform on the 2729c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // global scope. 2730c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); 2731c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 27324a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2733c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::TypeSpecWithTemplate: 2734c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::TypeSpec: { 2735c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, 2736c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor FirstQualifierInScope, SS); 27374a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2738c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (!TL) 2739c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(); 27404a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2741c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || 27424a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier (SemaRef.getLangOpts().CPlusPlus0x && 2743c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TL.getType()->isEnumeralType())) { 27444a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier assert(!TL.getType().hasLocalQualifiers() && 2745c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor "Can't get cv-qualifiers here"); 274695aafb2453e1fecec8dcfd9e125cd78277f45859Richard Smith if (TL.getType()->isEnumeralType()) 274795aafb2453e1fecec8dcfd9e125cd78277f45859Richard Smith SemaRef.Diag(TL.getBeginLoc(), 274895aafb2453e1fecec8dcfd9e125cd78277f45859Richard Smith diag::warn_cxx98_compat_enum_nested_name_spec); 2749c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, 2750c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalEndLoc()); 2751c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2752c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 275300c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu // If the nested-name-specifier is an invalid type def, don't emit an 275400c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu // error because a previous error should have already been emitted. 275500c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL); 275600c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) { 27574a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) 275800c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu << TL.getType() << SS.getRange(); 275900c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu } 2760c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(); 2761c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 27627c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor } 27634a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 27647c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor // The qualifier-in-scope and object type only apply to the leftmost entity. 2765c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor FirstQualifierInScope = 0; 27667c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor ObjectType = QualType(); 2767c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 27684a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2769c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // Don't rebuild the nested-name-specifier if we don't have to. 27704a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && 2771c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor !getDerived().AlwaysRebuild()) 2772c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NNS; 27734a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 27744a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier // If we can re-use the source-location data from the original 2775c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // nested-name-specifier, do so. 2776c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (SS.location_size() == NNS.getDataLength() && 2777c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) 2778c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); 2779c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2780c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // Allocate new nested-name-specifier location information. 2781c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return SS.getWithLocInContext(SemaRef.Context); 2782c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor} 2783c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2784c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived> 27852577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclarationNameInfo 27862577743c5650c646fb705df01403707e94f2df04Abramo BagnaraTreeTransform<Derived> 278743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { 27882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName Name = NameInfo.getName(); 278981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor if (!Name) 27902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(); 279181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor 279281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor switch (Name.getNameKind()) { 279381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::Identifier: 279481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCZeroArgSelector: 279581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCOneArgSelector: 279681499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCMultiArgSelector: 279781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXOperatorName: 27983e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt case DeclarationName::CXXLiteralOperatorName: 279981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXUsingDirective: 28002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return NameInfo; 28011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 280281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXConstructorName: 280381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXDestructorName: 280481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXConversionFunctionName: { 28052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TypeSourceInfo *NewTInfo; 28062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara CanQualType NewCanTy; 28072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { 280843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NewTInfo = getDerived().TransformType(OldTInfo); 280943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (!NewTInfo) 281043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return DeclarationNameInfo(); 281143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); 28122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 28132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara else { 28142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewTInfo = 0; 28152577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); 281643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType NewT = getDerived().TransformType(Name.getCXXNameType()); 28172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (NewT.isNull()) 28182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(); 28192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewCanTy = SemaRef.Context.getCanonicalType(NewT); 28202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 28211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName NewName 28232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), 28242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewCanTy); 28252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NewNameInfo(NameInfo); 28262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewNameInfo.setName(NewName); 28272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewNameInfo.setNamedTypeInfo(NewTInfo); 28282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return NewNameInfo; 282981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor } 28301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 28311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2832b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unknown name kind."); 283381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor} 283481499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor 283581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregortemplate<typename Derived> 28361eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 2837fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, 2838fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName Name, 2839fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 2840fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor QualType ObjectType, 2841fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor NamedDecl *FirstQualifierInScope) { 2842fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { 2843fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateDecl *Template = QTN->getTemplateDecl(); 2844fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor assert(Template && "qualified template name must refer to a template"); 28454a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2846fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateDecl *TransTemplate 28474a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, 2848fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor Template)); 2849fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!TransTemplate) 2850fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 28514a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2852fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2853fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SS.getScopeRep() == QTN->getQualifier() && 2854fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransTemplate == Template) 2855fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 28564a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2857fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), 2858fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransTemplate); 2859fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 28604a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2861fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { 2862fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (SS.getScopeRep()) { 2863fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor // These apply to the scope specifier, not the template. 2864fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType = QualType(); 2865fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor FirstQualifierInScope = 0; 28664a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier } 28674a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2868fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2869fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SS.getScopeRep() == DTN->getQualifier() && 2870fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType.isNull()) 2871fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 28724a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2873fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (DTN->isIdentifier()) { 2874fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(SS, 28754a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier *DTN->getIdentifier(), 2876fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor NameLoc, 2877fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType, 2878fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor FirstQualifierInScope); 2879fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 28804a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2881fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, 2882fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType); 2883fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 28844a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2885fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (TemplateDecl *Template = Name.getAsTemplateDecl()) { 2886fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateDecl *TransTemplate 28874a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, 2888fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor Template)); 2889fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!TransTemplate) 2890fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 28914a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2892fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2893fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransTemplate == Template) 2894fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 28954a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2896fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(TransTemplate); 2897fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 28984a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2899fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (SubstTemplateTemplateParmPackStorage *SubstPack 2900fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = Name.getAsSubstTemplateTemplateParmPack()) { 2901fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateTemplateParmDecl *TransParam 2902fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = cast_or_null<TemplateTemplateParmDecl>( 2903fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); 2904fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!TransParam) 2905fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 29064a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2907fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2908fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransParam == SubstPack->getParameterPack()) 2909fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 29104a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 29114a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return getDerived().RebuildTemplateName(TransParam, 2912fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SubstPack->getArgumentPack()); 2913fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 29144a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2915fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor // These should be getting filtered out before they reach the AST. 2916fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor llvm_unreachable("overloaded function decl survived to here"); 2917fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor} 2918fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2919fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregortemplate<typename Derived> 2920833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallvoid TreeTransform<Derived>::InventTemplateArgumentLoc( 2921833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgument &Arg, 2922833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &Output) { 2923833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation Loc = getDerived().getBaseLocation(); 2924670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor switch (Arg.getKind()) { 2925670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Null: 29269f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin llvm_unreachable("null template argument in TreeTransform"); 2927833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2928833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2929833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Type: 2930833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(Arg, 2931a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); 29324a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2933833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2934833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2935788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: 2936b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor case TemplateArgument::TemplateExpansion: { 2937b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor NestedNameSpecifierLocBuilder Builder; 2938b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor TemplateName Template = Arg.getAsTemplate(); 2939b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) 2940b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); 2941b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) 2942b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); 29434a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2944b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (Arg.getKind() == TemplateArgument::Template) 29454a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Output = TemplateArgumentLoc(Arg, 2946b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.getWithLocInContext(SemaRef.Context), 2947b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Loc); 2948b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor else 29494a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Output = TemplateArgumentLoc(Arg, 2950b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.getWithLocInContext(SemaRef.Context), 2951b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Loc, Loc); 29524a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 2953a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor break; 2954b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor } 2955a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 2956833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Expression: 2957833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); 2958833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2959833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2960833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Declaration: 2961670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Integral: 2962833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Pack: 2963828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); 2964833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2965833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 2966833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 2967833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2968833ca991c1bfc967f0995974ca86f66ba1f666b5John McCalltemplate<typename Derived> 2969833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TreeTransform<Derived>::TransformTemplateArgument( 2970833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc &Input, 2971833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &Output) { 2972833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgument &Arg = Input.getArgument(); 2973833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall switch (Arg.getKind()) { 2974833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Null: 2975833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Integral: 2976833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = Input; 2977833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 29781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2979670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Type: { 2980a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *DI = Input.getTypeSourceInfo(); 2981833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (DI == NULL) 2982a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall DI = InventTypeSourceInfo(Input.getArgument().getAsType()); 2983833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2984833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall DI = getDerived().TransformType(DI); 2985833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!DI) return true; 2986833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2987833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); 2988833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2989670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 29901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2991670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Declaration: { 2992833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: we should never have to transform one of these. 2993972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor DeclarationName Name; 2994972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) 2995972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor Name = ND->getDeclName(); 2996788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor TemporaryBase Rebase(*this, Input.getLocation(), Name); 29977c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); 2998833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!D) return true; 2999833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 3000828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Expr *SourceExpr = Input.getSourceDeclExpression(); 3001828bff2079b6a91ecd7ed5b842c59527d7682789John McCall if (SourceExpr) { 3002828bff2079b6a91ecd7ed5b842c59527d7682789John McCall EnterExpressionEvaluationContext Unevaluated(getSema(), 3003f6702a3927147655206ae729a84339c4fda4c651Richard Smith Sema::ConstantEvaluated); 300460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(SourceExpr); 3005ac6260187b6b2f26faa9264d170d649a501f58a9Eli Friedman E = SemaRef.ActOnConstantExpression(E); 30069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SourceExpr = (E.isInvalid() ? 0 : E.take()); 3007828bff2079b6a91ecd7ed5b842c59527d7682789John McCall } 3008828bff2079b6a91ecd7ed5b842c59527d7682789John McCall 3009828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); 3010833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 3011670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 30121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3013788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: { 3014b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); 3015b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (QualifierLoc) { 3016b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); 3017b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (!QualifierLoc) 3018b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor return true; 3019b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor } 30204a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 30211d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor CXXScopeSpec SS; 30221d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor SS.Adopt(QualifierLoc); 3023788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor TemplateName Template 30241d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), 30251d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor Input.getTemplateNameLoc()); 3026788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor if (Template.isNull()) 3027788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return true; 30284a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 3029b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, 3030788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor Input.getTemplateNameLoc()); 3031788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return false; 3032788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor } 3033a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 3034a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 3035a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor llvm_unreachable("Caller should expand pack expansions"); 3036a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 3037670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Expression: { 3038f6702a3927147655206ae729a84339c4fda4c651Richard Smith // Template argument expressions are constant expressions. 30391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EnterExpressionEvaluationContext Unevaluated(getSema(), 3040f6702a3927147655206ae729a84339c4fda4c651Richard Smith Sema::ConstantEvaluated); 30411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3042833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Expr *InputExpr = Input.getSourceExpression(); 3043833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); 3044833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 3045223de2497fdaacf3a6b0a123c12265ca837abf19Chris Lattner ExprResult E = getDerived().TransformExpr(InputExpr); 3046ac6260187b6b2f26faa9264d170d649a501f58a9Eli Friedman E = SemaRef.ActOnConstantExpression(E); 3047833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (E.isInvalid()) return true; 30489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); 3049833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 3050670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 30511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3052670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Pack: { 3053686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<TemplateArgument, 4> TransformedArgs; 3054670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor TransformedArgs.reserve(Arg.pack_size()); 30551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (TemplateArgument::pack_iterator A = Arg.pack_begin(), 3056670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor AEnd = Arg.pack_end(); 3057670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor A != AEnd; ++A) { 30581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3059833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: preserve source information here when we start 3060833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // caring about parameter packs. 3061833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 3062828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TemplateArgumentLoc InputArg; 3063828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TemplateArgumentLoc OutputArg; 3064828bff2079b6a91ecd7ed5b842c59527d7682789John McCall getDerived().InventTemplateArgumentLoc(*A, InputArg); 3065828bff2079b6a91ecd7ed5b842c59527d7682789John McCall if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) 3066833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 3067833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 3068828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TransformedArgs.push_back(OutputArg.getArgument()); 3069670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 3070910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor 3071910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TemplateArgument *TransformedArgsPtr 3072910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor = new (getSema().Context) TemplateArgument[TransformedArgs.size()]; 3073910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor std::copy(TransformedArgs.begin(), TransformedArgs.end(), 3074910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TransformedArgsPtr); 30754a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr, 30764a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier TransformedArgs.size()), 3077910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor Input.getLocInfo()); 3078833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 3079670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 3080670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 30811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3082670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Work around bogus GCC warning 3083833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 3084670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor} 3085670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor 30867ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// \brief Iterator adaptor that invents template argument location information 30877ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// for each of the template arguments in its underlying iterator. 30887ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename Derived, typename InputIterator> 30897ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorclass TemplateArgumentLocInventIterator { 30907ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TreeTransform<Derived> &Self; 30917ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Iter; 30924a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 30937ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorpublic: 30947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc value_type; 30957ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc reference; 30967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef typename std::iterator_traits<InputIterator>::difference_type 30977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor difference_type; 30987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef std::input_iterator_tag iterator_category; 30994a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 31007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class pointer { 31017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Arg; 31024a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 31037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 31047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } 31054a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 31067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLoc *operator->() const { return &Arg; } 31077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 31084a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 31097ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator() { } 31104a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 31117ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, 31127ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Iter) 31137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor : Self(Self), Iter(Iter) { } 31144a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 31157ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator &operator++() { 31167ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++Iter; 31177ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return *this; 3118fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor } 31194a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 31207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator operator++(int) { 31217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator Old(*this); 31227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++(*this); 31237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Old; 31247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 31254a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 31267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor reference operator*() const { 31277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Result; 31287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor Self.InventTemplateArgumentLoc(*Iter, Result); 31297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Result; 31307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 31314a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 31327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor pointer operator->() const { return pointer(**this); } 31334a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 31347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator==(const TemplateArgumentLocInventIterator &X, 31357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLocInventIterator &Y) { 31367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Iter == Y.Iter; 31377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 3138fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 31397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator!=(const TemplateArgumentLocInventIterator &X, 31407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLocInventIterator &Y) { 31417ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Iter != Y.Iter; 31427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 31437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor}; 31444a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 31457f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregortemplate<typename Derived> 31467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename InputIterator> 31477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorbool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, 31487ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Last, 31497f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor TemplateArgumentListInfo &Outputs) { 31507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor for (; First != Last; ++First) { 31517f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor TemplateArgumentLoc Out; 31527ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc In = *First; 31534a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 31548491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (In.getArgument().getKind() == TemplateArgument::Pack) { 31558491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // Unpack argument packs, which we translate them into separate 31568491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // arguments. 31577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // FIXME: We could do much better if we could guarantee that the 31587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // TemplateArgumentLocInfo for the pack expansion would be usable for 31597ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // all of the template arguments in the argument pack. 31604a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier typedef TemplateArgumentLocInventIterator<Derived, 31617ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgument::pack_iterator> 31627ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor PackLocIterator; 31634a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (TransformTemplateArguments(PackLocIterator(*this, 31647ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor In.getArgument().pack_begin()), 31657ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor PackLocIterator(*this, 31667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor In.getArgument().pack_end()), 31677ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor Outputs)) 31687ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return true; 31694a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 31708491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 31718491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 31724a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 31738491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (In.getArgument().isPackExpansion()) { 31748491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // We have a pack expansion, for which we will be substituting into 31758491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // the pattern. 31768491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor SourceLocation Ellipsis; 3177cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> OrigNumExpansions; 31788491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc Pattern 31794a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions, 3180cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor getSema().Context); 31814a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 3182686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<UnexpandedParameterPack, 2> Unexpanded; 31838491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 31848491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 31854a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 31868491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // Determine whether the set of unexpanded parameter packs can and should 31878491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // be expanded. 31888491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor bool Expand = true; 3189d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 3190cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; 31918491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TryExpandParameterPacks(Ellipsis, 31928491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Pattern.getSourceRange(), 3193a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 31944a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Expand, 3195d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor RetainExpansion, 3196d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) 31978491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 31984a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 31998491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (!Expand) { 32008491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The transform has determined that we should perform a simple 32014a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier // transformation on the pack expansion, producing another pack 32028491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // expansion. 32038491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc OutPattern; 32048491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 32058491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) 32068491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 32074a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 3208cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, 3209cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions); 32108491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (Out.getArgument().isNull()) 32118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 32124a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 32138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Outputs.addArgument(Out); 32148491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 32158491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 32164a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 32178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The transform has determined that we should perform an elementwise 32188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // expansion of the pattern. Do so. 3219cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 32208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 32218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 32228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, Out)) 32238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 32244a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 322577d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.getArgument().containsUnexpandedParameterPack()) { 3226cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Out = getDerived().RebuildPackExpansion(Out, Ellipsis, 3227cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor OrigNumExpansions); 322877d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.getArgument().isNull()) 322977d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor return true; 323077d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor } 32314a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 32328491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Outputs.addArgument(Out); 32338491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 32344a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 32353cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 32363cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // forgetting the partially-substituted parameter pack. 32373cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (RetainExpansion) { 32383cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 32394a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 32403cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, Out)) 32413cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor return true; 32424a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 3243cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Out = getDerived().RebuildPackExpansion(Out, Ellipsis, 3244cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor OrigNumExpansions); 32453cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (Out.getArgument().isNull()) 32463cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor return true; 32474a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 32483cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor Outputs.addArgument(Out); 32493cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor } 32504a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 32518491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 32528491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 32534a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 32544a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier // The simple case: 32558491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(In, Out)) 32567f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return true; 32574a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 32587f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor Outputs.addArgument(Out); 32597f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor } 32604a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 32617f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return false; 32627f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 32637f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor} 32647f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 3265577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 3266577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// Type transformation 3267577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 3268577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3269577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 327043fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::TransformType(QualType T) { 3271577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (getDerived().AlreadyTransformed(T)) 3272577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return T; 32731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3274a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Temporary workaround. All of these transformations should 3275a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // eventually turn into transformations on TypeLocs. 3276c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, 3277c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor getDerived().getBaseLocation()); 32784a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 327943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeSourceInfo *NewDI = getDerived().TransformType(DI); 32801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3281a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (!NewDI) 3282a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 32831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3284a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return NewDI->getType(); 3285577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 32861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3287577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 328843fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { 3289f6702a3927147655206ae729a84339c4fda4c651Richard Smith // Refine the base location to the type's location. 3290f6702a3927147655206ae729a84339c4fda4c651Richard Smith TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), 3291f6702a3927147655206ae729a84339c4fda4c651Richard Smith getDerived().getBaseEntity()); 3292a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlreadyTransformed(DI->getType())) 3293a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return DI; 32941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3295a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder TLB; 32961bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 3297a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLoc TL = DI->getTypeLoc(); 3298a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TLB.reserve(TL.getFullDataSize()); 32991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 330043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result = getDerived().TransformType(TLB, TL); 3301a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3302a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return 0; 33031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3304a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall return TLB.getTypeSourceInfo(SemaRef.Context, Result); 3305577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 33061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3308a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 330943fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { 3310a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall switch (T.getTypeLocClass()) { 3311a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT) 3312a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT) \ 3313a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall case TypeLoc::CLASS: \ 331443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); 3315a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def" 3316a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3317577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 33189f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin llvm_unreachable("unhandled type loc!"); 3319577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 33201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3321a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// FIXME: By default, this routine adds type qualifiers only to types 3322a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that can have qualifiers, and silently suppresses those qualifiers 3323a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that are not permitted (e.g., qualifiers on reference or function 3324a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// types). This is the right thing for template instantiation, but 3325a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// probably not for other clients. 33261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 33271eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3328a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, 332943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualifiedTypeLoc T) { 3330a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor Qualifiers Quals = T.getType().getLocalQualifiers(); 3331a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 333243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); 3333a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3334577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 33351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3336a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Silently suppress qualifiers if the result type can't be qualified. 3337a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: this is the right thing for template instantiation, but 3338a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // probably not for other clients. 3339a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result->isFunctionType() || Result->isReferenceType()) 3340a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 33411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3342f85e193739c953358c865005855253af4f68a497John McCall // Suppress Objective-C lifetime qualifiers if they don't make sense for the 3343e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // resulting type. 3344e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor if (Quals.hasObjCLifetime()) { 3345e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor if (!Result->isObjCLifetimeType() && !Result->isDependentType()) 3346e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Quals.removeObjCLifetime(); 33474020caec546d221170072d2388b57d151cb26111Douglas Gregor else if (Result.getObjCLifetime()) { 33484a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier // Objective-C ARC: 3349e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // A lifetime qualifier applied to a substituted template parameter 3350e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // overrides the lifetime qualifier from the template argument. 33514a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (const SubstTemplateTypeParmType *SubstTypeParam 3352e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor = dyn_cast<SubstTemplateTypeParmType>(Result)) { 3353e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor QualType Replacement = SubstTypeParam->getReplacementType(); 3354e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Qualifiers Qs = Replacement.getQualifiers(); 3355e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Qs.removeObjCLifetime(); 33564a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Replacement 3357e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), 3358e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Qs); 3359e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Result = SemaRef.Context.getSubstTemplateTypeParmType( 33604a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier SubstTypeParam->getReplacedParameter(), 3361e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Replacement); 3362e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor TLB.TypeWasModifiedSafely(Result); 3363e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } else { 33644020caec546d221170072d2388b57d151cb26111Douglas Gregor // Otherwise, complain about the addition of a qualifier to an 33654020caec546d221170072d2388b57d151cb26111Douglas Gregor // already-qualified type. 33664020caec546d221170072d2388b57d151cb26111Douglas Gregor SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange(); 3367b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant) 33684020caec546d221170072d2388b57d151cb26111Douglas Gregor << Result << R; 33694a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 3370e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Quals.removeObjCLifetime(); 3371e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } 3372e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } 3373e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } 33742865474261a608c7873b87ba4af110d17907896dJohn McCall if (!Quals.empty()) { 33752865474261a608c7873b87ba4af110d17907896dJohn McCall Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); 33762865474261a608c7873b87ba4af110d17907896dJohn McCall TLB.push<QualifiedTypeLoc>(Result); 33772865474261a608c7873b87ba4af110d17907896dJohn McCall // No location information to preserve. 33782865474261a608c7873b87ba4af110d17907896dJohn McCall } 3379a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3380a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3381a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 3382a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 338343fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived> 3384b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTypeLoc 3385b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, 338643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 338743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *UnqualLookup, 3388b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor CXXScopeSpec &SS) { 3389b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor QualType T = TL.getType(); 339043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (getDerived().AlreadyTransformed(T)) 3391b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TL; 33924a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 339343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeLocBuilder TLB; 339443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result; 33954a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 339643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (isa<TemplateSpecializationType>(T)) { 3397b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TemplateSpecializationTypeLoc SpecTL 3398b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = cast<TemplateSpecializationTypeLoc>(TL); 33994a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 340043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template = 3401b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor getDerived().TransformTemplateName(SS, 3402b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL.getTypePtr()->getTemplateName(), 3403b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL.getTemplateNameLoc(), 340443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType, UnqualLookup); 34054a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (Template.isNull()) 3406b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TypeLoc(); 34074a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 34084a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, 3409b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Template); 341043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } else if (isa<DependentTemplateSpecializationType>(T)) { 3411b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor DependentTemplateSpecializationTypeLoc SpecTL 3412b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = cast<DependentTemplateSpecializationTypeLoc>(TL); 34134a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 3414b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TemplateName Template 34154a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier = getDerived().RebuildTemplateName(SS, 34164a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier *SpecTL.getTypePtr()->getIdentifier(), 341755d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara SpecTL.getTemplateNameLoc(), 3418b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor ObjectType, UnqualLookup); 3419a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (Template.isNull()) 3420b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TypeLoc(); 34214a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 34224a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Result = getDerived().TransformDependentTemplateSpecializationType(TLB, 3423b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL, 3424087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor Template, 3425087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor SS); 342643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } else { 342743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // Nothing special needs to be done for these. 3428b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Result = getDerived().TransformType(TLB, TL); 342943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } 34304a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 34314a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (Result.isNull()) 3432b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TypeLoc(); 34334a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 3434b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc(); 343543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall} 343643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 3437c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived> 3438b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTypeSourceInfo * 3439b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, 3440c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType, 3441c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *UnqualLookup, 3442c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor CXXScopeSpec &SS) { 3443c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // FIXME: Painfully copy-paste from the above! 34444a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 3445b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor QualType T = TSInfo->getType(); 3446c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (getDerived().AlreadyTransformed(T)) 3447b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TSInfo; 34484a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 3449c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TypeLocBuilder TLB; 3450c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType Result; 34514a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 3452b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TypeLoc TL = TSInfo->getTypeLoc(); 3453c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (isa<TemplateSpecializationType>(T)) { 3454c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TemplateSpecializationTypeLoc SpecTL 3455c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast<TemplateSpecializationTypeLoc>(TL); 34564a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 3457b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TemplateName Template 3458b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = getDerived().TransformTemplateName(SS, 3459fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SpecTL.getTypePtr()->getTemplateName(), 3460fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SpecTL.getTemplateNameLoc(), 3461c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor ObjectType, UnqualLookup); 34624a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (Template.isNull()) 3463b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return 0; 34644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 34654a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, 3466c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Template); 3467c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } else if (isa<DependentTemplateSpecializationType>(T)) { 3468c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor DependentTemplateSpecializationTypeLoc SpecTL 3469c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast<DependentTemplateSpecializationTypeLoc>(TL); 34704a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 3471a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateName Template 34724a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier = getDerived().RebuildTemplateName(SS, 34734a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier *SpecTL.getTypePtr()->getIdentifier(), 347455d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara SpecTL.getTemplateNameLoc(), 34757c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor ObjectType, UnqualLookup); 3476a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (Template.isNull()) 3477b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return 0; 34784a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 34794a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Result = getDerived().TransformDependentTemplateSpecializationType(TLB, 3480a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor SpecTL, 3481087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor Template, 3482087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor SS); 3483c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } else { 3484c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // Nothing special needs to be done for these. 3485c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Result = getDerived().TransformType(TLB, TL); 3486c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 34874a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 34884a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (Result.isNull()) 3489b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return 0; 34904a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 3491b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TLB.getTypeSourceInfo(SemaRef.Context, Result); 3492c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor} 3493c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3494a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate <class TyLoc> static inline 3495a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { 3496a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TyLoc NewT = TLB.push<TyLoc>(T.getType()); 3497a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewT.setNameLoc(T.getNameLoc()); 3498a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return T.getType(); 3499a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 3500a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3501a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3502a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, 350343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall BuiltinTypeLoc T) { 3504ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); 3505ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor NewT.setBuiltinLoc(T.getBuiltinLoc()); 3506ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor if (T.needsExtraLocalData()) 3507ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); 3508ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return T.getType(); 3509577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3510577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 35111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3512a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, 351343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ComplexTypeLoc T) { 3514a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: recurse? 3515a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return TransformTypeSpecType(TLB, T); 3516a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 35171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3518a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3519a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, 352043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall PointerTypeLoc TL) { 35214a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier QualType PointeeType 35224a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier = getDerived().TransformType(TLB, TL.getPointeeLoc()); 352392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (PointeeType.isNull()) 352492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return QualType(); 352592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 352692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor QualType Result = TL.getType(); 3527c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (PointeeType->getAs<ObjCObjectType>()) { 352892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // A dependent pointer type 'T *' has is being transformed such 352992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // that an Objective-C class type is being replaced for 'T'. The 353092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // resulting pointer type is an ObjCObjectPointerType, not a 353192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // PointerType. 3532c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); 35334a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 3534c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); 3535c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall NewT.setStarLoc(TL.getStarLoc()); 353692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return Result; 353792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 353843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 353992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (getDerived().AlwaysRebuild() || 354092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor PointeeType != TL.getPointeeLoc().getType()) { 354192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); 354292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (Result.isNull()) 354392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return QualType(); 354492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 35454a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 3546f85e193739c953358c865005855253af4f68a497John McCall // Objective-C ARC can add lifetime qualifiers to the type that we're 3547f85e193739c953358c865005855253af4f68a497John McCall // pointing to. 3548f85e193739c953358c865005855253af4f68a497John McCall TLB.TypeWasModifiedSafely(Result->getPointeeType()); 35494a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 355092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); 355192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor NewT.setSigilLoc(TL.getSigilLoc()); 35524a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return Result; 3553577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3554577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 35551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 35561eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3557a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, 355843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall BlockPointerTypeLoc TL) { 3559db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor QualType PointeeType 35604a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier = getDerived().TransformType(TLB, TL.getPointeeLoc()); 35614a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (PointeeType.isNull()) 35624a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return QualType(); 35634a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 35644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier QualType Result = TL.getType(); 35654a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (getDerived().AlwaysRebuild() || 35664a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier PointeeType != TL.getPointeeLoc().getType()) { 35674a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Result = getDerived().RebuildBlockPointerType(PointeeType, 3568db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor TL.getSigilLoc()); 3569db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor if (Result.isNull()) 3570db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor return QualType(); 3571db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor } 3572db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor 357339968adc66ab02275d2f561e372a20ae454bd4e7Douglas Gregor BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); 3574db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor NewT.setSigilLoc(TL.getSigilLoc()); 3575db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor return Result; 3576a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 35771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 357885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// Transforms a reference type. Note that somewhat paradoxically we 357985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// don't care whether the type itself is an l-value type or an r-value 358085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// type; we only care if the type was *written* as an l-value type 358185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// or an r-value type. 358285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCalltemplate<typename Derived> 358385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType 358485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, 358543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ReferenceTypeLoc TL) { 358685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall const ReferenceType *T = TL.getTypePtr(); 358785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 358885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall // Note that this works with the pointee-as-written. 358985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 359085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (PointeeType.isNull()) 359185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return QualType(); 359285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 359385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType Result = TL.getType(); 359485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (getDerived().AlwaysRebuild() || 359585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall PointeeType != T->getPointeeTypeAsWritten()) { 359685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Result = getDerived().RebuildReferenceType(PointeeType, 359785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->isSpelledAsLValue(), 359885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getSigilLoc()); 359985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (Result.isNull()) 360085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return QualType(); 360185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall } 360285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 3603f85e193739c953358c865005855253af4f68a497John McCall // Objective-C ARC can add lifetime qualifiers to the type that we're 3604f85e193739c953358c865005855253af4f68a497John McCall // referring to. 3605f85e193739c953358c865005855253af4f68a497John McCall TLB.TypeWasModifiedSafely( 3606f85e193739c953358c865005855253af4f68a497John McCall Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); 3607f85e193739c953358c865005855253af4f68a497John McCall 360885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall // r-value references can be rebuilt as l-value references. 360985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall ReferenceTypeLoc NewTL; 361085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (isa<LValueReferenceType>(Result)) 361185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL = TLB.push<LValueReferenceTypeLoc>(Result); 361285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall else 361385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL = TLB.push<RValueReferenceTypeLoc>(Result); 361485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL.setSigilLoc(TL.getSigilLoc()); 361585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 361685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return Result; 361785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall} 361885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 3619a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3620a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3621a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, 362243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall LValueReferenceTypeLoc TL) { 362343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TransformReferenceType(TLB, TL); 3624a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 36251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3626a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3627a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3628a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, 362943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall RValueReferenceTypeLoc TL) { 363043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TransformReferenceType(TLB, TL); 3631577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 36321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3633577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 36341eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3635a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, 363643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall MemberPointerTypeLoc TL) { 3637a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 3638577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (PointeeType.isNull()) 3639577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3641b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); 3642b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara TypeSourceInfo* NewClsTInfo = 0; 3643b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (OldClsTInfo) { 3644b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsTInfo = getDerived().TransformType(OldClsTInfo); 3645b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (!NewClsTInfo) 3646b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara return QualType(); 3647b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara } 3648b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara 3649b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara const MemberPointerType *T = TL.getTypePtr(); 3650b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara QualType OldClsType = QualType(T->getClass(), 0); 3651b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara QualType NewClsType; 3652b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (NewClsTInfo) 3653b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsType = NewClsTInfo->getType(); 3654b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara else { 3655b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsType = getDerived().TransformType(OldClsType); 3656b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (NewClsType.isNull()) 3657b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara return QualType(); 3658b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara } 36591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3660a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3661a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3662a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall PointeeType != T->getPointeeType() || 3663b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsType != OldClsType) { 3664b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, 366585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getStarLoc()); 3666a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3667a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3668a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3669577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3670a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); 3671a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSigilLoc(TL.getSigilLoc()); 3672b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewTL.setClassTInfo(NewClsTInfo); 3673a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3674a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3675577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3676577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 36771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 36781eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3679a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, 368043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ConstantArrayTypeLoc TL) { 3681f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const ConstantArrayType *T = TL.getTypePtr(); 3682a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3683577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3684577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3686a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3687a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3688a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3689a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildConstantArrayType(ElementType, 3690a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 3691a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSize(), 369285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->getIndexTypeCVRQualifiers(), 369385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3694a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3695a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3696a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3697457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman 3698457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman // We might have either a ConstantArrayType or a VariableArrayType now: 3699457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman // a ConstantArrayType is allowed to have an element type which is a 3700457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman // VariableArrayType if the type is dependent. Fortunately, all array 3701457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman // types have the same location layout. 3702457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); 3703a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3704a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 37051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3706a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Expr *Size = TL.getSizeExpr(); 3707a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Size) { 3708f6702a3927147655206ae729a84339c4fda4c651Richard Smith EnterExpressionEvaluationContext Unevaluated(SemaRef, 3709f6702a3927147655206ae729a84339c4fda4c651Richard Smith Sema::ConstantEvaluated); 3710a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); 3711ac6260187b6b2f26faa9264d170d649a501f58a9Eli Friedman Size = SemaRef.ActOnConstantExpression(Size).take(); 3712a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3713a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(Size); 3714a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3715a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3716577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 37171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3718577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 3719577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformIncompleteArrayType( 3720a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 372143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall IncompleteArrayTypeLoc TL) { 3722f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const IncompleteArrayType *T = TL.getTypePtr(); 3723a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3724577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3725577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 37261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3727a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3728a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3729a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3730a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildIncompleteArrayType(ElementType, 3731a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 373285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->getIndexTypeCVRQualifiers(), 373385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3734a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3735a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3736a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 37374a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 3738a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); 3739a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3740a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 3741a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(0); 3742577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3743a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3744577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 37451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3746577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 3747a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3748a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, 374943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall VariableArrayTypeLoc TL) { 3750f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const VariableArrayType *T = TL.getTypePtr(); 3751a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3752577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3753577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 37541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 375560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SizeResult 3756a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall = getDerived().TransformExpr(T->getSizeExpr()); 3757a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (SizeResult.isInvalid()) 3758577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 37591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Size = SizeResult.take(); 3761a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3762a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3763a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3764a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType() || 3765a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Size != T->getSizeExpr()) { 3766a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildVariableArrayType(ElementType, 3767a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 37689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Size, 3769a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getIndexTypeCVRQualifiers(), 377085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3771a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3772a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3773577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 37744a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 3775a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); 3776a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3777a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 3778a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(Size); 37791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3780a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3781577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 37821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3784a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3785a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, 378643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentSizedArrayTypeLoc TL) { 3787f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentSizedArrayType *T = TL.getTypePtr(); 3788a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3789577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3790577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 37911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3792f6702a3927147655206ae729a84339c4fda4c651Richard Smith // Array bounds are constant expressions. 3793f6702a3927147655206ae729a84339c4fda4c651Richard Smith EnterExpressionEvaluationContext Unevaluated(SemaRef, 3794f6702a3927147655206ae729a84339c4fda4c651Richard Smith Sema::ConstantEvaluated); 37951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37963b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Prefer the expression from the TypeLoc; the other may have been uniqued. 37973b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Expr *origSize = TL.getSizeExpr(); 37983b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!origSize) origSize = T->getSizeExpr(); 37993b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 38003b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExprResult sizeResult 38013b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall = getDerived().TransformExpr(origSize); 3802ac6260187b6b2f26faa9264d170d649a501f58a9Eli Friedman sizeResult = SemaRef.ActOnConstantExpression(sizeResult); 38033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (sizeResult.isInvalid()) 3804577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 38051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Expr *size = sizeResult.get(); 3807a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3808a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3809a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3810a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType() || 38113b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall size != origSize) { 3812a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildDependentSizedArrayType(ElementType, 3813a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 38143b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall size, 3815a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getIndexTypeCVRQualifiers(), 381685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3817a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3818a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3819577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 38201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3821a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // We might have any sort of array type now, but fortunately they 3822a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // all have the same location layout. 3823a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); 3824a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3825a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 38263b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall NewTL.setSizeExpr(size); 3827a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3828a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3829577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 38301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3832577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( 3833a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 383443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentSizedExtVectorTypeLoc TL) { 3835f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentSizedExtVectorType *T = TL.getTypePtr(); 3836a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3837a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: ext vector locs should be nested 3838577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3839577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3840577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 38411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3842f6702a3927147655206ae729a84339c4fda4c651Richard Smith // Vector sizes are constant expressions. 3843f6702a3927147655206ae729a84339c4fda4c651Richard Smith EnterExpressionEvaluationContext Unevaluated(SemaRef, 3844f6702a3927147655206ae729a84339c4fda4c651Richard Smith Sema::ConstantEvaluated); 3845670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor 384660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); 3847ac6260187b6b2f26faa9264d170d649a501f58a9Eli Friedman Size = SemaRef.ActOnConstantExpression(Size); 3848577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (Size.isInvalid()) 3849577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 38501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3851a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3852a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3853eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall ElementType != T->getElementType() || 3854eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall Size.get() != T->getSizeExpr()) { 3855a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, 38569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Size.take(), 3857577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor T->getAttributeLoc()); 3858a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3859a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3860a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3861a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3862a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Result might be dependent or not. 3863a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (isa<DependentSizedExtVectorType>(Result)) { 3864a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall DependentSizedExtVectorTypeLoc NewTL 3865a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall = TLB.push<DependentSizedExtVectorTypeLoc>(Result); 3866a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 3867a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } else { 3868a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); 3869a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 3870a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3871a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3872a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3873577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 38741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3876a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, 387743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall VectorTypeLoc TL) { 3878f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const VectorType *T = TL.getTypePtr(); 3879577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3880577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3881577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 3882577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3883a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3884a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3885a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 388682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), 3887e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson T->getVectorKind()); 3888a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3889a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3890a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 38914a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 3892a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); 3893a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 38941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3895a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3896577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 38971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3899a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, 390043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ExtVectorTypeLoc TL) { 3901f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const VectorType *T = TL.getTypePtr(); 3902577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3903577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3904577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 39051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3906a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3907a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3908a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3909a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildExtVectorType(ElementType, 3910a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getNumElements(), 3911a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /*FIXME*/ SourceLocation()); 3912a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3913a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3914a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 39154a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 3916a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); 3917a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 39181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3919a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3920577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3921577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 39221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 392321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallParmVarDecl * 39246a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas GregorTreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm, 3925fb44de956f27875def889482b5393475060392afJohn McCall int indexAdjustment, 3926d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor llvm::Optional<unsigned> NumExpansions, 3927d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor bool ExpectParameterPack) { 392821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); 39296a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeSourceInfo *NewDI = 0; 39304a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 39316a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { 39324a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier // If we're substituting into a pack expansion type and we know the 3933d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor // length we want to expand to, just substitute for the pattern. 39346a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeLoc OldTL = OldDI->getTypeLoc(); 39356a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL); 39364a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 39376a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeLocBuilder TLB; 39386a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeLoc NewTL = OldDI->getTypeLoc(); 39396a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TLB.reserve(NewTL.getFullDataSize()); 39404a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 39414a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier QualType Result = getDerived().TransformType(TLB, 39426a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OldExpansionTL.getPatternLoc()); 39436a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor if (Result.isNull()) 39446a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor return 0; 39454a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 39464a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Result = RebuildPackExpansionType(Result, 39474a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier OldExpansionTL.getPatternLoc().getSourceRange(), 39486a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OldExpansionTL.getEllipsisLoc(), 39496a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NumExpansions); 39506a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor if (Result.isNull()) 39516a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor return 0; 39524a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 39536a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor PackExpansionTypeLoc NewExpansionTL 39546a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = TLB.push<PackExpansionTypeLoc>(Result); 39556a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); 39566a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); 39576a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor } else 39586a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NewDI = getDerived().TransformType(OldDI); 395921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall if (!NewDI) 396021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return 0; 396121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 3962fb44de956f27875def889482b5393475060392afJohn McCall if (NewDI == OldDI && indexAdjustment == 0) 396321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return OldParm; 3964fb44de956f27875def889482b5393475060392afJohn McCall 3965fb44de956f27875def889482b5393475060392afJohn McCall ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, 3966fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getDeclContext(), 3967fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getInnerLocStart(), 3968fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getLocation(), 3969fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getIdentifier(), 3970fb44de956f27875def889482b5393475060392afJohn McCall NewDI->getType(), 3971fb44de956f27875def889482b5393475060392afJohn McCall NewDI, 3972fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getStorageClass(), 3973fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getStorageClassAsWritten(), 3974fb44de956f27875def889482b5393475060392afJohn McCall /* DefArg */ NULL); 3975fb44de956f27875def889482b5393475060392afJohn McCall newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), 3976fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getFunctionScopeIndex() + indexAdjustment); 3977fb44de956f27875def889482b5393475060392afJohn McCall return newParm; 397821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall} 397921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 398021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived> 398121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallbool TreeTransform<Derived>:: 3982a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TransformFunctionTypeParams(SourceLocation Loc, 3983a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParmVarDecl **Params, unsigned NumParams, 3984a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor const QualType *ParamTypes, 3985686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<QualType> &OutParamTypes, 3986686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<ParmVarDecl*> *PVars) { 3987fb44de956f27875def889482b5393475060392afJohn McCall int indexAdjustment = 0; 3988fb44de956f27875def889482b5393475060392afJohn McCall 3989a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor for (unsigned i = 0; i != NumParams; ++i) { 3990a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (ParmVarDecl *OldParm = Params[i]) { 3991fb44de956f27875def889482b5393475060392afJohn McCall assert(OldParm->getFunctionScopeIndex() == i); 3992fb44de956f27875def889482b5393475060392afJohn McCall 39936a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor llvm::Optional<unsigned> NumExpansions; 3994406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor ParmVarDecl *NewParm = 0; 3995603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (OldParm->isParameterPack()) { 3996603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We have a function parameter pack that may need to be expanded. 3997686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<UnexpandedParameterPack, 2> Unexpanded; 3998603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 3999603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Find the parameter packs that could be expanded. 4000c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); 4001c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL); 4002c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor TypeLoc Pattern = ExpansionTL.getPatternLoc(); 4003c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); 4004406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); 4005406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor 4006603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Determine whether we should expand the parameter packs. 4007603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor bool ShouldExpand = false; 4008d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 40096a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor llvm::Optional<unsigned> OrigNumExpansions 40106a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = ExpansionTL.getTypePtr()->getNumExpansions(); 40116a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NumExpansions = OrigNumExpansions; 4012c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), 4013c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor Pattern.getSourceRange(), 40144a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Unexpanded, 40154a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ShouldExpand, 4016d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor RetainExpansion, 4017d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) { 4018603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 4019603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 40204a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 4021603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (ShouldExpand) { 4022603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Expand the function parameter pack into multiple, separate 4023603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // parameters. 402412c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor getDerived().ExpandingFunctionParameterPack(OldParm); 4025cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 4026603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 40274a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ParmVarDecl *NewParm 40286a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = getDerived().TransformFunctionTypeParam(OldParm, 4029fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment++, 4030d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor OrigNumExpansions, 4031d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor /*ExpectParameterPack=*/false); 4032603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (!NewParm) 4033603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 40344a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 4035a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewParm->getType()); 4036a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 4037a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(NewParm); 4038603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4039d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 4040d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 4041d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor // forgetting the partially-substituted parameter pack. 4042d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (RetainExpansion) { 4043d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 40444a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ParmVarDecl *NewParm 40456a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = getDerived().TransformFunctionTypeParam(OldParm, 4046fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment++, 4047d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor OrigNumExpansions, 4048d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor /*ExpectParameterPack=*/false); 4049d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (!NewParm) 4050d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor return true; 40514a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 4052d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor OutParamTypes.push_back(NewParm->getType()); 4053d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (PVars) 4054d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor PVars->push_back(NewParm); 4055d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor } 4056d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 4057fb44de956f27875def889482b5393475060392afJohn McCall // The next parameter should have the same adjustment as the 4058fb44de956f27875def889482b5393475060392afJohn McCall // last thing we pushed, but we post-incremented indexAdjustment 4059fb44de956f27875def889482b5393475060392afJohn McCall // on every push. Also, if we push nothing, the adjustment should 4060fb44de956f27875def889482b5393475060392afJohn McCall // go down by one. 4061fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment--; 4062fb44de956f27875def889482b5393475060392afJohn McCall 4063603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We're done with the pack expansion. 4064603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor continue; 4065603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 40664a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 40674a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier // We'll substitute the parameter now without expanding the pack 4068603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // expansion. 4069406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 4070406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewParm = getDerived().TransformFunctionTypeParam(OldParm, 4071fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment, 4072d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor NumExpansions, 4073d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor /*ExpectParameterPack=*/true); 4074406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor } else { 4075406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewParm = getDerived().TransformFunctionTypeParam(OldParm, 4076fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment, 4077d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor llvm::Optional<unsigned>(), 4078d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor /*ExpectParameterPack=*/false); 4079603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4080406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor 408121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall if (!NewParm) 408221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return true; 40834a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 4084a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewParm->getType()); 4085a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 4086a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(NewParm); 4087603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor continue; 4088603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4089a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4090a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Deal with the possibility that we don't have a parameter 4091a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // declaration for this parameter. 4092a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor QualType OldType = ParamTypes[i]; 4093603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor bool IsPackExpansion = false; 4094cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions; 4095406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor QualType NewType; 40964a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (const PackExpansionType *Expansion 4097603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor = dyn_cast<PackExpansionType>(OldType)) { 4098603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We have a function parameter pack that may need to be expanded. 4099603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor QualType Pattern = Expansion->getPattern(); 4100686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<UnexpandedParameterPack, 2> Unexpanded; 4101603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 41024a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 4103603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Determine whether we should expand the parameter packs. 4104603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor bool ShouldExpand = false; 4105d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 4106a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), 41074a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Unexpanded, 41084a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ShouldExpand, 4109d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor RetainExpansion, 4110d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) { 411121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return true; 4112603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 41134a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 4114603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (ShouldExpand) { 41154a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier // Expand the function parameter pack into multiple, separate 4116603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // parameters. 4117cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 4118603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 4119603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor QualType NewType = getDerived().TransformType(Pattern); 4120603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (NewType.isNull()) 4121603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 4122603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4123a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewType); 4124a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 4125a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(0); 4126603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 41274a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 4128603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We're done with the pack expansion. 4129603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor continue; 4130603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 41314a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 41323cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 41333cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // forgetting the partially-substituted parameter pack. 41343cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (RetainExpansion) { 41353cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 41363cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor QualType NewType = getDerived().TransformType(Pattern); 41373cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (NewType.isNull()) 41383cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor return true; 41394a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 41403cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor OutParamTypes.push_back(NewType); 41413cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (PVars) 41423cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor PVars->push_back(0); 41433cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor } 4144d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 41454a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier // We'll substitute the parameter now without expanding the pack 4146603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // expansion. 4147603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor OldType = Expansion->getPattern(); 4148603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor IsPackExpansion = true; 4149406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 4150406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewType = getDerived().TransformType(OldType); 4151406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor } else { 4152406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewType = getDerived().TransformType(OldType); 4153a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 41544a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 4155603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (NewType.isNull()) 4156603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 41571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4158603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (IsPackExpansion) 4159cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NewType = getSema().Context.getPackExpansionType(NewType, 4160cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions); 41614a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 4162a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewType); 4163a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 4164a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(0); 4165577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 41661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4167fb44de956f27875def889482b5393475060392afJohn McCall#ifndef NDEBUG 4168fb44de956f27875def889482b5393475060392afJohn McCall if (PVars) { 4169fb44de956f27875def889482b5393475060392afJohn McCall for (unsigned i = 0, e = PVars->size(); i != e; ++i) 4170fb44de956f27875def889482b5393475060392afJohn McCall if (ParmVarDecl *parm = (*PVars)[i]) 4171fb44de956f27875def889482b5393475060392afJohn McCall assert(parm->getFunctionScopeIndex() == i); 4172603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4173fb44de956f27875def889482b5393475060392afJohn McCall#endif 4174fb44de956f27875def889482b5393475060392afJohn McCall 4175fb44de956f27875def889482b5393475060392afJohn McCall return false; 4176fb44de956f27875def889482b5393475060392afJohn McCall} 417721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 417821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived> 417921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallQualType 418021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallTreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, 418143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FunctionProtoTypeLoc TL) { 4182cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0); 4183cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor} 4184cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor 4185cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregortemplate<typename Derived> 4186cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas GregorQualType 4187cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas GregorTreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, 4188cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor FunctionProtoTypeLoc TL, 4189cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor CXXRecordDecl *ThisContext, 4190cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor unsigned ThisTypeQuals) { 41917e010a04fef171049291d8cb3047f118566da090Douglas Gregor // Transform the parameters and return type. 41927e010a04fef171049291d8cb3047f118566da090Douglas Gregor // 4193e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith // We are required to instantiate the params and return type in source order. 4194dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // When the function has a trailing return type, we instantiate the 4195dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // parameters before the return type, since the return type can then refer 4196dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // to the parameters themselves (via decltype, sizeof, etc.). 4197dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // 4198686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<QualType, 4> ParamTypes; 4199686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<ParmVarDecl*, 4> ParamDecls; 4200f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const FunctionProtoType *T = TL.getTypePtr(); 42017e010a04fef171049291d8cb3047f118566da090Douglas Gregor 4202dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor QualType ResultType; 4203dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 42049fbf327cfdd27ddb5d845042c95f2299ac95b143Richard Smith if (T->hasTrailingReturn()) { 42054a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), 4206a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getParmArray(), 4207a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getNumArgs(), 42084a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier TL.getTypePtr()->arg_type_begin(), 4209a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParamTypes, &ParamDecls)) 4210dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 4211dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 4212cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor { 4213cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor // C++11 [expr.prim.general]p3: 42144a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier // If a declaration declares a member function or member function 42154a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier // template of a class X, the expression this is a prvalue of type 4216cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq 42174a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier // and the end of the function-definition, member-declarator, or 4218cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor // declarator. 4219cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals); 42204a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 4221cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 4222cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor if (ResultType.isNull()) 4223cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor return QualType(); 4224cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor } 4225dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor } 4226dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor else { 4227dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 4228dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (ResultType.isNull()) 4229dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 4230dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 42314a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), 4232a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getParmArray(), 4233a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getNumArgs(), 42344a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier TL.getTypePtr()->arg_type_begin(), 4235a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParamTypes, &ParamDecls)) 4236dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 4237dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor } 4238dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 4239e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith // FIXME: Need to transform the exception-specification too. 4240e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith 4241a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4242a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4243a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ResultType != T->getResultType() || 4244bd5f9f708aa31920d3bd73aa10fcb5de424c657aDouglas Gregor T->getNumArgs() != ParamTypes.size() || 4245a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { 4246a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildFunctionProtoType(ResultType, 4247a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ParamTypes.data(), 4248a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ParamTypes.size(), 4249a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->isVariadic(), 4250eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith T->hasTrailingReturn(), 4251fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman T->getTypeQuals(), 4252c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor T->getRefQualifier(), 4253fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman T->getExtInfo()); 4254a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4255a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4256a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 42571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4258a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); 4259796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); 4260796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); 4261a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) 4262a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setArg(i, ParamDecls[i]); 4263a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4264a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4265577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 42661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4267577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4268577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformFunctionNoProtoType( 4269a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 427043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FunctionNoProtoTypeLoc TL) { 4271f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const FunctionNoProtoType *T = TL.getTypePtr(); 4272a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 4273a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (ResultType.isNull()) 4274a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4275a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4276a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4277a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4278a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ResultType != T->getResultType()) 4279a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildFunctionNoProtoType(ResultType); 4280a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4281a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); 4282796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); 4283796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); 4284a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4285a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4286577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 42871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4288ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> QualType 4289ed97649e9574b9d854fa4d6109c9333ae0993554John McCallTreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, 429043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall UnresolvedUsingTypeLoc TL) { 4291f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const UnresolvedUsingType *T = TL.getTypePtr(); 42927c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); 4293ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (!D) 4294ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return QualType(); 4295ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4296ed97649e9574b9d854fa4d6109c9333ae0993554John McCall QualType Result = TL.getType(); 4297ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (getDerived().AlwaysRebuild() || D != T->getDecl()) { 4298ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Result = getDerived().RebuildUnresolvedUsingType(D); 4299ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (Result.isNull()) 4300ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return QualType(); 4301ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 4302ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4303ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // We might get an arbitrary type spec type back. We should at 4304ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // least always get a type spec type, though. 4305ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); 4306ed97649e9574b9d854fa4d6109c9333ae0993554John McCall NewTL.setNameLoc(TL.getNameLoc()); 4307ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4308ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return Result; 4309ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 4310ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4311577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4312a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, 431343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypedefTypeLoc TL) { 4314f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const TypedefType *T = TL.getTypePtr(); 4315162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TypedefNameDecl *Typedef 4316162e1c1b487352434552147967c3dd296ebee2f7Richard Smith = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), 4317162e1c1b487352434552147967c3dd296ebee2f7Richard Smith T->getDecl())); 4318577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Typedef) 4319577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 43201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4321a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4322a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4323a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Typedef != T->getDecl()) { 4324a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildTypedefType(Typedef); 4325a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4326a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4327a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4328a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4329a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); 4330a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 43311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4332a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4333577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 43341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4335577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4336a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, 433743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeOfExprTypeLoc TL) { 4338670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // typeof expressions are not potentially evaluated contexts 4339f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 43401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 434160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); 4342577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (E.isInvalid()) 4343577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 4344577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 434572b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); 434672b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman if (E.isInvalid()) 434772b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman return QualType(); 434872b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman 4349a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4350a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4351cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall E.get() != TL.getUnderlyingExpr()) { 43522a984cad5ac3fdceeff2bd99daa7b90979313475John McCall Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); 4353a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4354a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4355577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 4356a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall else E.take(); 43571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4358a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); 4359cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setTypeofLoc(TL.getTypeofLoc()); 4360cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setLParenLoc(TL.getLParenLoc()); 4361cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setRParenLoc(TL.getRParenLoc()); 4362a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4363a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4364577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 43651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 43661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4367a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, 436843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeOfTypeLoc TL) { 4369cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); 4370cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); 4371cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall if (!New_Under_TI) 4372577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 43731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4374a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4375cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { 4376cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); 4377a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4378a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4379a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 43801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4381a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); 4382cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setTypeofLoc(TL.getTypeofLoc()); 4383cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setLParenLoc(TL.getLParenLoc()); 4384cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setRParenLoc(TL.getRParenLoc()); 4385cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setUnderlyingTInfo(New_Under_TI); 4386a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4387a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4388577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 43891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 43901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4391a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, 439243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DecltypeTypeLoc TL) { 4393f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DecltypeType *T = TL.getTypePtr(); 4394a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4395670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // decltype expressions are not potentially evaluated contexts 439676f3f69db1416425070177243e9f390122c553e0Richard Smith EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0, 439776f3f69db1416425070177243e9f390122c553e0Richard Smith /*IsDecltype=*/ true); 43981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 439960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); 4400577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (E.isInvalid()) 4401577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 44021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 440376f3f69db1416425070177243e9f390122c553e0Richard Smith E = getSema().ActOnDecltypeExpression(E.take()); 440476f3f69db1416425070177243e9f390122c553e0Richard Smith if (E.isInvalid()) 440576f3f69db1416425070177243e9f390122c553e0Richard Smith return QualType(); 440676f3f69db1416425070177243e9f390122c553e0Richard Smith 4407a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4408a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4409a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall E.get() != T->getUnderlyingExpr()) { 44102a984cad5ac3fdceeff2bd99daa7b90979313475John McCall Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); 4411a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4412a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4413577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 4414a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall else E.take(); 4415a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4416a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); 4417a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 44181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4419a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4420577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 4421577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 4422577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4423ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType TreeTransform<Derived>::TransformUnaryTransformType( 4424ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt TypeLocBuilder &TLB, 4425ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformTypeLoc TL) { 4426ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType Result = TL.getType(); 4427ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt if (Result->isDependentType()) { 4428ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt const UnaryTransformType *T = TL.getTypePtr(); 4429ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType NewBase = 4430ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); 4431ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Result = getDerived().RebuildUnaryTransformType(NewBase, 4432ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt T->getUTTKind(), 4433ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt TL.getKWLoc()); 4434ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt if (Result.isNull()) 4435ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return QualType(); 4436ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt } 4437ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 4438ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); 4439ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt NewTL.setKWLoc(TL.getKWLoc()); 4440ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt NewTL.setParensRange(TL.getParensRange()); 4441ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); 4442ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return Result; 4443ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt} 4444ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 4445ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunttemplate<typename Derived> 444634b41d939a1328f484511c6002ba2456db879a29Richard SmithQualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, 444734b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoTypeLoc TL) { 444834b41d939a1328f484511c6002ba2456db879a29Richard Smith const AutoType *T = TL.getTypePtr(); 444934b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType OldDeduced = T->getDeducedType(); 445034b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType NewDeduced; 445134b41d939a1328f484511c6002ba2456db879a29Richard Smith if (!OldDeduced.isNull()) { 445234b41d939a1328f484511c6002ba2456db879a29Richard Smith NewDeduced = getDerived().TransformType(OldDeduced); 445334b41d939a1328f484511c6002ba2456db879a29Richard Smith if (NewDeduced.isNull()) 445434b41d939a1328f484511c6002ba2456db879a29Richard Smith return QualType(); 445534b41d939a1328f484511c6002ba2456db879a29Richard Smith } 445634b41d939a1328f484511c6002ba2456db879a29Richard Smith 445734b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType Result = TL.getType(); 445834b41d939a1328f484511c6002ba2456db879a29Richard Smith if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) { 445934b41d939a1328f484511c6002ba2456db879a29Richard Smith Result = getDerived().RebuildAutoType(NewDeduced); 446034b41d939a1328f484511c6002ba2456db879a29Richard Smith if (Result.isNull()) 446134b41d939a1328f484511c6002ba2456db879a29Richard Smith return QualType(); 446234b41d939a1328f484511c6002ba2456db879a29Richard Smith } 446334b41d939a1328f484511c6002ba2456db879a29Richard Smith 446434b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); 446534b41d939a1328f484511c6002ba2456db879a29Richard Smith NewTL.setNameLoc(TL.getNameLoc()); 446634b41d939a1328f484511c6002ba2456db879a29Richard Smith 446734b41d939a1328f484511c6002ba2456db879a29Richard Smith return Result; 446834b41d939a1328f484511c6002ba2456db879a29Richard Smith} 446934b41d939a1328f484511c6002ba2456db879a29Richard Smith 447034b41d939a1328f484511c6002ba2456db879a29Richard Smithtemplate<typename Derived> 4471a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, 447243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall RecordTypeLoc TL) { 4473f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const RecordType *T = TL.getTypePtr(); 4474577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor RecordDecl *Record 44757c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), 44767c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor T->getDecl())); 4477577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Record) 4478577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 44791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4480a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4481a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4482a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Record != T->getDecl()) { 4483a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildRecordType(Record); 4484a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4485a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4486a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 44871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4488a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); 4489a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 4490a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4491a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4492577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 44931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 44941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4495a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, 449643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall EnumTypeLoc TL) { 4497f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const EnumType *T = TL.getTypePtr(); 4498577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor EnumDecl *Enum 44997c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), 45007c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor T->getDecl())); 4501577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Enum) 4502577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 45031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4504a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4505a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4506a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Enum != T->getDecl()) { 4507a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildEnumType(Enum); 4508a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4509a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4510a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4511a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4512a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); 4513a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 45141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4515a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4516577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 45177da2431c23ef1ee8acb114e39692246e1801afc2John McCall 45183cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCalltemplate<typename Derived> 45193cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallQualType TreeTransform<Derived>::TransformInjectedClassNameType( 45203cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TypeLocBuilder &TLB, 452143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall InjectedClassNameTypeLoc TL) { 45223cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall Decl *D = getDerived().TransformDecl(TL.getNameLoc(), 45233cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TL.getTypePtr()->getDecl()); 45243cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall if (!D) return QualType(); 45253cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 45263cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); 45273cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); 45283cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return T; 45293cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 45303cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 4531577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4532577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateTypeParmType( 4533a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 453443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateTypeParmTypeLoc TL) { 4535a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return TransformTypeSpecType(TLB, TL); 4536577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 4537577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 45381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 453949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( 4540a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 454143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall SubstTemplateTypeParmTypeLoc TL) { 45420b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor const SubstTemplateTypeParmType *T = TL.getTypePtr(); 45434a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 45440b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // Substitute into the replacement type, which itself might involve something 45450b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // that needs to be transformed. This only tends to occur with default 45460b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // template arguments of template template parameters. 45470b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); 45480b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor QualType Replacement = getDerived().TransformType(T->getReplacementType()); 45490b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor if (Replacement.isNull()) 45500b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor return QualType(); 45514a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 45520b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // Always canonicalize the replacement type. 45530b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor Replacement = SemaRef.Context.getCanonicalType(Replacement); 45540b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor QualType Result 45554a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), 45560b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor Replacement); 45574a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 45580b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // Propagate type-source information. 45590b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor SubstTemplateTypeParmTypeLoc NewTL 45600b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); 45610b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor NewTL.setNameLoc(TL.getNameLoc()); 45620b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor return Result; 45630b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor 456449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall} 456549a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 456649a832bd499d6f61c23655f1fac99f0dd229756eJohn McCalltemplate<typename Derived> 4567c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( 4568c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor TypeLocBuilder &TLB, 4569c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackTypeLoc TL) { 4570c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return TransformTypeSpecType(TLB, TL); 4571c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 4572c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 4573c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregortemplate<typename Derived> 4574833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallQualType TreeTransform<Derived>::TransformTemplateSpecializationType( 457543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeLocBuilder &TLB, 457643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateSpecializationTypeLoc TL) { 457743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall const TemplateSpecializationType *T = TL.getTypePtr(); 4578828bff2079b6a91ecd7ed5b842c59527d7682789John McCall 45791d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor // The nested-name-specifier never matters in a TemplateSpecializationType, 45801d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor // because we can't have a dependent nested-name-specifier anyway. 45811d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor CXXScopeSpec SS; 458243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template 45831d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor = getDerived().TransformTemplateName(SS, T->getTemplateName(), 45841d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor TL.getTemplateNameLoc()); 458543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (Template.isNull()) 458643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return QualType(); 4587833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 458843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); 4589dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor} 459043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 4591b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmantemplate<typename Derived> 4592b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli FriedmanQualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, 4593b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicTypeLoc TL) { 4594b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); 4595b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (ValueType.isNull()) 4596b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return QualType(); 4597b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4598b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType Result = TL.getType(); 4599b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (getDerived().AlwaysRebuild() || 4600b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman ValueType != TL.getValueLoc().getType()) { 4601b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); 4602b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (Result.isNull()) 4603b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return QualType(); 4604b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 4605b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4606b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); 4607b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman NewTL.setKWLoc(TL.getKWLoc()); 4608b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman NewTL.setLParenLoc(TL.getLParenLoc()); 4609b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman NewTL.setRParenLoc(TL.getRParenLoc()); 4610b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4611b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return Result; 4612b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman} 4613b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 46147ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregornamespace { 46154a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier /// \brief Simple iterator that traverses the template arguments in a 46167ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// container that provides a \c getArgLoc() member function. 46177ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// 46187ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// This iterator is intended to be used with the iterator form of 46197ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \c TreeTransform<Derived>::TransformTemplateArguments(). 46207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor template<typename ArgLocContainer> 46217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class TemplateArgumentLocContainerIterator { 46227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgLocContainer *Container; 46237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor unsigned Index; 46244a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 46257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 46267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc value_type; 46277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc reference; 46287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef int difference_type; 46297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef std::input_iterator_tag iterator_category; 46304a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 46317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class pointer { 46327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Arg; 46334a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 46347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 46357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } 46364a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 46377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLoc *operator->() const { 46387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return &Arg; 46397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 46407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 46414a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 46424a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 46437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator() {} 46444a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 46457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator(ArgLocContainer &Container, 46467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor unsigned Index) 46477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor : Container(&Container), Index(Index) { } 46484a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 46497ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator &operator++() { 46507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++Index; 46517ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return *this; 46527ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 46534a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 46547ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator operator++(int) { 46557ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator Old(*this); 46567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++(*this); 46577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Old; 46587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 46594a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 46607ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc operator*() const { 46617ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Container->getArgLoc(Index); 46627ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 46634a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 46647ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor pointer operator->() const { 46657ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return pointer(Container->getArgLoc(Index)); 46667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 46674a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 46687ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator==(const TemplateArgumentLocContainerIterator &X, 4669f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor const TemplateArgumentLocContainerIterator &Y) { 46707ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Container == Y.Container && X.Index == Y.Index; 46717ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 46724a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 46737ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator!=(const TemplateArgumentLocContainerIterator &X, 4674f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor const TemplateArgumentLocContainerIterator &Y) { 46757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return !(X == Y); 46767ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 46777ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 46787ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor} 46794a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 46804a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 468143fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate <typename Derived> 4682577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateSpecializationType( 4683833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TypeLocBuilder &TLB, 4684833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateSpecializationTypeLoc TL, 468543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template) { 4686d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo NewTemplateArgs; 4687d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 4688d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 46897ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> 46907ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgIterator; 46914a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 46927ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgIterator(TL, TL.getNumArgs()), 46937ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor NewTemplateArgs)) 46947f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return QualType(); 46951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4696833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: maybe don't rebuild if all the template arguments are the same. 4697833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 4698833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall QualType Result = 4699833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall getDerived().RebuildTemplateSpecializationType(Template, 4700833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TL.getTemplateNameLoc(), 4701d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs); 47021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4703833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!Result.isNull()) { 47043e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // Specializations of template template parameters are represented as 47053e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // TemplateSpecializationTypes, and substitution of type alias templates 47063e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // within a dependent context can transform them into 47073e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // DependentTemplateSpecializationTypes. 47083e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (isa<DependentTemplateSpecializationType>(Result)) { 47093e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith DependentTemplateSpecializationTypeLoc NewTL 47103e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 471155d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara NewTL.setElaboratedKeywordLoc(SourceLocation()); 47123e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setQualifierLoc(NestedNameSpecifierLoc()); 471366581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 471455d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 47153e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setLAngleLoc(TL.getLAngleLoc()); 47163e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setRAngleLoc(TL.getRAngleLoc()); 47173e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 47183e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 47193e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return Result; 47203e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 47213e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 4722833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateSpecializationTypeLoc NewTL 4723833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall = TLB.push<TemplateSpecializationTypeLoc>(Result); 472455d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 4725833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 4726833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setLAngleLoc(TL.getLAngleLoc()); 4727833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setRAngleLoc(TL.getRAngleLoc()); 4728833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 4729833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 4730833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 47311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4732833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return Result; 4733577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 47341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4735a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregortemplate <typename Derived> 4736a88f09f34e86125ee4e6949a757aaed314012664Douglas GregorQualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( 4737a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TypeLocBuilder &TLB, 4738a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc TL, 4739087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor TemplateName Template, 4740087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor CXXScopeSpec &SS) { 4741a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateArgumentListInfo NewTemplateArgs; 4742a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 4743a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 4744a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor typedef TemplateArgumentLocContainerIterator< 4745a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc> ArgIterator; 47464a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 4747a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor ArgIterator(TL, TL.getNumArgs()), 4748a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs)) 4749a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return QualType(); 47504a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 4751a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor // FIXME: maybe don't rebuild if all the template arguments are the same. 47524a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 4753a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { 4754a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor QualType Result 4755a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = getSema().Context.getDependentTemplateSpecializationType( 4756a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TL.getTypePtr()->getKeyword(), 4757a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DTN->getQualifier(), 4758a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DTN->getIdentifier(), 4759a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs); 47604a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 4761a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc NewTL 4762a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 476355d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 476494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); 476566581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 476655d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 4767a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setLAngleLoc(TL.getLAngleLoc()); 4768a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setRAngleLoc(TL.getRAngleLoc()); 4769a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 4770a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 4771a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return Result; 4772a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor } 47734a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 47744a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier QualType Result 4775a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = getDerived().RebuildTemplateSpecializationType(Template, 477655d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara TL.getTemplateNameLoc(), 4777a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs); 47784a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 4779a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (!Result.isNull()) { 4780a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor /// FIXME: Wrap this in an elaborated-type-specifier? 4781a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateSpecializationTypeLoc NewTL 4782a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = TLB.push<TemplateSpecializationTypeLoc>(Result); 478366581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 478455d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 4785a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setLAngleLoc(TL.getLAngleLoc()); 4786a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setRAngleLoc(TL.getRAngleLoc()); 4787a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 4788a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 4789a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor } 47904a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 4791a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return Result; 4792a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor} 4793a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 47941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4795a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 4796465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, 479743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ElaboratedTypeLoc TL) { 4798f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const ElaboratedType *T = TL.getTypePtr(); 4799465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 48009e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 4801465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara // NOTE: the qualifier in an ElaboratedType is optional. 48029e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor if (TL.getQualifierLoc()) { 48034a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier QualifierLoc 48049e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 48059e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor if (!QualifierLoc) 4806465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return QualType(); 4807465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 48081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 480943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); 481043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (NamedT.isNull()) 481143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return QualType(); 4812a63db84b164d3f1c987a3ea6251e3092db4f317bDaniel Dunbar 48133e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // C++0x [dcl.type.elab]p2: 48143e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // If the identifier resolves to a typedef-name or the simple-template-id 48153e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // resolves to an alias template specialization, the 48163e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // elaborated-type-specifier is ill-formed. 48171804174e1591bf59118f317775b48edd0382c3f0Richard Smith if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { 48181804174e1591bf59118f317775b48edd0382c3f0Richard Smith if (const TemplateSpecializationType *TST = 48191804174e1591bf59118f317775b48edd0382c3f0Richard Smith NamedT->getAs<TemplateSpecializationType>()) { 48201804174e1591bf59118f317775b48edd0382c3f0Richard Smith TemplateName Template = TST->getTemplateName(); 48211804174e1591bf59118f317775b48edd0382c3f0Richard Smith if (TypeAliasTemplateDecl *TAT = 48221804174e1591bf59118f317775b48edd0382c3f0Richard Smith dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) { 48231804174e1591bf59118f317775b48edd0382c3f0Richard Smith SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), 48241804174e1591bf59118f317775b48edd0382c3f0Richard Smith diag::err_tag_reference_non_tag) << 4; 48251804174e1591bf59118f317775b48edd0382c3f0Richard Smith SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); 48261804174e1591bf59118f317775b48edd0382c3f0Richard Smith } 48273e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 48283e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 48293e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 4830a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4831a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 48329e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc != TL.getQualifierLoc() || 4833e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NamedT != T->getNamedType()) { 483438a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), 48354a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier T->getKeyword(), 48369e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc, NamedT); 4837a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4838a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4839a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4840577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 4841465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 484238a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 48439e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 4844a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4845577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 48461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 48471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 48489d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallQualType TreeTransform<Derived>::TransformAttributedType( 48499d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall TypeLocBuilder &TLB, 48509d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeLoc TL) { 48519d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall const AttributedType *oldType = TL.getTypePtr(); 48529d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); 48539d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (modifiedType.isNull()) 48549d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return QualType(); 48559d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 48569d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType result = TL.getType(); 48579d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 48589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // FIXME: dependent operand expressions? 48599d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (getDerived().AlwaysRebuild() || 48609d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall modifiedType != oldType->getModifiedType()) { 48619d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // TODO: this is really lame; we should really be rebuilding the 48629d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // equivalent type from first principles. 48639d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType equivalentType 48649d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall = getDerived().TransformType(oldType->getEquivalentType()); 48659d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (equivalentType.isNull()) 48669d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return QualType(); 48679d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), 48689d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall modifiedType, 48699d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall equivalentType); 48709d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 48719d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 48729d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); 48739d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrNameLoc(TL.getAttrNameLoc()); 48749d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (TL.hasAttrOperand()) 48759d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); 48769d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (TL.hasAttrExprOperand()) 48779d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrExprOperand(TL.getAttrExprOperand()); 48789d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall else if (TL.hasAttrEnumOperand()) 48799d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); 48809d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 48819d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return result; 48829d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall} 48839d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 48849d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCalltemplate<typename Derived> 4885075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType 4886075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraTreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, 4887075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenTypeLoc TL) { 4888075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); 4889075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (Inner.isNull()) 4890075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(); 4891075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 4892075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Result = TL.getType(); 4893075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (getDerived().AlwaysRebuild() || 4894075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Inner != TL.getInnerLoc().getType()) { 4895075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Result = getDerived().RebuildParenType(Inner); 4896075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (Result.isNull()) 4897075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(); 4898075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 4899075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 4900075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); 4901075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara NewTL.setLParenLoc(TL.getLParenLoc()); 4902075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara NewTL.setRParenLoc(TL.getRParenLoc()); 4903075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return Result; 4904075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 4905075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 4906075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaratemplate<typename Derived> 49074714c12a1ab759156b78be8f109ea4c12213af57Douglas GregorQualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, 490843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentNameTypeLoc TL) { 4909f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentNameType *T = TL.getTypePtr(); 4910833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 49112494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor NestedNameSpecifierLoc QualifierLoc 49122494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 49132494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor if (!QualifierLoc) 4914577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 49151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 491633500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Result 49172494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor = getDerived().RebuildDependentNameType(T->getKeyword(), 491838a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara TL.getElaboratedKeywordLoc(), 49192494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor QualifierLoc, 49202494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor T->getIdentifier(), 492133500955d731c73717af52088b7fc0e7a85681e7John McCall TL.getNameLoc()); 4922a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4923a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4924a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4925e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { 4926e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara QualType NamedT = ElabT->getNamedType(); 492733500955d731c73717af52088b7fc0e7a85681e7John McCall TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); 492833500955d731c73717af52088b7fc0e7a85681e7John McCall 4929e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 493038a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 49319e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 493233500955d731c73717af52088b7fc0e7a85681e7John McCall } else { 4933e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); 493438a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 49352494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 4936e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setNameLoc(TL.getNameLoc()); 4937e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 4938a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4939577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 49401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4941577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 494233500955d731c73717af52088b7fc0e7a85681e7John McCallQualType TreeTransform<Derived>:: 494333500955d731c73717af52088b7fc0e7a85681e7John McCall TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 494443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentTemplateSpecializationTypeLoc TL) { 494594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 494694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (TL.getQualifierLoc()) { 494794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualifierLoc 494894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 494994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (!QualifierLoc) 4950a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return QualType(); 4951a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor } 49524a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 495343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived() 495494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); 495543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall} 495643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 495743fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived> 495843fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>:: 495994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas GregorTransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 496094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor DependentTemplateSpecializationTypeLoc TL, 496194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NestedNameSpecifierLoc QualifierLoc) { 496294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor const DependentTemplateSpecializationType *T = TL.getTypePtr(); 49634a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 496494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor TemplateArgumentListInfo NewTemplateArgs; 496594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 496694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 49674a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 496894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor typedef TemplateArgumentLocContainerIterator< 496994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor DependentTemplateSpecializationTypeLoc> ArgIterator; 497094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 497194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor ArgIterator(TL, TL.getNumArgs()), 497294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs)) 497394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return QualType(); 49744a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 497594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualType Result 497694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), 497794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualifierLoc, 497894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor T->getIdentifier(), 497955d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara TL.getTemplateNameLoc(), 498094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs); 498194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (Result.isNull()) 498294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return QualType(); 49834a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 498494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { 498594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualType NamedT = ElabT->getNamedType(); 49864a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 498794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Copy information relevant to the template specialization. 498894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor TemplateSpecializationTypeLoc NamedTL 49890a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor = TLB.push<TemplateSpecializationTypeLoc>(NamedT); 499066581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 499155d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 499294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NamedTL.setLAngleLoc(TL.getLAngleLoc()); 499394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NamedTL.setRAngleLoc(TL.getRAngleLoc()); 4994944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 49950a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 49964a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 499794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Copy information relevant to the elaborated type. 499894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 499938a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 500094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 50010a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor } else if (isa<DependentTemplateSpecializationType>(Result)) { 50020a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor DependentTemplateSpecializationTypeLoc SpecTL 50030a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 500455d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 50050a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setQualifierLoc(QualifierLoc); 500666581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 500755d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 50080a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setLAngleLoc(TL.getLAngleLoc()); 50090a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setRAngleLoc(TL.getRAngleLoc()); 5010944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 50110a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 501294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor } else { 50130a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor TemplateSpecializationTypeLoc SpecTL 50140a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor = TLB.push<TemplateSpecializationTypeLoc>(Result); 501566581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 501655d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 50170a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setLAngleLoc(TL.getLAngleLoc()); 50180a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setRAngleLoc(TL.getRAngleLoc()); 5019944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 50200a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 502194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor } 502294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return Result; 502394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor} 502494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 502594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregortemplate<typename Derived> 50267536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas GregorQualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, 50277536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor PackExpansionTypeLoc TL) { 50284a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier QualType Pattern 50294a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier = getDerived().TransformType(TLB, TL.getPatternLoc()); 50302fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor if (Pattern.isNull()) 50312fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor return QualType(); 50324a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 50334a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier QualType Result = TL.getType(); 50342fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor if (getDerived().AlwaysRebuild() || 50352fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor Pattern != TL.getPatternLoc().getType()) { 50364a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Result = getDerived().RebuildPackExpansionType(Pattern, 50372fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor TL.getPatternLoc().getSourceRange(), 5038cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor TL.getEllipsisLoc(), 5039cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor TL.getTypePtr()->getNumExpansions()); 50402fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor if (Result.isNull()) 50412fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor return QualType(); 50422fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor } 50434a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 50442fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); 50452fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor NewT.setEllipsisLoc(TL.getEllipsisLoc()); 50462fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor return Result; 50477536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor} 50487536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 50497536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregortemplate<typename Derived> 5050a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 5051a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, 505243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCInterfaceTypeLoc TL) { 5053ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor // ObjCInterfaceType is never dependent. 5054c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 5055c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return TL.getType(); 5056c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 5057c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 5058c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCalltemplate<typename Derived> 5059c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallQualType 5060c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallTreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, 506143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCObjectTypeLoc TL) { 5062c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // ObjCObjectType is never dependent. 5063c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 5064ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor return TL.getType(); 5065577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 50661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 50671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 5068a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 5069a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, 507043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCObjectPointerTypeLoc TL) { 5071ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor // ObjCObjectPointerType is never dependent. 5072c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 5073ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor return TL.getType(); 507424fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis} 507524fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 5076577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 507743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor// Statement transformation 507843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===// 507943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 508060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 50811eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformNullStmt(NullStmt *S) { 50823fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 508343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 508443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 508543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 508660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 508743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { 508843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().TransformCompoundStmt(S, false); 508943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 509043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 509143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 509260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 50931eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, 509443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool IsStmtExpr) { 5095625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko Sema::CompoundScopeRAII CompoundScope(getSema()); 5096625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko 50977114cbab7eb6e8b714eb22f014327daf2c741c08John McCall bool SubStmtInvalid = false; 509843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool SubStmtChanged = false; 50994e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer SmallVector<Stmt*, 8> Statements; 510043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); 510143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor B != BEnd; ++B) { 510260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Result = getDerived().TransformStmt(*B); 51037114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (Result.isInvalid()) { 51047114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // Immediately fail if this was a DeclStmt, since it's very 51057114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // likely that this will cause problems for future statements. 51067114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (isa<DeclStmt>(*B)) 51077114cbab7eb6e8b714eb22f014327daf2c741c08John McCall return StmtError(); 51087114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 51097114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // Otherwise, just keep processing substatements and fail later. 51107114cbab7eb6e8b714eb22f014327daf2c741c08John McCall SubStmtInvalid = true; 51117114cbab7eb6e8b714eb22f014327daf2c741c08John McCall continue; 51127114cbab7eb6e8b714eb22f014327daf2c741c08John McCall } 51131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 511443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SubStmtChanged = SubStmtChanged || Result.get() != *B; 511543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Statements.push_back(Result.takeAs<Stmt>()); 511643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 51171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 51187114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (SubStmtInvalid) 51197114cbab7eb6e8b714eb22f014327daf2c741c08John McCall return StmtError(); 51207114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 512143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 512243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !SubStmtChanged) 51233fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 512443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 512543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildCompoundStmt(S->getLBracLoc(), 51263fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer Statements, 512743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getRBracLoc(), 512843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor IsStmtExpr); 512943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 51301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 513143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 513260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 51331eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { 513460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS, RHS; 5135264c1f8ec895952466eab59b84b8b06801e721faEli Friedman { 51366b3014b07c40a6ed8b0c8ed63950df02eeb82c28Eli Friedman EnterExpressionEvaluationContext Unevaluated(SemaRef, 51376b3014b07c40a6ed8b0c8ed63950df02eeb82c28Eli Friedman Sema::ConstantEvaluated); 51381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5139264c1f8ec895952466eab59b84b8b06801e721faEli Friedman // Transform the left-hand case value. 5140264c1f8ec895952466eab59b84b8b06801e721faEli Friedman LHS = getDerived().TransformExpr(S->getLHS()); 5141ac6260187b6b2f26faa9264d170d649a501f58a9Eli Friedman LHS = SemaRef.ActOnConstantExpression(LHS); 5142264c1f8ec895952466eab59b84b8b06801e721faEli Friedman if (LHS.isInvalid()) 5143f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5145264c1f8ec895952466eab59b84b8b06801e721faEli Friedman // Transform the right-hand case value (for the GNU case-range extension). 5146264c1f8ec895952466eab59b84b8b06801e721faEli Friedman RHS = getDerived().TransformExpr(S->getRHS()); 5147ac6260187b6b2f26faa9264d170d649a501f58a9Eli Friedman RHS = SemaRef.ActOnConstantExpression(RHS); 5148264c1f8ec895952466eab59b84b8b06801e721faEli Friedman if (RHS.isInvalid()) 5149f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5150264c1f8ec895952466eab59b84b8b06801e721faEli Friedman } 51511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 515243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Build the case statement. 515343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Case statements are always rebuilt so that they will attached to their 515443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transformed switch statement. 515560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), 51569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), 515743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getEllipsisLoc(), 51589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get(), 515943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getColonLoc()); 516043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Case.isInvalid()) 5161f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 516343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the statement following the case 516460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 516543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 5166f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 516843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Attach the body to the case statement 51699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); 517043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 517143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 517243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 517360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 51741eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { 517543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the statement following the default case 517660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 517743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 5178f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 518043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Default statements are always rebuilt 518143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), 51829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubStmt.get()); 518343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 51841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 518543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 518660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 51871eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { 518860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 518943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 5190f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 519257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), 519357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner S->getDecl()); 519457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner if (!LD) 519557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return StmtError(); 5196534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 5197534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 519843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // FIXME: Pass the real colon location in. 5199ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner return getDerived().RebuildLabelStmt(S->getIdentLoc(), 520057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner cast<LabelDecl>(LD), SourceLocation(), 520157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner SubStmt.get()); 520243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 52031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 520443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 520560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 5206534986f2b21e6050bf00163cd6423fd92155a6edRichard SmithTreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) { 5207534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 5208534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith if (SubStmt.isInvalid()) 5209534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith return StmtError(); 5210534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 5211534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith // TODO: transform attributes 5212534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */) 5213534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith return S; 5214534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 5215534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith return getDerived().RebuildAttributedStmt(S->getAttrLoc(), 5216534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith S->getAttrs(), 5217534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith SubStmt.get()); 5218534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith} 5219534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 5220534986f2b21e6050bf00163cd6423fd92155a6edRichard Smithtemplate<typename Derived> 5221534986f2b21e6050bf00163cd6423fd92155a6edRichard SmithStmtResult 52221eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIfStmt(IfStmt *S) { 522343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 522460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 52258cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor VarDecl *ConditionVar = 0; 52268cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor if (S->getConditionVariable()) { 52274a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ConditionVar 52288cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor = cast_or_null<VarDecl>( 5229aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5230aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5231aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 52328cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor if (!ConditionVar) 5233f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 523499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 52358cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 52364a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 523799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5238f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52394a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5240eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor // Convert the condition to a boolean value. 5241afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 52424a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), 52438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 5244afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 5245f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52464a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 52479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE.get(); 5248afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 524999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 52504a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 52519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 52529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 5253f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52544a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 525543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the "then" branch. 525660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Then = getDerived().TransformStmt(S->getThen()); 525743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Then.isInvalid()) 5258f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 526043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the "else" branch. 526160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Else = getDerived().TransformStmt(S->getElse()); 526243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Else.isInvalid()) 5263f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 526543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 52669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 526799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor ConditionVar == S->getConditionVariable() && 526843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Then.get() == S->getThen() && 526943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Else.get() == S->getElse()) 52703fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 52711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5272eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, 527344aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis Then.get(), 52749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall S->getElseLoc(), Else.get()); 527543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 527643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 527743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 527860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 52791eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { 528043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition. 528160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 5282d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor VarDecl *ConditionVar = 0; 5283d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor if (S->getConditionVariable()) { 52844a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ConditionVar 5285d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor = cast_or_null<VarDecl>( 5286aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5287aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5288aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 5289d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor if (!ConditionVar) 5290f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 529199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 5292d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 52934a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 529499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5295f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 529699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 52971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 529843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Rebuild the switch statement. 529960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Switch 53009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), 5301586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor ConditionVar); 530243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Switch.isInvalid()) 5303f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 53041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 530543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body of the switch statement. 530660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 530743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5308f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 53091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 531043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Complete the switch statement. 53119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), 53129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 531343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 53141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 531543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 531660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 53171eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { 531843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 531960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 53205656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor VarDecl *ConditionVar = 0; 53215656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor if (S->getConditionVariable()) { 53224a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ConditionVar 53235656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor = cast_or_null<VarDecl>( 5324aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5325aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5326aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 53275656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor if (!ConditionVar) 5328f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 532999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 53305656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 53314a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 533299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5333f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5334afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 5335afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 5336afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor // Convert the condition to a boolean value. 53374a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), 53388491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 5339afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 5340f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 53419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE; 5342afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 534399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 53441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 53459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 53469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 5347f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5348eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 534943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 535060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 535143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5352f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 53531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 535443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 53559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 535699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor ConditionVar == S->getConditionVariable() && 535743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 53589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Owned(S); 53591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5360eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, 53619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ConditionVar, Body.get()); 536243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 53631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 536443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 536560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 536643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformDoStmt(DoStmt *S) { 536743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 536860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 536943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5370f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 53711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5372eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor // Transform the condition 537360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(S->getCond()); 5374eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor if (Cond.isInvalid()) 5375f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 53764a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 537743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 537843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Cond.get() == S->getCond() && 537943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 53803fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 53811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 53829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), 53839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall /*FIXME:*/S->getWhileLoc(), Cond.get(), 538443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getRParenLoc()); 538543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 53861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 538743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 538860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 53891eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformForStmt(ForStmt *S) { 539043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the initialization statement 539160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Init = getDerived().TransformStmt(S->getInit()); 539243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Init.isInvalid()) 5393f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 53941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 539543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 539660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 539799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor VarDecl *ConditionVar = 0; 539899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (S->getConditionVariable()) { 53994a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ConditionVar 540099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor = cast_or_null<VarDecl>( 5401aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5402aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5403aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 540499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (!ConditionVar) 5405f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 540699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 540799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 54084a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 540999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5410f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5411afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 5412afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 5413afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor // Convert the condition to a boolean value. 54144a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), 54158491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 5416afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 5417f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5418afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 54199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE.get(); 5420afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 542199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 54221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 54234a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 54249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 5425f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5426eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 542743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the increment 542860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Inc = getDerived().TransformExpr(S->getInc()); 542943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Inc.isInvalid()) 5430f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 54311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 54329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get())); 54339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (S->getInc() && !FullInc.get()) 5434f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5435eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 543643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 543760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 543843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5439f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 54401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 544143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 544243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Init.get() == S->getInit() && 54439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 544443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Inc.get() == S->getInc() && 544543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 54463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 54471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 544843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), 54499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init.get(), FullCond, ConditionVar, 54509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullInc, S->getRParenLoc(), Body.get()); 545143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 545243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 545343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 545460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 54551eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { 545657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), 545757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner S->getLabel()); 545857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner if (!LD) 545957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return StmtError(); 54604a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 546143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Goto statements must always be rebuilt, to resolve the label. 54621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), 546357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner cast<LabelDecl>(LD)); 546443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 546543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 546643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 546760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 54681eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { 546960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Target = getDerived().TransformExpr(S->getTarget()); 547043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Target.isInvalid()) 5471f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5472d29975fd08713eb9d1777e60536addaa62df8995Eli Friedman Target = SemaRef.MaybeCreateExprWithCleanups(Target.take()); 54731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 547443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 547543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Target.get() == S->getTarget()) 54763fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 547743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 547843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), 54799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Target.get()); 548043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 548143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 548243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 548360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 54841eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { 54853fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 548643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 54871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 548843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 548960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 54901eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { 54913fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 549243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 54931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 549443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 549560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 54961eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { 549760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(S->getRetValue()); 549843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Result.isInvalid()) 5499f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 550043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 55011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // FIXME: We always rebuild the return statement because there is no way 550243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // to tell whether the return type of the function has changed. 55039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); 550443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 55051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 550643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 550760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 55081eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { 550943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool DeclChanged = false; 5510686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<Decl *, 4> Decls; 551143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); 551243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor D != DEnd; ++D) { 5513aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), 5514aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor *D); 551543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!Transformed) 5516f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 55171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 551843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Transformed != *D) 551943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor DeclChanged = true; 55201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 552143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Decls.push_back(Transformed); 552243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 55231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 552443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && !DeclChanged) 55253fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 55261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 55271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), 552843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getStartLoc(), S->getEndLoc()); 552943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 55301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 553143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 553260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 553343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { 55344a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 55354e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer SmallVector<Expr*, 8> Constraints; 55364e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer SmallVector<Expr*, 8> Exprs; 5537686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<IdentifierInfo *, 4> Names; 5538a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson 553960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult AsmString; 55404e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer SmallVector<Expr*, 8> Clobbers; 5541703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5542703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool ExprsChanged = false; 55434a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5544703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the outputs. 5545703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { 5546ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson Names.push_back(S->getOutputIdentifier(I)); 55474a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5548703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the constraint literal. 55493fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Constraints.push_back(S->getOutputConstraintLiteral(I)); 55504a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5551703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Transform the output expr. 5552703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson Expr *OutputExpr = S->getOutputExpr(I); 555360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(OutputExpr); 5554703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (Result.isInvalid()) 5555f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 55564a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5557703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson ExprsChanged |= Result.get() != OutputExpr; 55584a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 55599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs.push_back(Result.get()); 5560703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 55614a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5562703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the inputs. 5563703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { 5564ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson Names.push_back(S->getInputIdentifier(I)); 55654a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5566703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the constraint literal. 55673fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Constraints.push_back(S->getInputConstraintLiteral(I)); 55684a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5569703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Transform the input expr. 5570703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson Expr *InputExpr = S->getInputExpr(I); 557160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(InputExpr); 5572703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (Result.isInvalid()) 5573f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 55744a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5575703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson ExprsChanged |= Result.get() != InputExpr; 55764a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 55779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs.push_back(Result.get()); 5578703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 55794a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5580703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (!getDerived().AlwaysRebuild() && !ExprsChanged) 55813fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 5582703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5583703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the clobbers. 5584703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) 55853fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Clobbers.push_back(S->getClobber(I)); 5586703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5587703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the asm string literal. 5588703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson AsmString = SemaRef.Owned(S->getAsmString()); 5589703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5590703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson return getDerived().RebuildAsmStmt(S->getAsmLoc(), 5591703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isSimple(), 5592703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isVolatile(), 5593703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getNumOutputs(), 5594703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getNumInputs(), 5595a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson Names.data(), 55963fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer Constraints, 55973fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer Exprs, 55989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall AsmString.get(), 55993fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer Clobbers, 5600df4ee102aa909e2f40c294701bfeffac63e8d29bChad Rosier S->getRParenLoc()); 560143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 560243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 56038cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosiertemplate<typename Derived> 56048cd64b4c5553fa6284d248336cb7c82dc960a394Chad RosierStmtResult 56058cd64b4c5553fa6284d248336cb7c82dc960a394Chad RosierTreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { 560679efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier ArrayRef<Token> AsmToks = 560779efe24e125553b7fd4a35ffb3b7a45c4f1e661aChad Rosier llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks()); 560862f22b87801882646418bae85111e565f7a53ddbChad Rosier 56097bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(), 56107bd092b054444e9800e8de1d8d71c408dbdc8eadChad Rosier AsmToks, S->getEndLoc()); 56118cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier} 561243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 561343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 561460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 56151eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { 56164dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the body of the @try. 561760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); 56184dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (TryBody.isInvalid()) 5619f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 56204a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 56218f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor // Transform the @catch statements (if present). 56228f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor bool AnyCatchChanged = false; 56234e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer SmallVector<Stmt*, 8> CatchStmts; 56248f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { 562560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); 56264dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Catch.isInvalid()) 5627f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 56288f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor if (Catch.get() != S->getCatchStmt(I)) 56298f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor AnyCatchChanged = true; 56308f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor CatchStmts.push_back(Catch.release()); 56314dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 56324a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 56334dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the @finally statement (if present). 563460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Finally; 56354dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (S->getFinallyStmt()) { 56364dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Finally = getDerived().TransformStmt(S->getFinallyStmt()); 56374dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Finally.isInvalid()) 5638f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 56394dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 56404dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 56414dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // If nothing changed, just retain this statement. 56424dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (!getDerived().AlwaysRebuild() && 56434dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor TryBody.get() == S->getTryBody() && 56448f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor !AnyCatchChanged && 56454dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Finally.get() == S->getFinallyStmt()) 56463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 56474a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 56484dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Build a new statement. 56499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), 56503fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer CatchStmts, Finally.get()); 565143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 56521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 565343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 565460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 56551eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { 5656be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor // Transform the @catch parameter, if there is one. 5657be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *Var = 0; 5658be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (VarDecl *FromVar = S->getCatchParamDecl()) { 5659be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TypeSourceInfo *TSInfo = 0; 5660be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (FromVar->getTypeSourceInfo()) { 5661be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); 5662be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (!TSInfo) 5663f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5664be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 56654a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5666be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor QualType T; 5667be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (TSInfo) 5668be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor T = TSInfo->getType(); 5669be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor else { 5670be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor T = getDerived().TransformType(FromVar->getType()); 5671be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (T.isNull()) 56724a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return StmtError(); 5673be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 56744a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5675be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); 5676be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (!Var) 5677f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5678be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 56794a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 568060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); 5681be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (Body.isInvalid()) 5682f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 56834a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 56844a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), 5685be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor S->getRParenLoc(), 56869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Var, Body.get()); 568743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 56881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 568943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 569060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 56911eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { 56924dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the body. 569360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); 56944dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Body.isInvalid()) 5695f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 56964a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 56974dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // If nothing changed, just retain this statement. 56984dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (!getDerived().AlwaysRebuild() && 56994dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Body.get() == S->getFinallyBody()) 57003fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 57014dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 57024dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Build a new statement. 57034dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), 57049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 570543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 57061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 570743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 570860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 57091eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { 571060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Operand; 5711d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (S->getThrowExpr()) { 5712d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor Operand = getDerived().TransformExpr(S->getThrowExpr()); 5713d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (Operand.isInvalid()) 5714f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5715d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor } 57164a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5717d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (!getDerived().AlwaysRebuild() && 5718d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor Operand.get() == S->getThrowExpr()) 57193fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return getSema().Owned(S); 57204a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 57219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); 572243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 57231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 572443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 572560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 572643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCAtSynchronizedStmt( 57271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCAtSynchronizedStmt *S) { 57288fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Transform the object we are locking. 572960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); 57308fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (Object.isInvalid()) 5731f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 573207524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Object = 573307524039dce5c820f111a1b3f772b4261f004b4aJohn McCall getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), 573407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Object.get()); 573507524039dce5c820f111a1b3f772b4261f004b4aJohn McCall if (Object.isInvalid()) 573607524039dce5c820f111a1b3f772b4261f004b4aJohn McCall return StmtError(); 57374a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 57388fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Transform the body. 573960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); 57408fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (Body.isInvalid()) 5741f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 57424a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 57438fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // If nothing change, just retain the current statement. 57448fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (!getDerived().AlwaysRebuild() && 57458fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor Object.get() == S->getSynchExpr() && 57468fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor Body.get() == S->getSynchBody()) 57473fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 57488fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor 57498fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Build a new statement. 57508fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), 57519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Object.get(), Body.get()); 575243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 575343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 575443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 575560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 5756f85e193739c953358c865005855253af4f68a497John McCallTreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( 5757f85e193739c953358c865005855253af4f68a497John McCall ObjCAutoreleasePoolStmt *S) { 5758f85e193739c953358c865005855253af4f68a497John McCall // Transform the body. 5759f85e193739c953358c865005855253af4f68a497John McCall StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); 5760f85e193739c953358c865005855253af4f68a497John McCall if (Body.isInvalid()) 5761f85e193739c953358c865005855253af4f68a497John McCall return StmtError(); 57624a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5763f85e193739c953358c865005855253af4f68a497John McCall // If nothing changed, just retain this statement. 5764f85e193739c953358c865005855253af4f68a497John McCall if (!getDerived().AlwaysRebuild() && 5765f85e193739c953358c865005855253af4f68a497John McCall Body.get() == S->getSubStmt()) 5766f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(S); 5767f85e193739c953358c865005855253af4f68a497John McCall 5768f85e193739c953358c865005855253af4f68a497John McCall // Build a new statement. 5769f85e193739c953358c865005855253af4f68a497John McCall return getDerived().RebuildObjCAutoreleasePoolStmt( 5770f85e193739c953358c865005855253af4f68a497John McCall S->getAtLoc(), Body.get()); 5771f85e193739c953358c865005855253af4f68a497John McCall} 5772f85e193739c953358c865005855253af4f68a497John McCall 5773f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived> 5774f85e193739c953358c865005855253af4f68a497John McCallStmtResult 577543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCForCollectionStmt( 57761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCForCollectionStmt *S) { 5777c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the element statement. 577860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Element = getDerived().TransformStmt(S->getElement()); 5779c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Element.isInvalid()) 5780f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 57814a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5782c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the collection expression. 578360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Collection = getDerived().TransformExpr(S->getCollection()); 5784c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Collection.isInvalid()) 5785f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 57864a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5787c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the body. 578860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 5789c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Body.isInvalid()) 5790f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 57914a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5792c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // If nothing changed, just retain this statement. 5793c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (!getDerived().AlwaysRebuild() && 5794c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Element.get() == S->getElement() && 5795c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Collection.get() == S->getCollection() && 5796c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Body.get() == S->getBody()) 57973fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 57984a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5799c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Build a new statement. 5800c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), 58019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Element.get(), 58029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Collection.get(), 5803c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor S->getRParenLoc(), 58049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 580543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 580643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 580743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 580843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 580960d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 581043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { 581143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the exception declaration, if any. 581243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor VarDecl *Var = 0; 581343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (S->getExceptionDecl()) { 581443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor VarDecl *ExceptionDecl = S->getExceptionDecl(); 581583cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor TypeSourceInfo *T = getDerived().TransformType( 581683cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor ExceptionDecl->getTypeSourceInfo()); 581783cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor if (!T) 5818f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 58191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 582083cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, 5821ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getInnerLocStart(), 5822ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getLocation(), 5823ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getIdentifier()); 5824ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor if (!Var || Var->isInvalidDecl()) 5825f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 582643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 58271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 582843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the actual exception handler. 582960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); 5830ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor if (Handler.isInvalid()) 5831f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 58321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 583343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 583443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !Var && 583543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Handler.get() == S->getHandlerBlock()) 58363fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 583743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 583843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), 583943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Var, 58409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Handler.get()); 584143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 58421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 584343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 584460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 584543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { 584643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the try block itself. 584760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TryBlock 584843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor = getDerived().TransformCompoundStmt(S->getTryBlock()); 584943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (TryBlock.isInvalid()) 5850f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 58511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 585243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the handlers. 585343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool HandlerChanged = false; 58544e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer SmallVector<Stmt*, 8> Handlers; 585543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { 585660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Handler 585743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor = getDerived().TransformCXXCatchStmt(S->getHandler(I)); 585843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Handler.isInvalid()) 5859f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 58601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 586143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); 586243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Handlers.push_back(Handler.takeAs<Stmt>()); 586343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 58641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 586543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 586643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor TryBlock.get() == S->getTryBlock() && 586743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !HandlerChanged) 58683fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 586943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 58709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), 58713fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer Handlers); 587243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 58731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5874ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate<typename Derived> 5875ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithStmtResult 5876ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithTreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { 5877ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); 5878ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Range.isInvalid()) 5879ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5880ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5881ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt()); 5882ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (BeginEnd.isInvalid()) 5883ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5884ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5885ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ExprResult Cond = getDerived().TransformExpr(S->getCond()); 5886ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Cond.isInvalid()) 5887ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5888c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman if (Cond.get()) 5889c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc()); 5890c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman if (Cond.isInvalid()) 5891c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman return StmtError(); 5892c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman if (Cond.get()) 5893c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take()); 5894ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5895ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ExprResult Inc = getDerived().TransformExpr(S->getInc()); 5896ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Inc.isInvalid()) 5897ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5898c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman if (Inc.get()) 5899c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take()); 5900ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5901ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); 5902ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (LoopVar.isInvalid()) 5903ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5904ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5905ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult NewStmt = S; 5906ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (getDerived().AlwaysRebuild() || 5907ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Range.get() != S->getRangeStmt() || 5908ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith BeginEnd.get() != S->getBeginEndStmt() || 5909ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Cond.get() != S->getCond() || 5910ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Inc.get() != S->getInc() || 5911ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith LoopVar.get() != S->getLoopVarStmt()) 5912ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), 5913ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getColonLoc(), Range.get(), 5914ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith BeginEnd.get(), Cond.get(), 5915ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Inc.get(), LoopVar.get(), 5916ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getRParenLoc()); 5917ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5918ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult Body = getDerived().TransformStmt(S->getBody()); 5919ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Body.isInvalid()) 5920ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5921ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5922ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith // Body has changed but we didn't rebuild the for-range statement. Rebuild 5923ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith // it now so we have a new statement to attach the body to. 5924ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Body.get() != S->getBody() && NewStmt.get() == S) 5925ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), 5926ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getColonLoc(), Range.get(), 5927ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith BeginEnd.get(), Cond.get(), 5928ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Inc.get(), LoopVar.get(), 5929ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getRParenLoc()); 5930ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5931ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (NewStmt.get() == S) 5932ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return SemaRef.Owned(S); 5933ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5934ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); 5935ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith} 5936ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 593728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 593828bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 5939ba0513de93d2fab6db5ab30b6927209fcc883078Douglas GregorTreeTransform<Derived>::TransformMSDependentExistsStmt( 5940ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor MSDependentExistsStmt *S) { 5941ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // Transform the nested-name-specifier, if any. 5942ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 5943ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (S->getQualifierLoc()) { 59444a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier QualifierLoc 5945ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); 5946ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (!QualifierLoc) 5947ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return StmtError(); 5948ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor } 5949ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5950ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // Transform the declaration name. 5951ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor DeclarationNameInfo NameInfo = S->getNameInfo(); 5952ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (NameInfo.getName()) { 5953ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 5954ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (!NameInfo.getName()) 5955ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return StmtError(); 5956ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor } 5957ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5958ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // Check whether anything changed. 5959ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (!getDerived().AlwaysRebuild() && 5960ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor QualifierLoc == S->getQualifierLoc() && 5961ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NameInfo.getName() == S->getNameInfo().getName()) 5962ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return S; 59634a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5964ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // Determine whether this name exists, if we can. 5965ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor CXXScopeSpec SS; 5966ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor SS.Adopt(QualifierLoc); 5967ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor bool Dependent = false; 5968ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) { 5969ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor case Sema::IER_Exists: 5970ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (S->isIfExists()) 5971ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor break; 59724a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5973ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return new (getSema().Context) NullStmt(S->getKeywordLoc()); 5974ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5975ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor case Sema::IER_DoesNotExist: 5976ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (S->isIfNotExists()) 5977ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor break; 59784a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5979ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return new (getSema().Context) NullStmt(S->getKeywordLoc()); 59804a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5981ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor case Sema::IER_Dependent: 5982ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor Dependent = true; 5983ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor break; 59844a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 598565019acfc46ffb191fac4e781ac0c4b8d0c8434eDouglas Gregor case Sema::IER_Error: 598665019acfc46ffb191fac4e781ac0c4b8d0c8434eDouglas Gregor return StmtError(); 5987ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor } 59884a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5989ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // We need to continue with the instantiation, so do so now. 5990ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); 5991ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (SubStmt.isInvalid()) 5992ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return StmtError(); 59934a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5994ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // If we have resolved the name, just transform to the substatement. 5995ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (!Dependent) 5996ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return SubStmt; 59974a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 5998ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // The name is still dependent, so build a dependent expression again. 5999ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), 6000ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor S->isIfExists(), 6001ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor QualifierLoc, 6002ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NameInfo, 6003ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor SubStmt.get()); 6004ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor} 6005ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 6006ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregortemplate<typename Derived> 6007ba0513de93d2fab6db5ab30b6927209fcc883078Douglas GregorStmtResult 600828bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { 600928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock()); 601028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(TryBlock.isInvalid()) return StmtError(); 601128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 601228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); 601328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(!getDerived().AlwaysRebuild() && 601428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley TryBlock.get() == S->getTryBlock() && 601528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Handler.get() == S->getHandler()) 601628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return SemaRef.Owned(S); 601728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 601828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), 601928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley S->getTryLoc(), 602028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley TryBlock.take(), 602128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Handler.take()); 602228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 602328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 602428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 602528bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 602628bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { 602728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); 602828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(Block.isInvalid()) return StmtError(); 602928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 603028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), 603128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Block.take()); 603228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 603328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 603428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 603528bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 603628bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { 603728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); 603828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(FilterExpr.isInvalid()) return StmtError(); 603928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 604028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); 604128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(Block.isInvalid()) return StmtError(); 604228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 604328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), 604428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley FilterExpr.take(), 604528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Block.take()); 604628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 604728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 604828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 604928bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 605028bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { 605128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(isa<SEHFinallyStmt>(Handler)) 605228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); 605328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley else 605428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); 605528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 605628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 605743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===// 6058b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Expression transformation 6059577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 60601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 606160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6062454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { 60633fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 60641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 60651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 606760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6068454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { 606940d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc; 607040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (E->getQualifierLoc()) { 607140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc 607240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 607340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!QualifierLoc) 6074f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6075a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 6076dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 6077dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *ND 60787c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), 60797c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getDecl())); 6080b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!ND) 6081f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 60821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6083ec8045d3f0375302eadaa63deb373bacaf25a569John McCall DeclarationNameInfo NameInfo = E->getNameInfo(); 6084ec8045d3f0375302eadaa63deb373bacaf25a569John McCall if (NameInfo.getName()) { 6085ec8045d3f0375302eadaa63deb373bacaf25a569John McCall NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 6086ec8045d3f0375302eadaa63deb373bacaf25a569John McCall if (!NameInfo.getName()) 6087f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6088ec8045d3f0375302eadaa63deb373bacaf25a569John McCall } 60892577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 60902577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!getDerived().AlwaysRebuild() && 609140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc == E->getQualifierLoc() && 6092a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor ND == E->getDecl() && 60932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getDecl()->getDeclName() && 6094096832c5ed5b9106fa177ebc148489760c3bc496John McCall !E->hasExplicitTemplateArgs()) { 60951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6096dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // Mark it referenced in the new context regardless. 6097dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // FIXME: this is a bit instantiation-specific. 60985f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkDeclRefReferenced(E); 6099a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 61003fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6101a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 6102dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 6103dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; 6104096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (E->hasExplicitTemplateArgs()) { 6105dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TemplateArgs = &TransArgs; 6106dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TransArgs.setLAngleLoc(E->getLAngleLoc()); 6107dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TransArgs.setRAngleLoc(E->getRAngleLoc()); 6108fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 6109fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 6110fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 6111fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 6112dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall } 6113dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 61144a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, 611540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor TemplateArgs); 6116577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 61171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6118b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 611960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6120454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { 61213fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6122577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 61231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6124b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 612560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6126454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { 61273fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6128b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 61291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6130b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 613160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6132454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { 61333fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6134b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 61351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 613760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6138454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { 61393fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6140b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 61411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6142b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 614360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6144454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { 61453fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6146b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 61471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6148b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 614960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 61509fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard SmithTreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { 61519fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith return SemaRef.MaybeBindToTemporary(E); 61529fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith} 61539fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith 61549fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smithtemplate<typename Derived> 61559fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard SmithExprResult 6156f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneTreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { 6157f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult ControllingExpr = 6158f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne getDerived().TransformExpr(E->getControllingExpr()); 6159f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (ControllingExpr.isInvalid()) 6160f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ExprError(); 6161f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 6162686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<Expr *, 4> AssocExprs; 6163686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<TypeSourceInfo *, 4> AssocTypes; 6164f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne for (unsigned i = 0; i != E->getNumAssocs(); ++i) { 6165f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); 6166f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (TS) { 6167f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo *AssocType = getDerived().TransformType(TS); 6168f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!AssocType) 6169f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ExprError(); 6170f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes.push_back(AssocType); 6171f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } else { 6172f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes.push_back(0); 6173f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 6174f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 6175f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); 6176f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (AssocExpr.isInvalid()) 6177f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ExprError(); 6178f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs.push_back(AssocExpr.release()); 6179f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 6180f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 6181f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), 6182f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E->getDefaultLoc(), 6183f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E->getRParenLoc(), 6184f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ControllingExpr.release(), 6185f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes.data(), 6186f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs.data(), 6187f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E->getNumAssocs()); 6188f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne} 6189f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 6190f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbournetemplate<typename Derived> 6191f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneExprResult 6192454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { 619360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 6194b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6195f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6197b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) 61983fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 61991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), 6201b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParen()); 6202b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6203b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 62041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 620560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6206454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { 620760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 6208b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6209f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6211b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) 62123fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 62131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6214b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), 6215b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOpcode(), 62169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get()); 6217b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 62181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6219b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 622060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 62218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorTreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { 62228ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Transform the type. 62238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); 62248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (!Type) 6225f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62264a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 62278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Transform all of the components into components similar to what the 62288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // parser uses. 62294a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier // FIXME: It would be slightly more efficient in the non-dependent case to 62304a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier // just map FieldDecls, rather than requiring the rebuilder to look for 62314a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier // the fields again. However, __builtin_offsetof is rare enough in 62328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // template code that we don't care. 62338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor bool ExprChanged = false; 6234f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall typedef Sema::OffsetOfComponent Component; 62358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor typedef OffsetOfExpr::OffsetOfNode Node; 6236686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<Component, 4> Components; 62378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { 62388ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor const Node &ON = E->getComponent(I); 62398ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Component Comp; 624072be24f39c162448e53dd73cf57cc6357114361eDouglas Gregor Comp.isBrackets = true; 624106dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara Comp.LocStart = ON.getSourceRange().getBegin(); 624206dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara Comp.LocEnd = ON.getSourceRange().getEnd(); 62438ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor switch (ON.getKind()) { 62448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Array: { 62458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); 624660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Index = getDerived().TransformExpr(FromIndex); 62478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (Index.isInvalid()) 6248f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62494a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 62508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor ExprChanged = ExprChanged || Index.get() != FromIndex; 62518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.isBrackets = true; 62529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Comp.U.E = Index.get(); 62538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor break; 62548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 62554a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 62568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Field: 62578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Identifier: 62588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.isBrackets = false; 62598ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.U.IdentInfo = ON.getFieldName(); 626029d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor if (!Comp.U.IdentInfo) 626129d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor continue; 62624a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 62638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor break; 62644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 6265cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor case Node::Base: 6266cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor // Will be recomputed during the rebuild. 6267cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor continue; 62688ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 62694a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 62708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Components.push_back(Comp); 62718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 62724a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 62738ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // If nothing changed, retain the existing expression. 62748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (!getDerived().AlwaysRebuild() && 62758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Type == E->getTypeSourceInfo() && 62768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor !ExprChanged) 62773fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 62784a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 62798ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Build a new offsetof expression. 62808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, 62818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Components.data(), Components.size(), 62828ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor E->getRParenLoc()); 62837cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall} 62847cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall 62857cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCalltemplate<typename Derived> 62867cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallExprResult 62877cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallTreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { 62887cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall assert(getDerived().AlreadyTransformed(E->getType()) && 62897cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall "opaque value expression requires transformation"); 62907cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall return SemaRef.Owned(E); 62918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 62928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 62938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregortemplate<typename Derived> 629460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 62954b9c2d235fb9449e249d74f48ecfec601650de93John McCallTreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { 629601e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // Rebuild the syntactic form. The original syntactic form has 629701e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // opaque-value expressions in it, so strip those away and rebuild 629801e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // the result. This is a really awful way of doing this, but the 629901e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // better solution (rebuilding the semantic expressions and 630001e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // rebinding OVEs as necessary) doesn't work; we'd need 630101e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // TreeTransform to not strip away implicit conversions. 630201e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); 630301e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall ExprResult result = getDerived().TransformExpr(newSyntacticForm); 63044b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (result.isInvalid()) return ExprError(); 63054b9c2d235fb9449e249d74f48ecfec601650de93John McCall 63064b9c2d235fb9449e249d74f48ecfec601650de93John McCall // If that gives us a pseudo-object result back, the pseudo-object 63074b9c2d235fb9449e249d74f48ecfec601650de93John McCall // expression must have been an lvalue-to-rvalue conversion which we 63084b9c2d235fb9449e249d74f48ecfec601650de93John McCall // should reapply. 63094b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) 63104b9c2d235fb9449e249d74f48ecfec601650de93John McCall result = SemaRef.checkPseudoObjectRValue(result.take()); 63114b9c2d235fb9449e249d74f48ecfec601650de93John McCall 63124b9c2d235fb9449e249d74f48ecfec601650de93John McCall return result; 63134b9c2d235fb9449e249d74f48ecfec601650de93John McCall} 63144b9c2d235fb9449e249d74f48ecfec601650de93John McCall 63154b9c2d235fb9449e249d74f48ecfec601650de93John McCalltemplate<typename Derived> 63164b9c2d235fb9449e249d74f48ecfec601650de93John McCallExprResult 6317f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter CollingbourneTreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( 6318f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr *E) { 6319b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->isArgumentType()) { 6320a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *OldT = E->getArgumentTypeInfo(); 63215557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor 6322a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *NewT = getDerived().TransformType(OldT); 63235ab75172051a6d2ea71a80a79e81c65519fd3462John McCall if (!NewT) 6324f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63265ab75172051a6d2ea71a80a79e81c65519fd3462John McCall if (!getDerived().AlwaysRebuild() && OldT == NewT) 63273fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 63281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6329f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), 6330f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getKind(), 6331f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getSourceRange()); 6332b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 63331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 633472b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman // C++0x [expr.sizeof]p1: 633572b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman // The operand is either an expression, which is an unevaluated operand 633672b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman // [...] 633772b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 63381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 633972b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); 634072b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman if (SubExpr.isInvalid()) 634172b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman return ExprError(); 63421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 634372b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) 634472b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman return SemaRef.Owned(E); 63451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6346f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), 6347f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getOperatorLoc(), 6348f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getKind(), 6349f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getSourceRange()); 6350b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 63511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6352b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 635360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6354454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { 635560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6356b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6357f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 635960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6360b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6361f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6364b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6365b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6366b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 63673fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 63681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildArraySubscriptExpr(LHS.get(), 6370b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLHS()->getLocStart(), 63719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get(), 6372b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRBracketLoc()); 6373b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 63741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 637660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6377454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCallExpr(CallExpr *E) { 6378b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the callee. 637960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 6380b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Callee.isInvalid()) 6381f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6382b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6383b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform arguments. 6384b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgChanged = false; 63854e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer SmallVector<Expr*, 8> Args; 63864a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 6387aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgChanged)) 6388aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 63894a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 6390b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6391b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Callee.get() == E->getCallee() && 6392b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgChanged) 639392be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E);; 63941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6395b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Wrong source location information for the '('. 63961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeLParenLoc 6397b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = ((Expr *)Callee.get())->getSourceRange().getBegin(); 63989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, 63993fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer Args, 6400b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6401b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 64031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 640460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6405454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { 640660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 6407b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Base.isInvalid()) 6408f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 641040d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc; 641183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor if (E->hasQualifier()) { 641240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc 641340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 64144a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 641540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!QualifierLoc) 6416f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 641783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 6418e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); 64191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6420f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *Member 64217c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), 64227c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getMemberDecl())); 6423b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Member) 6424f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 64266bb8017bb9e828d118e15e59d71c66bba323c364John McCall NamedDecl *FoundDecl = E->getFoundDecl(); 64276bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (FoundDecl == E->getMemberDecl()) { 64286bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl = Member; 64296bb8017bb9e828d118e15e59d71c66bba323c364John McCall } else { 64306bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl = cast_or_null<NamedDecl>( 64316bb8017bb9e828d118e15e59d71c66bba323c364John McCall getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); 64326bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!FoundDecl) 6433f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64346bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 64356bb8017bb9e828d118e15e59d71c66bba323c364John McCall 6436b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6437b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Base.get() == E->getBase() && 643840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc == E->getQualifierLoc() && 64398a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor Member == E->getMemberDecl() && 64406bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl == E->getFoundDecl() && 6441096832c5ed5b9106fa177ebc148489760c3bc496John McCall !E->hasExplicitTemplateArgs()) { 64424a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 64431f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson // Mark it referenced in the new context regardless. 64441f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson // FIXME: this is a bit instantiation-specific. 64455f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkMemberReferenced(E); 64465f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman 64473fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 64481f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson } 6449b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6450d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs; 6451096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (E->hasExplicitTemplateArgs()) { 6452d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TransArgs.setLAngleLoc(E->getLAngleLoc()); 6453d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TransArgs.setRAngleLoc(E->getRAngleLoc()); 6454fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 6455fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 6456fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 6457fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 64588a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor } 64594a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 6460b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Bogus source location for the operator 6461b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeOperatorLoc 6462b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); 6463b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6464c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // FIXME: to do this check properly, we will need to preserve the 6465c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // first-qualifier-in-scope here, just in case we had a dependent 6466c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // base (and therefore couldn't do the check) and a 6467c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // nested-name-qualifier (and therefore could do the lookup). 6468c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall NamedDecl *FirstQualifierInScope = 0; 6469c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 64709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, 6471b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrow(), 647240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc, 6473e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateKWLoc, 64742577743c5650c646fb705df01403707e94f2df04Abramo Bagnara E->getMemberNameInfo(), 64758a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor Member, 64766bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl, 6477096832c5ed5b9106fa177ebc148489760c3bc496John McCall (E->hasExplicitTemplateArgs() 6478d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall ? &TransArgs : 0), 6479c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall FirstQualifierInScope); 6480b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6482b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 648360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6484454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { 648560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6486b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6487f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 648960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6490b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6491f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6493b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6494b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6495b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 64963fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 64971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6498b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), 64999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), RHS.get()); 6500b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6501b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 65021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 650360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6504b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCompoundAssignOperator( 6505454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CompoundAssignOperator *E) { 6506454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformBinaryOperator(E); 6507b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 65081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6509b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 651056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallExprResult TreeTransform<Derived>:: 651156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallTransformBinaryConditionalOperator(BinaryConditionalOperator *e) { 651256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // Just rebuild the common and RHS expressions and see whether we 651356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // get any changes. 651456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 651556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); 651656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (commonExpr.isInvalid()) 651756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return ExprError(); 651856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 651956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); 652056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (rhs.isInvalid()) 652156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return ExprError(); 652256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 652356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (!getDerived().AlwaysRebuild() && 652456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall commonExpr.get() == e->getCommon() && 652556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs.get() == e->getFalseExpr()) 652656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return SemaRef.Owned(e); 652756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 652856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return getDerived().RebuildConditionalOperator(commonExpr.take(), 652956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall e->getQuestionLoc(), 653056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 0, 653156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall e->getColonLoc(), 653256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs.get()); 653356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 653456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 653556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCalltemplate<typename Derived> 653660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6537454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { 653860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(E->getCond()); 6539b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Cond.isInvalid()) 6540f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 654260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6543b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6544f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 654660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6547b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6548f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6550b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6551b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Cond.get() == E->getCond() && 6552b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6553b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 65543fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 65551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 65569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildConditionalOperator(Cond.get(), 655747e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor E->getQuestionLoc(), 65589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), 655947e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor E->getColonLoc(), 65609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get()); 6561b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 65621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 65631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 656460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6565454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { 6566a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor // Implicit casts are eliminated during transformation, since they 6567a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor // will be recomputed by semantic analysis after transformation. 65686eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return getDerived().TransformExpr(E->getSubExprAsWritten()); 6569b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 65701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6571b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 657260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6573454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { 6574ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 6575ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 6576ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 65774a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 657860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 65796eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 6580b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6581f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6583b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6584ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 6585b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 65863fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 65871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 65889d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), 6589ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type, 6590b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc(), 65919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get()); 6592b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 65931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6594b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 659560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6596454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { 659742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *OldT = E->getTypeSourceInfo(); 659842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *NewT = getDerived().TransformType(OldT); 659942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall if (!NewT) 6600f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 660260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Init = getDerived().TransformExpr(E->getInitializer()); 6603b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Init.isInvalid()) 6604f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6606b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 660742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall OldT == NewT && 6608b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Init.get() == E->getInitializer()) 660992be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 6610b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 66111d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // Note: the expression type doesn't necessarily match the 66121d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // type-as-written, but that's okay, because it should always be 66131d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // derivable from the initializer. 66141d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 661542f56b50062cd3b3c6b23fdb9053578ae9145664John McCall return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, 6616b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getInitializer()->getLocEnd(), 66179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init.get()); 6618b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6620b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 662160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6622454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { 662360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 6624b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Base.isInvalid()) 6625f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6627b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6628b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Base.get() == E->getBase()) 66293fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 66301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6631b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Bad source location 66321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeOperatorLoc 6633b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); 66349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, 6635b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getAccessorLoc(), 6636b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getAccessor()); 6637b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6639b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 664060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6641454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { 6642b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool InitChanged = false; 66431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 66444e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer SmallVector<Expr*, 4> Inits; 66454a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, 6646aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Inits, &InitChanged)) 6647aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 66484a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 6649b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && !InitChanged) 66503fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 66511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 66523fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer return getDerived().RebuildInitList(E->getLBraceLoc(), Inits, 6653e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor E->getRBraceLoc(), E->getType()); 6654b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6656b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 665760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6658454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { 6659b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Designation Desig; 66601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 666143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transform the initializer value 666260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Init = getDerived().TransformExpr(E->getInit()); 6663b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Init.isInvalid()) 6664f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 666643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transform the designators. 66674e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer SmallVector<Expr*, 4> ArrayExprs; 6668b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ExprChanged = false; 6669b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), 6670b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor DEnd = E->designators_end(); 6671b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D != DEnd; ++D) { 6672b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (D->isFieldDesignator()) { 6673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Desig.AddDesignator(Designator::getField(D->getFieldName(), 6674b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getDotLoc(), 6675b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getFieldLoc())); 6676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor continue; 6677b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 66781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6679b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (D->isArrayDesignator()) { 668060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); 6681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Index.isInvalid()) 6682f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 66841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Desig.AddDesignator(Designator::getArray(Index.get(), 6685b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getLBracketLoc())); 66861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6687b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); 6688b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(Index.release()); 6689b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor continue; 6690b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 66911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6692b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor assert(D->isArrayRangeDesignator() && "New kind of designator?"); 669360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Start 6694b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = getDerived().TransformExpr(E->getArrayRangeStart(*D)); 6695b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Start.isInvalid()) 6696f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 669860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); 6699b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (End.isInvalid()) 6700f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 67011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 67021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Desig.AddDesignator(Designator::getArrayRange(Start.get(), 6703b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor End.get(), 6704b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getLBracketLoc(), 6705b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getEllipsisLoc())); 67061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6707b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || 6708b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor End.get() != E->getArrayRangeEnd(*D); 67091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6710b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(Start.release()); 6711b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(End.release()); 6712b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 67131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6714b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6715b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Init.get() == E->getInit() && 6716b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ExprChanged) 67173fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 67181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 67193fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs, 6720b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getEqualOrColonLoc(), 67219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall E->usesGNUSyntax(), Init.get()); 6722b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 67231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6724b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 672560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6726b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformImplicitValueInitExpr( 6727454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall ImplicitValueInitExpr *E) { 67285557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); 67294a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 67305557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor // FIXME: Will we ever have proper type location here? Will we actually 67315557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor // need to transform the type? 6732b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor QualType T = getDerived().TransformType(E->getType()); 6733b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (T.isNull()) 6734f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 67351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6736b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6737b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T == E->getType()) 67383fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 67391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6740b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildImplicitValueInitExpr(T); 6741b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 67421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6743b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 674460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6745454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { 67469bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); 67479bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor if (!TInfo) 6748f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 67491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 675060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 6751b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6752f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 67531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6754b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 67552cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TInfo == E->getWrittenTypeInfo() && 6756b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 67573fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 67581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 67599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), 67602cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TInfo, E->getRParenLoc()); 6761b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6762b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6763b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 676460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6765454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { 6766b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 67674e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer SmallVector<Expr*, 4> Inits; 6768aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, 6769aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 6770aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 67714a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 6772b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildParenListExpr(E->getLParenLoc(), 67733fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer Inits, 6774b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6775b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 67761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6777b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform an address-of-label expression. 6778b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 6779b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// By default, the transformation of an address-of-label expression always 6780b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// rebuilds the expression, so that the label identifier can be resolved to 6781b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// the corresponding label statement by semantic analysis. 6782b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 678360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6784454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { 678557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), 678657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner E->getLabel()); 678757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner if (!LD) 678857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return ExprError(); 67894a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 6790b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), 679157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner cast<LabelDecl>(LD)); 6792b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 67931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 67941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 67954a9d795502f8e001cdc6465ea7a0739ca48dd483Chad RosierExprResult 6796454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { 67977f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall SemaRef.ActOnStartStmtExpr(); 679860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt 6799b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = getDerived().TransformCompoundStmt(E->getSubStmt(), true); 68007f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall if (SubStmt.isInvalid()) { 68017f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall SemaRef.ActOnStmtExprError(); 6802f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68037f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall } 68041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6805b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 68067f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall SubStmt.get() == E->getSubStmt()) { 68077f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall // Calling this an 'error' is unintuitive, but it does the right thing. 68087f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall SemaRef.ActOnStmtExprError(); 680992be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 68107f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall } 68111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 68121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildStmtExpr(E->getLParenLoc(), 68139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubStmt.get(), 6814b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6815b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6817b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 681860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6819454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { 682060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(E->getCond()); 6821b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Cond.isInvalid()) 6822f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 682460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6825b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6826f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 682860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6829b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6830f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6832b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6833b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Cond.get() == E->getCond() && 6834b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6835b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 68363fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 68371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6838b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), 68399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond.get(), LHS.get(), RHS.get(), 6840b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6841b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6843b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 684460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6845454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { 68463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6847b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6848b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6849b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 685060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6851454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { 6852668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor switch (E->getOperator()) { 6853668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_New: 6854668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Delete: 6855668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Array_New: 6856668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Array_Delete: 6857668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); 68584a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 6859668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Call: { 6860668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // This is a call to an object's operator(). 6861668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); 6862668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6863668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Transform the object itself. 686460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Object = getDerived().TransformExpr(E->getArg(0)); 6865668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor if (Object.isInvalid()) 6866f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6867668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6868668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // FIXME: Poor location information 6869668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor SourceLocation FakeLParenLoc 6870668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor = SemaRef.PP.getLocForEndOfToken( 6871668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor static_cast<Expr *>(Object.get())->getLocEnd()); 6872668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6873668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Transform the call arguments. 68744e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer SmallVector<Expr*, 8> Args; 68754a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, 6876aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args)) 6877aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6878668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 68799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, 68803fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer Args, 6881668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor E->getLocEnd()); 6882668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor } 6883668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6884668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ 6885668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_##Name: 6886668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) 6887668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#include "clang/Basic/OperatorKinds.def" 6888668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Subscript: 6889668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Handled below. 6890668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor break; 6891668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6892668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Conditional: 6893668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("conditional operator is not actually overloadable"); 6894668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6895668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_None: 6896668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case NUM_OVERLOADED_OPERATORS: 6897668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("not an overloaded operator?"); 6898668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor } 6899668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 690060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 6901b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Callee.isInvalid()) 6902f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 69031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 690460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult First = getDerived().TransformExpr(E->getArg(0)); 6905b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (First.isInvalid()) 6906f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6907b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 690860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Second; 6909b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->getNumArgs() == 2) { 6910b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Second = getDerived().TransformExpr(E->getArg(1)); 6911b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Second.isInvalid()) 6912f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6913b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 69141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6915b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6916b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Callee.get() == E->getCallee() && 6917b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor First.get() == E->getArg(0) && 69181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) 691992be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 69201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6921b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), 6922b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOperatorLoc(), 69239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Callee.get(), 69249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall First.get(), 69259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Second.get()); 6926b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 69271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6928b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 692960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6930454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { 6931454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCallExpr(E); 6932b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 69331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6934b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 6935e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneExprResult 6936e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneTreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { 6937e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // Transform the callee. 6938e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 6939e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (Callee.isInvalid()) 6940e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return ExprError(); 6941e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6942e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // Transform exec config. 6943e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); 6944e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (EC.isInvalid()) 6945e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return ExprError(); 6946e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6947e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // Transform arguments. 6948e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne bool ArgChanged = false; 69494e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer SmallVector<Expr*, 8> Args; 69504a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 6951e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne &ArgChanged)) 6952e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return ExprError(); 6953e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6954e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (!getDerived().AlwaysRebuild() && 6955e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne Callee.get() == E->getCallee() && 6956e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne !ArgChanged) 695792be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 6958e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6959e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // FIXME: Wrong source location information for the '('. 6960e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne SourceLocation FakeLParenLoc 6961e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne = ((Expr *)Callee.get())->getSourceRange().getBegin(); 6962e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, 69633fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer Args, 6964e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne E->getRParenLoc(), EC.get()); 6965e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne} 6966e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6967e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournetemplate<typename Derived> 696860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6969454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { 6970ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 6971ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 6972ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 69734a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 697460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 69756eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 6976b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6977f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 69781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6979b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6980ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 6981b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 69823fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 69831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6984b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Poor source location information here. 69851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeLAngleLoc 6986b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); 6987b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); 6988b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeRParenLoc 6989b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken( 6990b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getSubExpr()->getSourceRange().getEnd()); 6991b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), 69921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump E->getStmtClass(), 6993b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeLAngleLoc, 6994ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type, 6995b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRAngleLoc, 6996b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRAngleLoc, 69979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 6998b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRParenLoc); 6999b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 70001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7001b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 700260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7003454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { 7004454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 7005b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 70061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7007b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 700860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7009454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { 7010454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 7011b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 70121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7013b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 701460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7015b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXReinterpretCastExpr( 7016454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXReinterpretCastExpr *E) { 7017454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 7018b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 70191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7020b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 702160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7022454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { 7023454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 7024b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 70251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7026b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 702760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7028b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXFunctionalCastExpr( 7029454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXFunctionalCastExpr *E) { 7030ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 7031ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 7032ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 70331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 703460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 70356eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 7036b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 7037f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7039b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7040ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 7041b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 70423fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 70431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7044ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return getDerived().RebuildCXXFunctionalCastExpr(Type, 7045b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getSubExpr()->getLocStart(), 70469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 7047b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 7048b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 70491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7050b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 705160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7052454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { 7053b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->isTypeOperand()) { 705457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TypeSourceInfo *TInfo 705557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor = getDerived().TransformType(E->getTypeOperandSourceInfo()); 705657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor if (!TInfo) 7057f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7059b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 706057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TInfo == E->getTypeOperandSourceInfo()) 70613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 70621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 706357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return getDerived().RebuildCXXTypeidExpr(E->getType(), 706457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor E->getLocStart(), 706557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TInfo, 7066b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 7067b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 70681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7069ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman // We don't know whether the subexpression is potentially evaluated until 7070ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman // after we perform semantic analysis. We speculatively assume it is 7071ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman // unevaluated; it will get fixed later if the subexpression is in fact 7072b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // potentially evaluated. 7073ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 70741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 707560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); 7076b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 7077f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7079b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7080b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getExprOperand()) 70813fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 70821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 708357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return getDerived().RebuildCXXTypeidExpr(E->getType(), 708457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor E->getLocStart(), 70859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 7086b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 7087b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7088b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7089b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 709060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 709101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetTreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { 709201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (E->isTypeOperand()) { 709301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TypeSourceInfo *TInfo 709401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet = getDerived().TransformType(E->getTypeOperandSourceInfo()); 709501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!TInfo) 709601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return ExprError(); 709701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 709801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!getDerived().AlwaysRebuild() && 709901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TInfo == E->getTypeOperandSourceInfo()) 71003fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 710101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 71023c52a218f41f091a17582d037663594d2b8dc708Douglas Gregor return getDerived().RebuildCXXUuidofExpr(E->getType(), 710301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocStart(), 710401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TInfo, 710501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocEnd()); 710601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 710701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 710801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 710901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 711001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); 711101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (SubExpr.isInvalid()) 711201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return ExprError(); 711301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 711401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!getDerived().AlwaysRebuild() && 711501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SubExpr.get() == E->getExprOperand()) 71163fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 711701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 711801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getDerived().RebuildCXXUuidofExpr(E->getType(), 711901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocStart(), 712001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SubExpr.get(), 712101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocEnd()); 712201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet} 712301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 712401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichettemplate<typename Derived> 712501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetExprResult 7126454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { 71273fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7128b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 71291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7130b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 713160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7132b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( 7133454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXNullPtrLiteralExpr *E) { 71343fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7135b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 71361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7137b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 713860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7139454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { 7140ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor DeclContext *DC = getSema().getFunctionLevelDeclContext(); 71417a614d8380297fcd2bc23986241905d97222948cRichard Smith QualType T; 71427a614d8380297fcd2bc23986241905d97222948cRichard Smith if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) 71437a614d8380297fcd2bc23986241905d97222948cRichard Smith T = MD->getThisType(getSema().Context); 71447a614d8380297fcd2bc23986241905d97222948cRichard Smith else 71457a614d8380297fcd2bc23986241905d97222948cRichard Smith T = getSema().Context.getPointerType( 71467a614d8380297fcd2bc23986241905d97222948cRichard Smith getSema().Context.getRecordType(cast<CXXRecordDecl>(DC))); 71471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7148ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor if (!getDerived().AlwaysRebuild() && T == E->getType()) { 7149ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor // Make sure that we capture 'this'. 7150ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor getSema().CheckCXXThisCapture(E->getLocStart()); 71513fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7152ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor } 71534a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 7154828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); 7155b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 71561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7157b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 715860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7159454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { 716060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 7161b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 7162f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 71631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7164b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7165b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 71663fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7167b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7168bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), 7169bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor E->isThrownVariableInScope()); 7170b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 71711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7172b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 717360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7174454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { 71751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParmVarDecl *Param 71767c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), 71777c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getParam())); 7178b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Param) 7179f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 71801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 718153cb6f82c41397917b14fb8cdcb32e6c9bd07655Chandler Carruth if (!getDerived().AlwaysRebuild() && 7182b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Param == E->getParam()) 71833fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 71841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7185036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); 7186b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 71871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7188b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 718960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7190ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas GregorTreeTransform<Derived>::TransformCXXScalarValueInitExpr( 7191ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXScalarValueInitExpr *E) { 7192ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 7193ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 7194f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 71954a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 7196b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7197ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo()) 71983fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 71991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 72004a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return getDerived().RebuildCXXScalarValueInitExpr(T, 7201ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /*FIXME:*/T->getTypeLoc().getEndLoc(), 7202ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor E->getRParenLoc()); 7203b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 72041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7205b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 720660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7207454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { 7208b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the type that we're allocating 72091bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *AllocTypeInfo 72101bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); 72111bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor if (!AllocTypeInfo) 7212f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 72131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7214b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the size of the array we're allocating (if any). 721560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); 7216b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (ArraySize.isInvalid()) 7217f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 72181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7219b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the placement arguments (if any). 7220b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 72214e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer SmallVector<Expr*, 8> PlacementArgs; 72224a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (getDerived().TransformExprs(E->getPlacementArgs(), 7223aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor E->getNumPlacementArgs(), true, 7224aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor PlacementArgs, &ArgumentChanged)) 72252aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return ExprError(); 72262aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl 72272aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl // Transform the initializer (if any). 72282aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl Expr *OldInit = E->getInitializer(); 72292aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl ExprResult NewInit; 72302aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl if (OldInit) 72312aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl NewInit = getDerived().TransformExpr(OldInit); 72322aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl if (NewInit.isInvalid()) 72332aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return ExprError(); 72341af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor 72352aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl // Transform new operator and delete operator. 72361af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorNew = 0; 72371af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorNew()) { 72381af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorNew = cast_or_null<FunctionDecl>( 72397c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 72407c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorNew())); 72411af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorNew) 7242f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 72431af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 72441af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor 72451af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorDelete = 0; 72461af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorDelete()) { 72471af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete = cast_or_null<FunctionDecl>( 72487c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 72497c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorDelete())); 72501af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorDelete) 7251f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 72521af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 72534a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 7254b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 72551bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocTypeInfo == E->getAllocatedTypeSourceInfo() && 7256b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArraySize.get() == E->getArraySize() && 72572aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl NewInit.get() == OldInit && 72581af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorNew == E->getOperatorNew() && 72591af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete == E->getOperatorDelete() && 72601af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor !ArgumentChanged) { 72611af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark any declarations we need as referenced. 72621af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: instantiation-specific. 72631af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorNew) 72645f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew); 72651af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorDelete) 72665f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); 72674a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 72682aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl if (E->isArray() && !E->getAllocatedType()->isDependentType()) { 72692ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor QualType ElementType 72702ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor = SemaRef.Context.getBaseElementType(E->getAllocatedType()); 72712ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { 72722ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); 72732ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { 72745f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor); 72752ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor } 72762ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor } 72772ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor } 72782aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl 72793fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 72801af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 72811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 72821bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor QualType AllocType = AllocTypeInfo->getType(); 72835b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (!ArraySize.get()) { 72845b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // If no array size was specified, but the new expression was 72855b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // instantiated with an array type (e.g., "new T" where T is 72865b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // instantiated with "int[4]"), extract the outer bound from the 72875b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // array type as our array size. We do this with constant and 72885b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // dependently-sized array types. 72895b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); 72905b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (!ArrayT) { 72915b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // Do nothing 72925b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } else if (const ConstantArrayType *ConsArrayT 72935b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor = dyn_cast<ConstantArrayType>(ArrayT)) { 72944a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ArraySize 72959996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, 72964a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ConsArrayT->getSize(), 72979996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis SemaRef.Context.getSizeType(), 72989996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /*FIXME:*/E->getLocStart())); 72995b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor AllocType = ConsArrayT->getElementType(); 73005b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } else if (const DependentSizedArrayType *DepArrayT 73015b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor = dyn_cast<DependentSizedArrayType>(ArrayT)) { 73025b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (DepArrayT->getSizeExpr()) { 73033fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); 73045b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor AllocType = DepArrayT->getElementType(); 73055b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 73065b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 73075b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 73082aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl 7309b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXNewExpr(E->getLocStart(), 7310b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isGlobalNew(), 7311b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLocStart(), 73123fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer PlacementArgs, 7313b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLocStart(), 73144bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor E->getTypeIdParens(), 7315b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor AllocType, 73161bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocTypeInfo, 73179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ArraySize.get(), 73182aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl E->getDirectInitRange(), 73192aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl NewInit.take()); 7320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 73211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7322b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 732360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7324454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { 732560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Operand = getDerived().TransformExpr(E->getArgument()); 7326b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Operand.isInvalid()) 7327f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 73281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 73291af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Transform the delete operator, if known. 73301af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorDelete = 0; 73311af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorDelete()) { 73321af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete = cast_or_null<FunctionDecl>( 73337c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 73347c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorDelete())); 73351af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorDelete) 7336f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 73371af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 73384a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 7339b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 73401af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor Operand.get() == E->getArgument() && 73411af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete == E->getOperatorDelete()) { 73421af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark any declarations we need as referenced. 73431af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: instantiation-specific. 73441af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorDelete) 73455f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); 73464a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 73475833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor if (!E->getArgument()->isTypeDependent()) { 73485833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor QualType Destroyed = SemaRef.Context.getBaseElementType( 73495833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor E->getDestroyedType()); 73505833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { 73515833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); 73524a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier SemaRef.MarkFunctionReferenced(E->getLocStart(), 73535f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.LookupDestructor(Record)); 73545833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor } 73555833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor } 73564a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 73573fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 73581af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 73591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7360b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), 7361b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isGlobalDelete(), 7362b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrayForm(), 73639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Operand.get()); 7364b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 73651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7366b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 736760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7368a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas GregorTreeTransform<Derived>::TransformCXXPseudoDestructorExpr( 7369454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXPseudoDestructorExpr *E) { 737060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 7371a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor if (Base.isInvalid()) 7372f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 73731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7374b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectTypePtr; 7375a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor bool MayBePseudoDestructor = false; 73764a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), 7377a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getOperatorLoc(), 7378a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->isArrow()? tok::arrow : tok::period, 7379a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor ObjectTypePtr, 7380a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor MayBePseudoDestructor); 7381a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (Base.isInvalid()) 7382f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 73834a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 7384b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall QualType ObjectType = ObjectTypePtr.get(); 7385f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); 7386f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor if (QualifierLoc) { 7387f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor QualifierLoc 7388f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); 7389f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor if (!QualifierLoc) 739043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return ExprError(); 739143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } 7392f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor CXXScopeSpec SS; 7393f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SS.Adopt(QualifierLoc); 73941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7395a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed; 7396a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (E->getDestroyedTypeInfo()) { 7397a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor TypeSourceInfo *DestroyedTypeInfo 739843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), 7399b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor ObjectType, 0, SS); 7400a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (!DestroyedTypeInfo) 7401f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7402a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed = DestroyedTypeInfo; 74036b18e740495b67b439fa366367242110365cc4d9Douglas Gregor } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { 7404a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // We aren't likely to be able to resolve the identifier down to a type 7405a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // now anyway, so just retain the identifier. 7406a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), 7407a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc()); 7408a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } else { 7409a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // Look for a destructor known with the given name. 7410b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), 7411a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor *E->getDestroyedTypeIdentifier(), 7412a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc(), 7413a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /*Scope=*/0, 7414a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor SS, ObjectTypePtr, 7415a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor false); 7416a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (!T) 7417f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 74184a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 7419a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed 7420a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), 7421a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc()); 7422a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 742326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor 742426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor TypeSourceInfo *ScopeTypeInfo = 0; 742526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor if (E->getScopeTypeInfo()) { 742643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo()); 742726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor if (!ScopeTypeInfo) 7428f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7429a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor } 74304a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 74319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), 7432a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor E->getOperatorLoc(), 7433a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor E->isArrow(), 7434f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SS, 743526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor ScopeTypeInfo, 743626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor E->getColonColonLoc(), 7437fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor E->getTildeLoc(), 7438a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed); 7439a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor} 74401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7441a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregortemplate<typename Derived> 744260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7443ba13543329afac4a0d01304ec2ec4924d99306a6John McCallTreeTransform<Derived>::TransformUnresolvedLookupExpr( 7444454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall UnresolvedLookupExpr *Old) { 7445f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), 7446f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall Sema::LookupOrdinaryName); 7447f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7448f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Transform all the decls. 7449f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), 7450f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall E = Old->decls_end(); I != E; ++I) { 74517c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor NamedDecl *InstD = static_cast<NamedDecl*>( 74527c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(Old->getNameLoc(), 74537c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor *I)); 74549f54ad4381370c6b771424b53d219e661d6d6706John McCall if (!InstD) { 74559f54ad4381370c6b771424b53d219e661d6d6706John McCall // Silently ignore these if a UsingShadowDecl instantiated to nothing. 74569f54ad4381370c6b771424b53d219e661d6d6706John McCall // This can happen because of dependent hiding. 74579f54ad4381370c6b771424b53d219e661d6d6706John McCall if (isa<UsingShadowDecl>(*I)) 74589f54ad4381370c6b771424b53d219e661d6d6706John McCall continue; 74599f54ad4381370c6b771424b53d219e661d6d6706John McCall else 7460f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 74619f54ad4381370c6b771424b53d219e661d6d6706John McCall } 7462f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7463f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Expand using declarations. 7464f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (isa<UsingDecl>(InstD)) { 7465f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall UsingDecl *UD = cast<UsingDecl>(InstD); 7466f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall for (UsingDecl::shadow_iterator I = UD->shadow_begin(), 7467f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall E = UD->shadow_end(); I != E; ++I) 7468f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.addDecl(*I); 7469f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall continue; 7470f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 7471f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7472f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.addDecl(InstD); 7473f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 7474f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7475f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Resolve a kind, but don't do any further analysis. If it's 7476f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // ambiguous, the callee needs to deal with it. 7477f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.resolveKind(); 7478f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7479f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Rebuild the nested-name qualifier, if present. 7480f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall CXXScopeSpec SS; 74814c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (Old->getQualifierLoc()) { 74824c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc 74834c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); 74844c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (!QualifierLoc) 7485f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 74864a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 74874c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor SS.Adopt(QualifierLoc); 74884a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier } 74894a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 7490c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor if (Old->getNamingClass()) { 749166c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor CXXRecordDecl *NamingClass 749266c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( 749366c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNameLoc(), 749466c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNamingClass())); 749566c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor if (!NamingClass) 7496f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 74974a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 749866c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor R.setNamingClass(NamingClass); 7499f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 7500f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7501e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); 7502e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 75039d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara // If we have neither explicit template arguments, nor the template keyword, 75049d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara // it's a normal declaration name. 75059d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) 7506f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); 7507f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7508f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // If we have template arguments, rebuild them, then rebuild the 7509f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // templateid expression. 7510f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); 7511fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), 7512fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor Old->getNumTemplateArgs(), 7513fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7514fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 7515f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7516e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, 75179d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara Old->requiresADL(), &TransArgs); 7518b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 75191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7520b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 752160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7522454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { 75233d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); 75243d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor if (!T) 7525f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 75261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7527b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 75283d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor T == E->getQueriedTypeSourceInfo()) 75293fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 75301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 75311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildUnaryTypeTrait(E->getTrait(), 7532b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocStart(), 7533b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T, 7534b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 7535b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 75361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7537b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 753860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 75396ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetTreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { 75406ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); 75416ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!LhsT) 75426ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return ExprError(); 75436ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 75446ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); 75456ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!RhsT) 75466ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return ExprError(); 75476ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 75486ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!getDerived().AlwaysRebuild() && 75496ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) 75506ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return SemaRef.Owned(E); 75516ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 75526ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return getDerived().RebuildBinaryTypeTrait(E->getTrait(), 75536ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet E->getLocStart(), 75546ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet LhsT, RhsT, 75556ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet E->getLocEnd()); 75566ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet} 75576ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 75586ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichettemplate<typename Derived> 75596ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetExprResult 75604ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas GregorTreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { 75614ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor bool ArgChanged = false; 75624ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor llvm::SmallVector<TypeSourceInfo *, 4> Args; 75634ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { 75644ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeSourceInfo *From = E->getArg(I); 75654ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeLoc FromTL = From->getTypeLoc(); 75664ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (!isa<PackExpansionTypeLoc>(FromTL)) { 75674ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeLocBuilder TLB; 75684ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TLB.reserve(FromTL.getFullDataSize()); 75694ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor QualType To = getDerived().TransformType(TLB, FromTL); 75704ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (To.isNull()) 75714ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return ExprError(); 75724a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 75734ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (To == From->getType()) 75744ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Args.push_back(From); 75754ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor else { 75764ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); 75774ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ArgChanged = true; 75784ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 75794ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor continue; 75804ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 75814a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 75824ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ArgChanged = true; 75834a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 75844ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // We have a pack expansion. Instantiate it. 75854a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL); 75864ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeLoc PatternTL = ExpansionTL.getPatternLoc(); 75874ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor SmallVector<UnexpandedParameterPack, 2> Unexpanded; 75884ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); 75894a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 75904ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // Determine whether the set of unexpanded parameter packs can and should 75914ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // be expanded. 75924ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor bool Expand = true; 75934ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor bool RetainExpansion = false; 75944ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor llvm::Optional<unsigned> OrigNumExpansions 75954ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor = ExpansionTL.getTypePtr()->getNumExpansions(); 75964ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; 75974ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), 75984ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor PatternTL.getSourceRange(), 75994ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Unexpanded, 76004ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Expand, RetainExpansion, 76014ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor NumExpansions)) 76024ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return ExprError(); 76034a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 76044ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (!Expand) { 76054ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // The transform has determined that we should perform a simple 76064a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier // transformation on the pack expansion, producing another pack 76074ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // expansion. 76084ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 76094a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 76104ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeLocBuilder TLB; 76114ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TLB.reserve(From->getTypeLoc().getFullDataSize()); 76124ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76134ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor QualType To = getDerived().TransformType(TLB, PatternTL); 76144ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (To.isNull()) 76154ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return ExprError(); 76164ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76174a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier To = getDerived().RebuildPackExpansionType(To, 76184ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor PatternTL.getSourceRange(), 76194ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ExpansionTL.getEllipsisLoc(), 76204ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor NumExpansions); 76214ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (To.isNull()) 76224ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return ExprError(); 76234a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 76244ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor PackExpansionTypeLoc ToExpansionTL 76254ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor = TLB.push<PackExpansionTypeLoc>(To); 76264ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); 76274ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); 76284ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor continue; 76294ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 76304ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76314ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // Expand the pack expansion by substituting for each argument in the 76324ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // pack(s). 76334ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 76344ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); 76354ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeLocBuilder TLB; 76364ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TLB.reserve(PatternTL.getFullDataSize()); 76374ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor QualType To = getDerived().TransformType(TLB, PatternTL); 76384ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (To.isNull()) 76394ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return ExprError(); 76404ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76414ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); 76424ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 76434a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 76444ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (!RetainExpansion) 76454ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor continue; 76464a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 76474ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 76484ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // forgetting the partially-substituted parameter pack. 76494ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 76504ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76514ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeLocBuilder TLB; 76524ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TLB.reserve(From->getTypeLoc().getFullDataSize()); 76534a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 76544ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor QualType To = getDerived().TransformType(TLB, PatternTL); 76554ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (To.isNull()) 76564ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return ExprError(); 76574a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 76584a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier To = getDerived().RebuildPackExpansionType(To, 76594ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor PatternTL.getSourceRange(), 76604ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ExpansionTL.getEllipsisLoc(), 76614ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor NumExpansions); 76624ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (To.isNull()) 76634ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return ExprError(); 76644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 76654ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor PackExpansionTypeLoc ToExpansionTL 76664ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor = TLB.push<PackExpansionTypeLoc>(To); 76674ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); 76684ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); 76694ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 76704a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 76714ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (!getDerived().AlwaysRebuild() && !ArgChanged) 76724ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return SemaRef.Owned(E); 76734ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76744ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return getDerived().RebuildTypeTrait(E->getTrait(), 76754ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor E->getLocStart(), 76764ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Args, 76774ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor E->getLocEnd()); 76784ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor} 76794ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76804ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregortemplate<typename Derived> 76814ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas GregorExprResult 768221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John WiegleyTreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { 768321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); 768421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (!T) 768521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return ExprError(); 768621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 768721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (!getDerived().AlwaysRebuild() && 768821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley T == E->getQueriedTypeSourceInfo()) 768921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return SemaRef.Owned(E); 769021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 769121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ExprResult SubExpr; 769221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley { 769321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 769421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); 769521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (SubExpr.isInvalid()) 769621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return ExprError(); 769721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 769821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) 769921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return SemaRef.Owned(E); 770021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 770121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 770221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return getDerived().RebuildArrayTypeTrait(E->getTrait(), 770321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley E->getLocStart(), 770421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley T, 770521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SubExpr.get(), 770621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley E->getLocEnd()); 770721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley} 770821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 770921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleytemplate<typename Derived> 771021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John WiegleyExprResult 7711552622067dc45013d240f73952fece703f5e63bdJohn WiegleyTreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { 7712552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExprResult SubExpr; 7713552622067dc45013d240f73952fece703f5e63bdJohn Wiegley { 7714552622067dc45013d240f73952fece703f5e63bdJohn Wiegley EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 7715552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); 7716552622067dc45013d240f73952fece703f5e63bdJohn Wiegley if (SubExpr.isInvalid()) 7717552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return ExprError(); 7718552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 7719552622067dc45013d240f73952fece703f5e63bdJohn Wiegley if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) 7720552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return SemaRef.Owned(E); 7721552622067dc45013d240f73952fece703f5e63bdJohn Wiegley } 7722552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 7723552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return getDerived().RebuildExpressionTrait( 7724552622067dc45013d240f73952fece703f5e63bdJohn Wiegley E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); 7725552622067dc45013d240f73952fece703f5e63bdJohn Wiegley} 7726552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 7727552622067dc45013d240f73952fece703f5e63bdJohn Wiegleytemplate<typename Derived> 7728552622067dc45013d240f73952fece703f5e63bdJohn WiegleyExprResult 7729865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformDependentScopeDeclRefExpr( 77302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DependentScopeDeclRefExpr *E) { 773100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc 773200cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 773300cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor if (!QualifierLoc) 7734f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7735e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); 77361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 773743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // TODO: If this is a conversion-function-id, verify that the 773843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // destination type name (if present) resolves the same way after 773943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // instantiation as it did in the local scope. 774043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 77412577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo 77422577743c5650c646fb705df01403707e94f2df04Abramo Bagnara = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); 77432577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!NameInfo.getName()) 7744f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 77451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7746f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!E->hasExplicitTemplateArgs()) { 7747f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!getDerived().AlwaysRebuild() && 774800cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor QualifierLoc == E->getQualifierLoc() && 77492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // Note: it is sufficient to compare the Name component of NameInfo: 77502577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // if name has not changed, DNLoc has not changed either. 77512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getDeclName()) 77523fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 77531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 775400cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, 7755e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateKWLoc, 77562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7757f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /*TemplateArgs*/ 0); 7758f17bb74e74aca9bb0525d2249041ab65c7d1fd48Douglas Gregor } 7759d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 7760d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); 7761fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 7762fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 7763fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7764fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 7765b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 776600cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, 7767e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateKWLoc, 77682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7769f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall &TransArgs); 7770b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7771b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7772b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 777360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7774454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { 7775321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor // CXXConstructExprs are always implicit, so when we have a 7776321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor // 1-argument construction we just transform that argument. 7777321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor if (E->getNumArgs() == 1 || 7778321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) 7779321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor return getDerived().TransformExpr(E->getArg(0)); 7780321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor 7781b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); 7782b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7783b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor QualType T = getDerived().TransformType(E->getType()); 7784b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (T.isNull()) 7785f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7786b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7787b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXConstructorDecl *Constructor 7788b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = cast_or_null<CXXConstructorDecl>( 77897c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 77907c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 7791b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Constructor) 7792f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 77931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7794b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 77954e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer SmallVector<Expr*, 8> Args; 77964a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 7797aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 7798aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 77994a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 7800b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7801b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T == E->getType() && 7802b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Constructor == E->getConstructor() && 7803c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor !ArgumentChanged) { 78041af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark the constructor as referenced. 78051af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: Instantiation-specific 78065f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); 78073fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7808c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor } 78091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 78104411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), 78114411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor Constructor, E->isElidable(), 78123fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer Args, 78137cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara E->hadMultipleCandidates(), 78148c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor E->requiresZeroInitialization(), 7815428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth E->getConstructionKind(), 7816428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth E->getParenRange()); 7817b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 78181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7819b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform a C++ temporary-binding expression. 7820b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 78215132655e4296b780672e9a96b46a740135073534Douglas Gregor/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just 78225132655e4296b780672e9a96b46a740135073534Douglas Gregor/// transform the subexpression and return that. 7823b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 782460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7825454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { 78265132655e4296b780672e9a96b46a740135073534Douglas Gregor return getDerived().TransformExpr(E->getSubExpr()); 7827b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 78281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 78294765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// \brief Transform a C++ expression that contains cleanups that should 78304765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// be run after the expression is evaluated. 7831b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 78324765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Since ExprWithCleanups nodes are implicitly generated, we 78335132655e4296b780672e9a96b46a740135073534Douglas Gregor/// just transform the subexpression and return that. 7834b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 783560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 78364765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallTreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { 78375132655e4296b780672e9a96b46a740135073534Douglas Gregor return getDerived().TransformExpr(E->getSubExpr()); 7838b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 78391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7840b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 784160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7842b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXTemporaryObjectExpr( 7843ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXTemporaryObjectExpr *E) { 7844ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 7845ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 7846f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 78471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7848b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXConstructorDecl *Constructor 7849b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = cast_or_null<CXXConstructorDecl>( 78504a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier getDerived().TransformDecl(E->getLocStart(), 78517c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 7852b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Constructor) 7853f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 78541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7855b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 78564e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer SmallVector<Expr*, 8> Args; 7857b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Args.reserve(E->getNumArgs()); 78584a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 7859aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 7860aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 78611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7862b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7863ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo() && 7864b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Constructor == E->getConstructor() && 786591be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor !ArgumentChanged) { 786691be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor // FIXME: Instantiation-specific 78675f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); 78683fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.MaybeBindToTemporary(E); 786991be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor } 78704a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 7871ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXTemporaryObjectExpr(T, 7872ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /*FIXME:*/T->getTypeLoc().getEndLoc(), 78733fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer Args, 7874b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 7875b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 78761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7877b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 787860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 787901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas GregorTreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { 7880dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // Create the local class that will describe the lambda. 7881dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor CXXRecordDecl *Class 7882f54486acc1cadf2791c3916ece66fded1e57ba0bDouglas Gregor = getSema().createLambdaClosureType(E->getIntroducerRange(), 7883f54486acc1cadf2791c3916ece66fded1e57ba0bDouglas Gregor /*KnownDependent=*/false); 7884dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor getDerived().transformedLocalDecl(E->getLambdaClass(), Class); 78854a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 7886dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // Transform the type of the lambda parameters and start the definition of 7887dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // the lambda itself. 7888dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor TypeSourceInfo *MethodTy 78894a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier = TransformType(E->getCallOperator()->getTypeSourceInfo()); 7890dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor if (!MethodTy) 7891dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor return ExprError(); 7892dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 7893c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor // Transform lambda parameters. 7894c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor llvm::SmallVector<QualType, 4> ParamTypes; 7895c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor llvm::SmallVector<ParmVarDecl *, 4> Params; 7896c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor if (getDerived().TransformFunctionTypeParams(E->getLocStart(), 7897c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor E->getCallOperator()->param_begin(), 7898c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor E->getCallOperator()->param_size(), 7899c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor 0, ParamTypes, &Params)) 7900612409ece080e814f79e06772c690d603f45fbd6Richard Smith return ExprError(); 7901c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor 7902dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // Build the call operator. 7903dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor CXXMethodDecl *CallOperator 7904dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor = getSema().startLambdaDefinition(Class, E->getIntroducerRange(), 7905adb1d4c18ee83249d4cffc99ef902f98e846092aRichard Smith MethodTy, 7906c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor E->getCallOperator()->getLocEnd(), 7907adb1d4c18ee83249d4cffc99ef902f98e846092aRichard Smith Params); 7908dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor getDerived().transformAttrs(E->getCallOperator(), CallOperator); 7909d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor 7910612409ece080e814f79e06772c690d603f45fbd6Richard Smith return getDerived().TransformLambdaScope(E, CallOperator); 7911612409ece080e814f79e06772c690d603f45fbd6Richard Smith} 7912612409ece080e814f79e06772c690d603f45fbd6Richard Smith 7913612409ece080e814f79e06772c690d603f45fbd6Richard Smithtemplate<typename Derived> 7914612409ece080e814f79e06772c690d603f45fbd6Richard SmithExprResult 7915612409ece080e814f79e06772c690d603f45fbd6Richard SmithTreeTransform<Derived>::TransformLambdaScope(LambdaExpr *E, 7916612409ece080e814f79e06772c690d603f45fbd6Richard Smith CXXMethodDecl *CallOperator) { 7917d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor // Introduce the context of the call operator. 7918d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor Sema::ContextRAII SavedContext(getSema(), CallOperator); 7919d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor 7920dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // Enter the scope of the lambda. 7921dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor sema::LambdaScopeInfo *LSI 7922dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(), 7923dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor E->getCaptureDefault(), 7924dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor E->hasExplicitParameters(), 7925dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor E->hasExplicitResultType(), 7926dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor E->isMutable()); 79274a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 7928dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // Transform captures. 7929612409ece080e814f79e06772c690d603f45fbd6Richard Smith bool Invalid = false; 7930dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor bool FinishedExplicitCaptures = false; 79314a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier for (LambdaExpr::capture_iterator C = E->capture_begin(), 7932dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor CEnd = E->capture_end(); 7933dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor C != CEnd; ++C) { 7934dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // When we hit the first implicit capture, tell Sema that we've finished 7935dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // the list of explicit captures. 7936dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor if (!FinishedExplicitCaptures && C->isImplicit()) { 7937dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor getSema().finishLambdaExplicitCaptures(LSI); 7938dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor FinishedExplicitCaptures = true; 7939dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor } 79404a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 7941dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // Capturing 'this' is trivial. 7942dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor if (C->capturesThis()) { 7943dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit()); 7944dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor continue; 7945dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor } 79464a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 7947a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor // Determine the capture kind for Sema. 7948a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor Sema::TryCaptureKind Kind 7949a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor = C->isImplicit()? Sema::TryCapture_Implicit 7950a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor : C->getCaptureKind() == LCK_ByCopy 7951a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor ? Sema::TryCapture_ExplicitByVal 7952a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor : Sema::TryCapture_ExplicitByRef; 7953a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor SourceLocation EllipsisLoc; 7954a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor if (C->isPackExpansion()) { 7955a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); 7956a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor bool ShouldExpand = false; 7957a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor bool RetainExpansion = false; 7958a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor llvm::Optional<unsigned> NumExpansions; 79594a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), 79604a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier C->getLocation(), 7961a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor Unexpanded, 7962a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor ShouldExpand, RetainExpansion, 7963a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor NumExpansions)) 7964a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor return ExprError(); 79654a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 7966a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor if (ShouldExpand) { 7967a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor // The transform has determined that we should perform an expansion; 7968a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor // transform and capture each of the arguments. 7969a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor // expansion of the pattern. Do so. 7970a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor VarDecl *Pack = C->getCapturedVar(); 7971a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 7972a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 7973a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor VarDecl *CapturedVar 79744a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), 7975a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor Pack)); 7976a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor if (!CapturedVar) { 7977a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor Invalid = true; 7978a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor continue; 7979a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor } 79804a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 7981a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor // Capture the transformed variable. 79824a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); 79834a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier } 7984a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor continue; 7985a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor } 79864a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 7987a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor EllipsisLoc = C->getEllipsisLoc(); 7988a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor } 79894a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 7990dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // Transform the captured variable. 7991dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor VarDecl *CapturedVar 79924a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), 7993dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor C->getCapturedVar())); 7994dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor if (!CapturedVar) { 7995dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor Invalid = true; 7996dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor continue; 7997dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor } 79984a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 7999dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // Capture the transformed variable. 8000999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); 8001dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor } 8002dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor if (!FinishedExplicitCaptures) 8003dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor getSema().finishLambdaExplicitCaptures(LSI); 8004dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 8005dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 8006dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // Enter a new evaluation context to insulate the lambda from any 8007dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // cleanups from the enclosing full-expression. 80084a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated); 8009dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 8010dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor if (Invalid) { 80114a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0, 8012dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /*IsInstantiation=*/true); 8013dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor return ExprError(); 8014dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor } 8015dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 8016dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // Instantiate the body of the lambda expression. 8017d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor StmtResult Body = getDerived().TransformStmt(E->getBody()); 8018d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor if (Body.isInvalid()) { 80194a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0, 8020d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor /*IsInstantiation=*/true); 80214a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return ExprError(); 8022d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor } 8023ccc1b5eebc6ca8a904c58c0468b9a71483b7c7cfDouglas Gregor 80244a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(), 8025f54486acc1cadf2791c3916ece66fded1e57ba0bDouglas Gregor /*CurScope=*/0, /*IsInstantiation=*/true); 802601d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor} 802701d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 802801d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregortemplate<typename Derived> 802901d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas GregorExprResult 8030b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( 8031454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXUnresolvedConstructExpr *E) { 8032ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 8033ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 8034f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 80351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8036b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 80374e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer SmallVector<Expr*, 8> Args; 8038aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args.reserve(E->arg_size()); 80394a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, 8040aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 8041aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 80424a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8043b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 8044ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo() && 8045b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgumentChanged) 80463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 80471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8048b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: we're faking the locations of the commas 8049ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXUnresolvedConstructExpr(T, 8050b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLParenLoc(), 80513fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer Args, 8052b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 8053b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 80541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8055b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 805660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8057865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( 80582577743c5650c646fb705df01403707e94f2df04Abramo Bagnara CXXDependentScopeMemberExpr *E) { 8059b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the base of the expression. 806060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base((Expr*) 0); 8061aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *OldBase; 8062aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType; 8063aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType ObjectType; 8064aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!E->isImplicitAccess()) { 8065aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OldBase = E->getBase(); 8066aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base = getDerived().TransformExpr(OldBase); 8067aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 8068f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 80691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8070aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall // Start the member reference and compute the object's type. 8071b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectTy; 8072d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor bool MayBePseudoDestructor = false; 80739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), 8074aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall E->getOperatorLoc(), 8075a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor E->isArrow()? tok::arrow : tok::period, 8076d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor ObjectTy, 8077d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor MayBePseudoDestructor); 8078aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 8079f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8080aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 8081b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ObjectType = ObjectTy.get(); 8082aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = ((Expr*) Base.get())->getType(); 8083aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } else { 8084aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OldBase = 0; 8085aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = getDerived().TransformType(E->getBaseType()); 8086aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); 8087aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 80881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 80896cd219879ffce00920189ec1dcea927a42602961Douglas Gregor // Transform the first part of the nested-name-specifier that qualifies 80906cd219879ffce00920189ec1dcea927a42602961Douglas Gregor // the member name. 8091c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor NamedDecl *FirstQualifierInScope 80926cd219879ffce00920189ec1dcea927a42602961Douglas Gregor = getDerived().TransformFirstQualifierInScope( 80937c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor E->getFirstQualifierFoundInScope(), 80947c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor E->getQualifierLoc().getBeginLoc()); 80951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 80967c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 8097a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor if (E->getQualifier()) { 80987c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc 80997c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), 81007c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor ObjectType, 81017c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor FirstQualifierInScope); 81027c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor if (!QualifierLoc) 8103f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8104a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor } 81051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8106e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); 8107e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 810843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // TODO: If this is a conversion-function-id, verify that the 810943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // destination type name (if present) resolves the same way after 811043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // instantiation as it did in the local scope. 811143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 81122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo 811343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); 81142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!NameInfo.getName()) 8115f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 81161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8117aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!E->hasExplicitTemplateArgs()) { 81183b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor // This is a reference to a member without an explicitly-specified 81193b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor // template argument list. Optimize for this common case. 81203b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor if (!getDerived().AlwaysRebuild() && 8121aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base.get() == OldBase && 8122aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType == E->getBaseType() && 81237c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc == E->getQualifierLoc() && 81242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getMember() && 81253b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor FirstQualifierInScope == E->getFirstQualifierFoundInScope()) 81263fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 81271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 81289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), 8129aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 81303b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor E->isArrow(), 81313b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor E->getOperatorLoc(), 81327c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc, 8133e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateKWLoc, 8134129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall FirstQualifierInScope, 81352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 8136129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /*TemplateArgs*/ 0); 81373b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 81383b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor 8139d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); 8140fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 8141fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 8142fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 8143fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 81441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 81459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), 8146aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 8147b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrow(), 8148b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOperatorLoc(), 81497c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc, 8150e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateKWLoc, 81513b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor FirstQualifierInScope, 81522577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 8153129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall &TransArgs); 8154129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall} 8155129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 8156129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCalltemplate<typename Derived> 815760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8158454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { 8159129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Transform the base of the expression. 816060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base((Expr*) 0); 8161aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType; 8162aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!Old->isImplicitAccess()) { 8163aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base = getDerived().TransformExpr(Old->getBase()); 8164aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 8165f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 81669138b4e96429cbaae00c52c15c960f72b6645088Richard Smith Base = getSema().PerformMemberExprBaseConversion(Base.take(), 81679138b4e96429cbaae00c52c15c960f72b6645088Richard Smith Old->isArrow()); 81689138b4e96429cbaae00c52c15c960f72b6645088Richard Smith if (Base.isInvalid()) 81699138b4e96429cbaae00c52c15c960f72b6645088Richard Smith return ExprError(); 81709138b4e96429cbaae00c52c15c960f72b6645088Richard Smith BaseType = Base.get()->getType(); 8171aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } else { 8172aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = getDerived().TransformType(Old->getBaseType()); 8173aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 8174129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 81754c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 81764c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (Old->getQualifierLoc()) { 81774c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor QualifierLoc 81784c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); 81794c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (!QualifierLoc) 8180f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8181129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 8182129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 8183e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); 8184e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 81852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LookupResult R(SemaRef, Old->getMemberNameInfo(), 8186129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Sema::LookupOrdinaryName); 8187129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 8188129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Transform all the decls. 8189129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), 8190129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall E = Old->decls_end(); I != E; ++I) { 81917c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor NamedDecl *InstD = static_cast<NamedDecl*>( 81927c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(Old->getMemberLoc(), 81937c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor *I)); 81949f54ad4381370c6b771424b53d219e661d6d6706John McCall if (!InstD) { 81959f54ad4381370c6b771424b53d219e661d6d6706John McCall // Silently ignore these if a UsingShadowDecl instantiated to nothing. 81969f54ad4381370c6b771424b53d219e661d6d6706John McCall // This can happen because of dependent hiding. 81979f54ad4381370c6b771424b53d219e661d6d6706John McCall if (isa<UsingShadowDecl>(*I)) 81989f54ad4381370c6b771424b53d219e661d6d6706John McCall continue; 819934f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis else { 820034f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis R.clear(); 8201f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 820234f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis } 82039f54ad4381370c6b771424b53d219e661d6d6706John McCall } 8204129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 8205129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Expand using declarations. 8206129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (isa<UsingDecl>(InstD)) { 8207129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall UsingDecl *UD = cast<UsingDecl>(InstD); 8208129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall for (UsingDecl::shadow_iterator I = UD->shadow_begin(), 8209129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall E = UD->shadow_end(); I != E; ++I) 8210129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.addDecl(*I); 8211129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall continue; 8212129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 8213129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 8214129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.addDecl(InstD); 8215129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 8216129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 8217129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.resolveKind(); 8218129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 8219c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor // Determine the naming class. 8220042d6f98ea73d781e43cc17077e8fc84a4201eefChandler Carruth if (Old->getNamingClass()) { 82214a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier CXXRecordDecl *NamingClass 8222c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( 822366c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getMemberLoc(), 822466c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNamingClass())); 822566c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor if (!NamingClass) 8226f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 82274a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 822866c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor R.setNamingClass(NamingClass); 8229c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor } 82304a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8231129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TemplateArgumentListInfo TransArgs; 8232129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (Old->hasExplicitTemplateArgs()) { 8233129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TransArgs.setLAngleLoc(Old->getLAngleLoc()); 8234129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TransArgs.setRAngleLoc(Old->getRAngleLoc()); 8235fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), 8236fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor Old->getNumTemplateArgs(), 8237fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 8238fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 8239129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 8240c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 8241c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // FIXME: to do this check properly, we will need to preserve the 8242c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // first-qualifier-in-scope here, just in case we had a dependent 8243c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // base (and therefore couldn't do the check) and a 8244c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // nested-name-qualifier (and therefore could do the lookup). 8245c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall NamedDecl *FirstQualifierInScope = 0; 82464a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 82479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildUnresolvedMemberExpr(Base.get(), 8248aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 8249129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Old->getOperatorLoc(), 8250129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Old->isArrow(), 82514c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor QualifierLoc, 8252e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateKWLoc, 8253c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall FirstQualifierInScope, 8254129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R, 8255129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall (Old->hasExplicitTemplateArgs() 8256129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall ? &TransArgs : 0)); 8257b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8258b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 8259b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 826060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 82612e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlTreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { 8262eea06c609b73afc7bcfdf3e101efb8d9e7b3560cSean Hunt EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 82632e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); 82642e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl if (SubExpr.isInvalid()) 82652e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return ExprError(); 82662e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 82672e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) 82683fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 82692e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 82702e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); 82712e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl} 82722e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 82732e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redltemplate<typename Derived> 82742e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlExprResult 8275be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorTreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { 82764f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); 82774f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor if (Pattern.isInvalid()) 82784f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor return ExprError(); 82794a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 82804f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) 82814f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor return SemaRef.Owned(E); 82824f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor 828367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), 828467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor E->getNumExpansions()); 8285be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor} 8286ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 8287ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregortemplate<typename Derived> 8288ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorExprResult 8289ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorTreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { 8290ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // If E is not value-dependent, then nothing will change when we transform it. 8291ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // Note: This is an instantiation-centric view. 8292ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor if (!E->isValueDependent()) 8293ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return SemaRef.Owned(E); 8294ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 8295ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // Note: None of the implementations of TryExpandParameterPacks can ever 8296ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // produce a diagnostic when given only a single unexpanded parameter pack, 82974a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier // so 8298ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); 8299ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor bool ShouldExpand = false; 8300d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 8301cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions; 83024a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), 8303a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 8304d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ShouldExpand, RetainExpansion, 8305d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) 8306ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return ExprError(); 83074a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8308089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor if (RetainExpansion) 8309ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return SemaRef.Owned(E); 83104a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8311089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor NamedDecl *Pack = E->getPack(); 8312089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor if (!ShouldExpand) { 83134a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(), 8314089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor Pack)); 8315089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor if (!Pack) 8316089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor return ExprError(); 8317089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor } 8318089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor 83194a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8320ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // We now know the length of the parameter pack, so build a new expression 8321ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // that stores that length. 83224a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, 83234a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier E->getPackLoc(), E->getRParenLoc(), 8324089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor NumExpansions); 8325ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor} 8326ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 8327be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregortemplate<typename Derived> 8328be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorExprResult 8329c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorTreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( 8330c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor SubstNonTypeTemplateParmPackExpr *E) { 8331c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor // Default behavior is to do nothing with this transformation. 833291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return SemaRef.Owned(E); 833391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall} 833491a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 833591a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCalltemplate<typename Derived> 833691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallExprResult 833791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallTreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( 833891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall SubstNonTypeTemplateParmExpr *E) { 833991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall // Default behavior is to do nothing with this transformation. 8340c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor return SemaRef.Owned(E); 8341c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor} 8342c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor 8343c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregortemplate<typename Derived> 8344c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorExprResult 834503e80030515c800d1ab44125b9052dfffd1bd04cDouglas GregorTreeTransform<Derived>::TransformMaterializeTemporaryExpr( 834603e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor MaterializeTemporaryExpr *E) { 834703e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return getDerived().TransformExpr(E->GetTemporaryExpr()); 834803e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor} 83494a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 835003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregortemplate<typename Derived> 835103e80030515c800d1ab44125b9052dfffd1bd04cDouglas GregorExprResult 8352454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { 8353ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return SemaRef.MaybeBindToTemporary(E); 8354ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 8355ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8356ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenektemplate<typename Derived> 8357ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult 8358ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekTreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { 8359d8b5ca14277e142506daed181ecff9151dfae32cJordy Rose return SemaRef.Owned(E); 8360ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 8361ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8362ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenektemplate<typename Derived> 8363ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult 8364eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick BeardTreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { 8365eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 8366eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard if (SubExpr.isInvalid()) 8367eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard return ExprError(); 8368eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard 8369eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard if (!getDerived().AlwaysRebuild() && 8370eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard SubExpr.get() == E->getSubExpr()) 8371eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard return SemaRef.Owned(E); 8372eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard 8373eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); 8374ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 8375ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8376ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenektemplate<typename Derived> 8377ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult 8378ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekTreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { 8379ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Transform each of the elements. 8380ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek llvm::SmallVector<Expr *, 8> Elements; 8381ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool ArgChanged = false; 83824a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), 8383ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /*IsCall=*/false, Elements, &ArgChanged)) 8384ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(); 83854a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8386ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (!getDerived().AlwaysRebuild() && !ArgChanged) 8387ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return SemaRef.MaybeBindToTemporary(E); 83884a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8389ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), 8390ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Elements.data(), 8391ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Elements.size()); 8392ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 8393ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8394ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenektemplate<typename Derived> 8395ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult 8396ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekTreeTransform<Derived>::TransformObjCDictionaryLiteral( 83974a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ObjCDictionaryLiteral *E) { 8398ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Transform each of the elements. 8399ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek llvm::SmallVector<ObjCDictionaryElement, 8> Elements; 8400ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool ArgChanged = false; 8401ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { 8402ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); 84034a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8404ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (OrigElement.isPackExpansion()) { 8405ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // This key/value element is a pack expansion. 8406ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SmallVector<UnexpandedParameterPack, 2> Unexpanded; 8407ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); 8408ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); 8409ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 8410ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8411ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Determine whether the set of unexpanded parameter packs can 8412ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // and should be expanded. 8413ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool Expand = true; 8414ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool RetainExpansion = false; 8415ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions; 8416ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; 8417ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange PatternRange(OrigElement.Key->getLocStart(), 8418ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek OrigElement.Value->getLocEnd()); 8419ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc, 8420ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek PatternRange, 8421ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Unexpanded, 8422ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expand, RetainExpansion, 8423ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek NumExpansions)) 8424ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(); 8425ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8426ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (!Expand) { 8427ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // The transform has determined that we should perform a simple 84284a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier // transformation on the pack expansion, producing another pack 8429ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // expansion. 8430ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 8431ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult Key = getDerived().TransformExpr(OrigElement.Key); 8432ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Key.isInvalid()) 8433ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(); 8434ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8435ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Key.get() != OrigElement.Key) 8436ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ArgChanged = true; 8437ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8438ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult Value = getDerived().TransformExpr(OrigElement.Value); 8439ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Value.isInvalid()) 8440ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(); 84414a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8442ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Value.get() != OrigElement.Value) 8443ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ArgChanged = true; 8444ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 84454a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ObjCDictionaryElement Expansion = { 8446ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions 8447ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek }; 8448ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Elements.push_back(Expansion); 8449ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek continue; 8450ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 8451ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8452ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Record right away that the argument was changed. This needs 8453ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // to happen even if the array expands to nothing. 8454ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ArgChanged = true; 84554a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8456ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // The transform has determined that we should perform an elementwise 8457ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // expansion of the pattern. Do so. 8458ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek for (unsigned I = 0; I != *NumExpansions; ++I) { 8459ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 8460ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult Key = getDerived().TransformExpr(OrigElement.Key); 8461ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Key.isInvalid()) 8462ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(); 8463ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8464ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult Value = getDerived().TransformExpr(OrigElement.Value); 8465ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Value.isInvalid()) 8466ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(); 8467ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 84684a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ObjCDictionaryElement Element = { 8469ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Key.get(), Value.get(), SourceLocation(), NumExpansions 8470ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek }; 8471ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8472ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // If any unexpanded parameter packs remain, we still have a 8473ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // pack expansion. 8474ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Key.get()->containsUnexpandedParameterPack() || 8475ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Value.get()->containsUnexpandedParameterPack()) 8476ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Element.EllipsisLoc = OrigElement.EllipsisLoc; 84774a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8478ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Elements.push_back(Element); 8479ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 8480ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8481ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // We've finished with this pack expansion. 8482ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek continue; 8483ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 8484ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8485ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Transform and check key. 8486ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult Key = getDerived().TransformExpr(OrigElement.Key); 8487ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Key.isInvalid()) 8488ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(); 84894a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8490ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Key.get() != OrigElement.Key) 8491ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ArgChanged = true; 84924a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8493ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Transform and check value. 8494ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult Value 8495ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek = getDerived().TransformExpr(OrigElement.Value); 8496ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Value.isInvalid()) 8497ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(); 84984a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8499ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Value.get() != OrigElement.Value) 8500ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ArgChanged = true; 85014a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 85024a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier ObjCDictionaryElement Element = { 8503ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>() 8504ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek }; 8505ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Elements.push_back(Element); 8506ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 85074a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8508ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (!getDerived().AlwaysRebuild() && !ArgChanged) 8509ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return SemaRef.MaybeBindToTemporary(E); 8510ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8511ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), 8512ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Elements.data(), 8513ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Elements.size()); 8514b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8515b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 85161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 851760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8518454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { 851981d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *EncodedTypeInfo 852081d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor = getDerived().TransformType(E->getEncodedTypeSourceInfo()); 852181d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor if (!EncodedTypeInfo) 8522f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 85231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8524b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 852581d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedTypeInfo == E->getEncodedTypeSourceInfo()) 85263fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8527b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 8528b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), 852981d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedTypeInfo, 8530b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 8531b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 85321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8533b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 8534f85e193739c953358c865005855253af4f68a497John McCallExprResult TreeTransform<Derived>:: 8535f85e193739c953358c865005855253af4f68a497John McCallTransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { 8536f85e193739c953358c865005855253af4f68a497John McCall ExprResult result = getDerived().TransformExpr(E->getSubExpr()); 8537f85e193739c953358c865005855253af4f68a497John McCall if (result.isInvalid()) return ExprError(); 8538f85e193739c953358c865005855253af4f68a497John McCall Expr *subExpr = result.take(); 8539f85e193739c953358c865005855253af4f68a497John McCall 8540f85e193739c953358c865005855253af4f68a497John McCall if (!getDerived().AlwaysRebuild() && 8541f85e193739c953358c865005855253af4f68a497John McCall subExpr == E->getSubExpr()) 8542f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(E); 8543f85e193739c953358c865005855253af4f68a497John McCall 8544f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(new(SemaRef.Context) 8545f85e193739c953358c865005855253af4f68a497John McCall ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy())); 8546f85e193739c953358c865005855253af4f68a497John McCall} 8547f85e193739c953358c865005855253af4f68a497John McCall 8548f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived> 8549f85e193739c953358c865005855253af4f68a497John McCallExprResult TreeTransform<Derived>:: 8550f85e193739c953358c865005855253af4f68a497John McCallTransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { 85514a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier TypeSourceInfo *TSInfo 8552f85e193739c953358c865005855253af4f68a497John McCall = getDerived().TransformType(E->getTypeInfoAsWritten()); 8553f85e193739c953358c865005855253af4f68a497John McCall if (!TSInfo) 8554f85e193739c953358c865005855253af4f68a497John McCall return ExprError(); 85554a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8556f85e193739c953358c865005855253af4f68a497John McCall ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); 85574a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (Result.isInvalid()) 8558f85e193739c953358c865005855253af4f68a497John McCall return ExprError(); 85594a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8560f85e193739c953358c865005855253af4f68a497John McCall if (!getDerived().AlwaysRebuild() && 8561f85e193739c953358c865005855253af4f68a497John McCall TSInfo == E->getTypeInfoAsWritten() && 8562f85e193739c953358c865005855253af4f68a497John McCall Result.get() == E->getSubExpr()) 8563f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(E); 85644a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8565f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), 85664a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier E->getBridgeKeywordLoc(), TSInfo, 8567f85e193739c953358c865005855253af4f68a497John McCall Result.get()); 8568f85e193739c953358c865005855253af4f68a497John McCall} 8569f85e193739c953358c865005855253af4f68a497John McCall 8570f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived> 857160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8572454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { 857392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Transform arguments. 857492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor bool ArgChanged = false; 85754e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer SmallVector<Expr*, 8> Args; 8576aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args.reserve(E->getNumArgs()); 85774a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, 8578aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgChanged)) 8579aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 85804a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 858192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (E->getReceiverKind() == ObjCMessageExpr::Class) { 858292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Class message: transform the receiver type. 858392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor TypeSourceInfo *ReceiverTypeInfo 858492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor = getDerived().TransformType(E->getClassReceiverTypeInfo()); 858592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!ReceiverTypeInfo) 8586f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 85874a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 858892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // If nothing changed, just retain the existing message send. 858992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!getDerived().AlwaysRebuild() && 859092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) 859192be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 859292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 859392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Build a new class message send. 8594207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SmallVector<SourceLocation, 16> SelLocs; 8595207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis E->getSelectorLocs(SelLocs); 859692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, 859792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getSelector(), 8598207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocs, 859992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getMethodDecl(), 860092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getLeftLoc(), 86013fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer Args, 860292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getRightLoc()); 860392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 860492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 860592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Instance message: transform the receiver 860692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor assert(E->getReceiverKind() == ObjCMessageExpr::Instance && 860792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor "Only class and instance messages may be instantiated"); 860860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Receiver 860992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor = getDerived().TransformExpr(E->getInstanceReceiver()); 861092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (Receiver.isInvalid()) 8611f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 861292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 861392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // If nothing changed, just retain the existing message send. 861492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!getDerived().AlwaysRebuild() && 861592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Receiver.get() == E->getInstanceReceiver() && !ArgChanged) 861692be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 86174a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 861892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Build a new instance message send. 8619207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SmallVector<SourceLocation, 16> SelLocs; 8620207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis E->getSelectorLocs(SelLocs); 86219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCMessageExpr(Receiver.get(), 862292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getSelector(), 8623207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocs, 862492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getMethodDecl(), 862592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getLeftLoc(), 86263fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer Args, 862792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getRightLoc()); 8628b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8629b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 86301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 863160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8632454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { 86333fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8634b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8635b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 86361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 863760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8638454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { 86393fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8640b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8641b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 86421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 864360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8644454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { 8645f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // Transform the base expression. 864660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 8647f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Base.isInvalid()) 8648f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8649f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor 8650f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // We don't need to transform the ivar; it will never change. 86514a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8652f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // If nothing changed, just retain the existing expression. 8653f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (!getDerived().AlwaysRebuild() && 8654f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Base.get() == E->getBase()) 86553fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 86564a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 86579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), 8658f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->getLocation(), 8659f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->isArrow(), E->isFreeIvar()); 8660b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8661b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 86621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 866360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8664454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { 866512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // 'super' and types never change. Property never changes. Just 866612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // retain the existing expression. 866712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (!E->isObjectReceiver()) 86683fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 86694a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8670e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // Transform the base expression. 867160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 8672e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (Base.isInvalid()) 8673f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 86744a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8675e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // We don't need to transform the property; it will never change. 86764a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8677e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // If nothing changed, just retain the existing expression. 8678e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (!getDerived().AlwaysRebuild() && 8679e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor Base.get() == E->getBase()) 86803fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 868212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (E->isExplicitProperty()) 868312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getDerived().RebuildObjCPropertyRefExpr(Base.get(), 868412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getExplicitProperty(), 868512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getLocation()); 868612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 868712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getDerived().RebuildObjCPropertyRefExpr(Base.get(), 86883c3b7f90a863af43fa63043d396553ecf205351cJohn McCall SemaRef.Context.PseudoObjectTy, 868912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getImplicitPropertyGetter(), 869012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getImplicitPropertySetter(), 869112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getLocation()); 8692b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8693b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 86941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 869560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8696ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekTreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { 8697ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Transform the base expression. 8698ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); 8699ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Base.isInvalid()) 8700ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(); 8701ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8702ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Transform the key expression. 8703ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); 8704ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Key.isInvalid()) 8705ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(); 8706ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8707ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // If nothing changed, just retain the existing expression. 8708ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (!getDerived().AlwaysRebuild() && 8709ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) 8710ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return SemaRef.Owned(E); 8711ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 87124a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), 8713ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Base.get(), Key.get(), 8714ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek E->getAtIndexMethodDecl(), 8715ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek E->setAtIndexMethodDecl()); 8716ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 8717ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8718ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenektemplate<typename Derived> 8719ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult 8720454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { 8721f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // Transform the base expression. 872260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 8723f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Base.isInvalid()) 8724f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 87254a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8726f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // If nothing changed, just retain the existing expression. 8727f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (!getDerived().AlwaysRebuild() && 8728f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Base.get() == E->getBase()) 87293fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 87304a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 87319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), 8732f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->isArrow()); 8733b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8734b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 87351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 873660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8737454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { 8738b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 87394e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer SmallVector<Expr*, 8> SubExprs; 8740aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor SubExprs.reserve(E->getNumSubExprs()); 87414a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, 8742aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor SubExprs, &ArgumentChanged)) 8743aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 87441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8745b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 8746b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgumentChanged) 87473fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 87481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8749b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), 87503fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer SubExprs, 8751b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 8752b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8753b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 87541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 875560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8756454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { 8757c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall BlockDecl *oldBlock = E->getBlockDecl(); 87584a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8759c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); 8760c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall BlockScopeInfo *blockScope = SemaRef.getCurBlock(); 8761c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 8762c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); 87630586520acb2f368c874943353a222be7f00c3068Fariborz Jahanian blockScope->TheDecl->setBlockMissingReturnType( 87640586520acb2f368c874943353a222be7f00c3068Fariborz Jahanian oldBlock->blockMissingReturnType()); 87654a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8766686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<ParmVarDecl*, 4> params; 8767686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<QualType, 4> paramTypes; 87684a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8769a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian // Parameter substitution. 8770c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), 8771c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldBlock->param_begin(), 8772c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldBlock->param_size(), 877300b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis 0, paramTypes, ¶ms)) { 877400b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); 877592be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return ExprError(); 877600b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis } 8777c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 8778c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall const FunctionType *exprFunctionType = E->getFunctionType(); 877984b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman QualType exprResultType = 878084b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman getDerived().TransformType(exprFunctionType->getResultType()); 8781a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 8782a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // Don't allow returning a objc interface by value. 878384b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman if (exprResultType->isObjCObjectType()) { 87844a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier getSema().Diag(E->getCaretLocation(), 87854a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier diag::err_object_cannot_be_passed_returned_by_value) 878684b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman << 0 << exprResultType; 878700b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); 8788a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor return ExprError(); 8789a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor } 8790711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 8791c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall QualType functionType = getDerived().RebuildFunctionProtoType( 879284b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman exprResultType, 8793c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall paramTypes.data(), 8794c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall paramTypes.size(), 8795c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldBlock->isVariadic(), 8796eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith false, 0, RQ_None, 8797c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall exprFunctionType->getExtInfo()); 8798c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->FunctionType = functionType; 8799711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 8800711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Set the parameters on the block decl. 8801c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (!params.empty()) 88024278c654b645402554eb52a48e9c7097c9f1233aDavid Blaikie blockScope->TheDecl->setParams(params); 880384b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman 880484b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman if (!oldBlock->blockMissingReturnType()) { 880584b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman blockScope->HasImplicitReturnType = false; 880684b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman blockScope->ReturnType = exprResultType; 880784b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman } 88084a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8809711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Transform the body 8810c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall StmtResult body = getDerived().TransformStmt(E->getBody()); 881100b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis if (body.isInvalid()) { 881200b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); 8813711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return ExprError(); 881400b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis } 8815711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 8816c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#ifndef NDEBUG 8817c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall // In builds with assertions, make sure that we captured everything we 8818c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall // captured before. 8819fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor if (!SemaRef.getDiagnostics().hasErrorOccurred()) { 8820fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), 8821fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor e = oldBlock->capture_end(); i != e; ++i) { 8822fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor VarDecl *oldCapture = i->getVariable(); 8823fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor 8824fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor // Ignore parameter packs. 8825fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor if (isa<ParmVarDecl>(oldCapture) && 8826fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor cast<ParmVarDecl>(oldCapture)->isParameterPack()) 8827fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor continue; 8828c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 8829fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor VarDecl *newCapture = 8830fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), 8831fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor oldCapture)); 8832fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor assert(blockScope->CaptureMap.count(newCapture)); 8833fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor } 8834ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured()); 8835c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall } 8836c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#endif 8837c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 8838c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), 8839c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall /*Scope=*/0); 8840b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8841b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 88421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 884360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 884461eee0ca33b29e102f11bab77c8b74cc00e2392bTanya LattnerTreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { 8845b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Cannot transform asType expressions yet"); 884661eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner} 8847276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 8848276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmantemplate<typename Derived> 8849276b061970939293f1abaf694bd3ef05b2cbda79Eli FriedmanExprResult 8850276b061970939293f1abaf694bd3ef05b2cbda79Eli FriedmanTreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { 8851dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman QualType RetTy = getDerived().TransformType(E->getType()); 8852dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman bool ArgumentChanged = false; 88534e28d9e2ba9ce237549b45cfd4136ec6536d1325Benjamin Kramer SmallVector<Expr*, 8> SubExprs; 8854dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman SubExprs.reserve(E->getNumSubExprs()); 8855dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, 8856dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman SubExprs, &ArgumentChanged)) 8857dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman return ExprError(); 8858dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 8859dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (!getDerived().AlwaysRebuild() && 8860dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman !ArgumentChanged) 8861dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman return SemaRef.Owned(E); 8862dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 88633fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs, 8864dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman RetTy, E->getOp(), E->getRParenLoc()); 8865276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman} 88664a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 8867b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===// 8868b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Type reconstruction 8869b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===// 8870b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 88711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 887285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, 887385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Star) { 88742865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildPointerType(PointeeType, Star, 8875b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor getDerived().getBaseEntity()); 8876b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8877b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 88781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 887985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, 888085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Star) { 88812865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildBlockPointerType(PointeeType, Star, 8882b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor getDerived().getBaseEntity()); 8883b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8884b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 88851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 88861eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 888785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, 888885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall bool WrittenAsLValue, 888985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil) { 88902865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, 889185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Sigil, getDerived().getBaseEntity()); 8892b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8893b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 88941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 88951eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 889685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, 889785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType ClassType, 889885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil) { 88992865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildMemberPointerType(PointeeType, ClassType, 890085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Sigil, getDerived().getBaseEntity()); 8901577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8902577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8903577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 89041eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 8905577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorTreeTransform<Derived>::RebuildArrayType(QualType ElementType, 8906577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 8907577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt *Size, 8908577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Expr *SizeExpr, 8909577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 8910577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 8911577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (SizeExpr || !Size) 8912577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, 8913577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange, 8914577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor getDerived().getBaseEntity()); 89151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 89161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Types[] = { 89171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, 89181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, 89191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty 8920577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor }; 8921577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const unsigned NumTypes = sizeof(Types) / sizeof(QualType); 8922577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType SizeType; 8923577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor for (unsigned I = 0; I != NumTypes; ++I) 8924577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { 8925577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SizeType = Types[I]; 8926577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor break; 8927577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 89281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 892901f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman // Note that we can return a VariableArrayType here in the case where 893001f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman // the element type was a dependent VariableArrayType. 893101f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman IntegerLiteral *ArraySize 893201f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, 893301f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman /*FIXME*/BracketsRange.getBegin()); 893401f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, 8935577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange, 89361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getDerived().getBaseEntity()); 8937577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 89381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8939577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 89401eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 89411eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, 8942577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 8943577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt &Size, 894485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 894585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange) { 89461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, 894785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall IndexTypeQuals, BracketsRange); 8948577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8949577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8950577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 89511eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 89521eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, 8953577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 895485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 895585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange) { 89561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, 895785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall IndexTypeQuals, BracketsRange); 8958577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 89591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8960577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 89611eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 89621eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, 8963577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 89649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 8965577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 8966577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 89671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 89689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SizeExpr, 8969577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange); 8970577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8971577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8972577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 89731eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 89741eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, 8975577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 89769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 8977577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 8978577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 89791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 89809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SizeExpr, 8981577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange); 8982577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8983577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8984577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8985577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, 8986e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson unsigned NumElements, 8987e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::VectorKind VecKind) { 8988577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor // FIXME: semantic checking! 8989e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); 8990577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 89911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8992577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8993577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, 8994577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumElements, 8995577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc) { 8996577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), 8997577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor NumElements, true); 8998577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IntegerLiteral *VectorSize 89999996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, 90009996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis AttributeLoc); 90019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); 9002577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 90031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9004577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 90051eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 90061eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, 90079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 9008577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc) { 90099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); 9010577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 90111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9012577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 9013577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, 90141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType *ParamTypes, 9015577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumParamTypes, 90161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool Variadic, 9017eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith bool HasTrailingReturn, 9018fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman unsigned Quals, 9019c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind RefQualifier, 9020fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman const FunctionType::ExtInfo &Info) { 90211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, 9022eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith HasTrailingReturn, Quals, RefQualifier, 9023577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor getDerived().getBaseLocation(), 9024fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman getDerived().getBaseEntity(), 9025fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman Info); 9026577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 90271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9028577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 9029a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { 9030a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return SemaRef.Context.getFunctionNoProtoType(T); 9031a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 9032a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 9033a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 9034ed97649e9574b9d854fa4d6109c9333ae0993554John McCallQualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { 9035ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(D && "no decl found"); 9036ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (D->isInvalidDecl()) return QualType(); 9037ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 903892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // FIXME: Doesn't account for ObjCInterfaceDecl! 9039ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TypeDecl *Ty; 9040ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (isa<UsingDecl>(D)) { 9041ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UsingDecl *Using = cast<UsingDecl>(D); 9042ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(Using->isTypeName() && 9043ed97649e9574b9d854fa4d6109c9333ae0993554John McCall "UnresolvedUsingTypenameDecl transformed to non-typename using"); 9044ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 9045ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // A valid resolved using typename decl points to exactly one type decl. 9046ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(++Using->shadow_begin() == Using->shadow_end()); 9047ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); 90484a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 9049ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } else { 9050ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(isa<UnresolvedUsingTypenameDecl>(D) && 9051ed97649e9574b9d854fa4d6109c9333ae0993554John McCall "UnresolvedUsingTypenameDecl transformed to non-using decl"); 9052ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Ty = cast<UnresolvedUsingTypenameDecl>(D); 9053ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 9054ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 9055ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return SemaRef.Context.getTypeDeclType(Ty); 9056ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 9057ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 9058ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> 90592a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, 90602a984cad5ac3fdceeff2bd99daa7b90979313475John McCall SourceLocation Loc) { 90612a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return SemaRef.BuildTypeofExprType(E, Loc); 9062577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 9063577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 9064577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 9065577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { 9066577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeOfType(Underlying); 9067577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 9068577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 9069577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 90702a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, 90712a984cad5ac3fdceeff2bd99daa7b90979313475John McCall SourceLocation Loc) { 90722a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return SemaRef.BuildDecltypeType(E, Loc); 9073577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 9074577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 9075577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 9076ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, 9077ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType::UTTKind UKind, 9078ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt SourceLocation Loc) { 9079ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); 9080ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt} 9081ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 9082ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunttemplate<typename Derived> 9083577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTemplateSpecializationType( 9084833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateName Template, 9085833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation TemplateNameLoc, 908667714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor TemplateArgumentListInfo &TemplateArgs) { 9087d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); 9088577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 90891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9090dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived> 9091b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli FriedmanQualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, 9092b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman SourceLocation KWLoc) { 9093b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return SemaRef.BuildAtomicType(ValueType, KWLoc); 9094b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman} 9095b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 9096b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmantemplate<typename Derived> 90971eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 9098fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 9099d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor bool TemplateKW, 9100d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TemplateDecl *Template) { 9101fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, 9102d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor Template); 9103d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor} 9104d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor 9105d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived> 91061eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 9107fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 9108fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor const IdentifierInfo &Name, 9109fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 911043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 911143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope) { 9112fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor UnqualifiedId TemplateName; 9113fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName.setIdentifier(&Name, NameLoc); 9114d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Sema::TemplateTy Template; 9115e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. 9116d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor getSema().ActOnDependentTemplateName(/*Scope=*/0, 9117e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, TemplateKWLoc, TemplateName, 9118b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType::make(ObjectType), 9119d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor /*EnteringContext=*/false, 9120d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Template); 912143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return Template.get(); 9122d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor} 91231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9124b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 9125ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTemplateName 9126fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 9127ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor OverloadedOperatorKind Operator, 9128fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 9129ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor QualType ObjectType) { 9130ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId Name; 9131fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor // FIXME: Bogus location information. 9132e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; 9133fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); 9134e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. 9135d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Sema::TemplateTy Template; 9136d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor getSema().ActOnDependentTemplateName(/*Scope=*/0, 9137e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, TemplateKWLoc, Name, 9138b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType::make(ObjectType), 9139d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor /*EnteringContext=*/false, 9140d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Template); 9141d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor return Template.template getAsVal<TemplateName>(); 9142ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor} 91434a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier 9144ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregortemplate<typename Derived> 914560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 9146b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, 9147b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 91489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *OrigCallee, 91499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *First, 91509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Second) { 91519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Callee = OrigCallee->IgnoreParenCasts(); 91529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); 91531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9154b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Determine whether this should be a builtin operation. 9155f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl if (Op == OO_Subscript) { 91569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType() && 91579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall !Second->getType()->isOverloadableType()) 91589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().CreateBuiltinArraySubscriptExpr(First, 91599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Callee->getLocStart(), 91609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Second, OpLoc); 91611a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman } else if (Op == OO_Arrow) { 91621a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman // -> is never a builtin operation. 91639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); 91649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall } else if (Second == 0 || isPostIncDec) { 91659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType()) { 9166b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // The argument is not of overloadable type, so try to create a 9167b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // built-in unary operation. 91682de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc 9169b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); 91701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 91719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); 9172b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 9173b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } else { 91749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType() && 91759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall !Second->getType()->isOverloadableType()) { 9176b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Neither of the arguments is an overloadable type, so try to 9177b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // create a built-in binary operation. 91782de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 917960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 91809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); 9181b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 9182f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 91831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 91843fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer return Result; 9185b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 9186b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 91871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 91881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Compute the transformed set of functions (and function templates) to be 9189b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // used during overload resolution. 91906e26689f5d513e24ad7783a4493201930fdeccc0John McCall UnresolvedSet<16> Functions; 91911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 91929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { 9193ba13543329afac4a0d01304ec2ec4924d99306a6John McCall assert(ULE->requiresADL()); 9194ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 9195ba13543329afac4a0d01304ec2ec4924d99306a6John McCall // FIXME: Do we have to check 9196ba13543329afac4a0d01304ec2ec4924d99306a6John McCall // IsAcceptableNonMemberOperatorCandidate for each of these? 91976e26689f5d513e24ad7783a4493201930fdeccc0John McCall Functions.append(ULE->decls_begin(), ULE->decls_end()); 9198ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } else { 91999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl()); 9200ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } 92011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9202b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Add any functions found via argument-dependent lookup. 92039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Args[2] = { First, Second }; 92049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall unsigned NumArgs = 1 + (Second != 0); 92051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9206b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Create the overloaded operator invocation for unary operators. 9207b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (NumArgs == 1 || isPostIncDec) { 92082de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc 9209b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); 92109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); 9211b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 92121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 92135b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor if (Op == OO_Subscript) { 92145b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor SourceLocation LBrace; 92155b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor SourceLocation RBrace; 92165b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor 92175b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { 92185b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo(); 92195b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor LBrace = SourceLocation::getFromRawEncoding( 92205b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor NameLoc.CXXOperatorName.BeginOpNameLoc); 92215b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor RBrace = SourceLocation::getFromRawEncoding( 92225b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor NameLoc.CXXOperatorName.EndOpNameLoc); 92235b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor } else { 92245b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor LBrace = Callee->getLocStart(); 92255b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor RBrace = OpLoc; 92265b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor } 92275b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor 92285b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, 92295b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor First, Second); 92305b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor } 9231f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl 9232b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Create the overloaded operator invocation for binary operators. 92332de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 923460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 9235b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); 9236b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 9237f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 92381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 92393fe198bf0d6118c7b080c17c3bb28d7c84e458b9Benjamin Kramer return Result; 9240b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 92411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 924226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregortemplate<typename Derived> 92434a9d795502f8e001cdc6465ea7a0739ca48dd483Chad RosierExprResult 92449ae2f076ca5ab1feb3ba95629099ec2319833701John McCallTreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, 924526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SourceLocation OperatorLoc, 924626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor bool isArrow, 9247f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor CXXScopeSpec &SS, 924826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor TypeSourceInfo *ScopeType, 924926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SourceLocation CCLoc, 9250fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SourceLocation TildeLoc, 9251a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed) { 92529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall QualType BaseType = Base->getType(); 92539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (Base->isTypeDependent() || Destroyed.getIdentifier() || 925426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor (!isArrow && !BaseType->getAs<RecordType>()) || 92554a9d795502f8e001cdc6465ea7a0739ca48dd483Chad Rosier (isArrow && BaseType->getAs<PointerType>() && 9256bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif !BaseType->getAs<PointerType>()->getPointeeType() 9257bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif ->template getAs<RecordType>())){ 925826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor // This pseudo-destructor expression is still a pseudo-destructor. 92599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, 926026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor isArrow? tok::arrow : tok::period, 9261fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SS, ScopeType, CCLoc, TildeLoc, 9262a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed, 926326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /*FIXME?*/true); 926426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor } 92652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 9266a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); 92672577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( 92682577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SemaRef.Context.getCanonicalType(DestroyedType->getType()))); 92692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); 92702577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.setNamedTypeInfo(DestroyedType); 92712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 92726314db9d5918939ad8ec88cd9c3f42a33a67c2b6Richard Smith // The scope type is now known to be a valid nested name specifier 92736314db9d5918939ad8ec88cd9c3f42a33a67c2b6Richard Smith // component. Tack it on to the end of the nested name specifier. 92746314db9d5918939ad8ec88cd9c3f42a33a67c2b6Richard Smith if (ScopeType) 92756314db9d5918939ad8ec88cd9c3f42a33a67c2b6Richard Smith SS.Extend(SemaRef.Context, SourceLocation(), 92766314db9d5918939ad8ec88cd9c3f42a33a67c2b6Richard Smith ScopeType->getTypeLoc(), CCLoc); 92772577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 9278e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. 92799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, BaseType, 928026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor OperatorLoc, isArrow, 9281e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, TemplateKWLoc, 9282e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /*FIXME: FirstQualifier*/ 0, 92832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 928426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /*TemplateArgs*/ 0); 928526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor} 928626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor 9287577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} // end namespace clang 9288577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 9289577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H 9290