TreeTransform.h revision 699c9044c7d53a2774d0dd261a6901dd2c4a545f
157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===// 2577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// 3577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// The LLVM Compiler Infrastructure 4577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// 5577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// This file is distributed under the University of Illinois Open Source 6577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// License. See LICENSE.TXT for details. 757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner//===----------------------------------------------------------------------===// 8577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// 9577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// This file implements a semantic tree transformation that takes a given 10577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// AST and rebuilds it, possibly transforming some nodes in the process. 11577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// 1257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner//===----------------------------------------------------------------------===// 1357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 14577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H 15577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#define LLVM_CLANG_SEMA_TREETRANSFORM_H 16577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 172d88708cbe4e4ec5e04e4acb6bd7f5be68557379John McCall#include "clang/Sema/SemaInternal.h" 18e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#include "clang/Sema/Lookup.h" 198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor#include "clang/Sema/ParsedTemplate.h" 20dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor#include "clang/Sema/SemaDiagnostic.h" 21781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#include "clang/Sema/ScopeInfo.h" 22c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor#include "clang/AST/Decl.h" 237cd088e519d7e6caa4c4c12db52e0e4ae35d25c2John McCall#include "clang/AST/DeclObjC.h" 243e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith#include "clang/AST/DeclTemplate.h" 25657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor#include "clang/AST/Expr.h" 26b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/AST/ExprCXX.h" 27b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/AST/ExprObjC.h" 2843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/Stmt.h" 2943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/StmtCXX.h" 3043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/StmtObjC.h" 3119510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Ownership.h" 3219510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Designator.h" 33b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/Lex/Preprocessor.h" 34a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie#include "llvm/ADT/ArrayRef.h" 35a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "llvm/Support/ErrorHandling.h" 367e44e3fcd75147f229f42e6912898ce62d6b4d08Douglas Gregor#include "TypeLocBuilder.h" 37577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#include <algorithm> 38577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 39577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregornamespace clang { 40781472fe99a120098c631b0cbe33c89f8cef5e70John McCallusing namespace sema; 411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \brief A semantic tree transformation that allows one to transform one 43577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// abstract syntax tree into another. 44577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// A new tree transformation is defined by creating a new subclass \c X of 461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// \c TreeTransform<X> and then overriding certain operations to provide 471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// behavior specific to that transformation. For example, template 48577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// instantiation is implemented as a tree transformation where the 49577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation of TemplateTypeParmType nodes involves substituting the 50577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template arguments for their corresponding template parameters; a similar 51577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation is performed for non-type template parameters and 52577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template template parameters. 53577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 54577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// This tree-transformation template uses static polymorphism to allow 551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// subclasses to customize any of its operations. Thus, a subclass can 56577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// override any of the transformation or rebuild operators by providing an 57577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operation with the same signature as the default implementation. The 58577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// overridding function should not be virtual. 59577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 60577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// Semantic tree transformations are split into two stages, either of which 61577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// can be replaced by a subclass. The "transform" step transforms an AST node 62577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// or the parts of an AST node using the various transformation functions, 63577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// then passes the pieces on to the "rebuild" step, which constructs a new AST 64577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// node of the appropriate kind from the pieces. The default transformation 65577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// routines recursively transform the operands to composite AST nodes (e.g., 66577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// the pointee type of a PointerType node) and, if any of those operand nodes 67577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// were changed by the transformation, invokes the rebuild operation to create 68577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// a new AST node. 69577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Subclasses can customize the transformation at various levels. The 71670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor/// most coarse-grained transformations involve replacing TransformType(), 729151c11836f5fbb36cedfe4d22df7e00e77a1d42Douglas Gregor/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(), 73577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// TransformTemplateName(), or TransformTemplateArgument() with entirely 74577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// new implementations. 75577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 76577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// For more fine-grained transformations, subclasses can replace any of the 77577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \c TransformXXX functions (where XXX is the name of an AST node, e.g., 7843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor/// PointerType, StmtExpr) to alter the transformation. As mentioned previously, 79577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// replacing TransformTemplateTypeParmType() allows template instantiation 801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to substitute template arguments for their corresponding template 81577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// parameters. Additionally, subclasses can override the \c RebuildXXX 82577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// functions to control how AST nodes are rebuilt when their operands change. 83577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// By default, \c TreeTransform will invoke semantic analysis to rebuild 84577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// AST nodes. However, certain other tree transformations (e.g, cloning) may 85577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// be able to use more efficient rebuild steps. 86577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 87577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// There are a handful of other functions that can be overridden, allowing one 881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to avoid traversing nodes that don't need any transformation 89577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their 90577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operands have not changed (\c AlwaysRebuild()), and customize the 91577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// default locations and entity names used for type-checking 92577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c getBaseLocation(), \c getBaseEntity()). 93577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 94577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorclass TreeTransform { 95d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// \brief Private RAII object that helps us forget and then re-remember 96d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// the template argument corresponding to a partially-substituted parameter 97d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor /// pack. 98d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor class ForgetPartiallySubstitutedPackRAII { 99d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Derived &Self; 100d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor TemplateArgument Old; 101d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 102d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor public: 103d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) { 104d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Old = Self.ForgetPartiallySubstitutedPack(); 105d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor } 106d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 107d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ~ForgetPartiallySubstitutedPackRAII() { 108d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Self.RememberPartiallySubstitutedPack(Old); 109d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor } 110d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor }; 111d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 112577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorprotected: 113577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Sema &SemaRef; 1148491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 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; 119dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 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(); 180ae201f75e56f33278b2d48396b35bfa74c32af63Douglas Gregor 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 } 210c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 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 /// 2248491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \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 /// 2448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \returns true if an error occurred (e.g., because the parameter packs 2458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// are to be instantiated with arguments of different lengths), false 2468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 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 } 2578491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 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 } 266d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 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) { } 273d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 27412c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor /// \brief Note to the derived class when a function parameter pack is 27512c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor /// being expanded. 27612c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { } 27712c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor 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 /// 328aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// This routine transforms a list of expressions by invoking 329aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \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 339aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 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); 352aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 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. 359dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 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; 364dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 365dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor return D; 366dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor } 36743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 368dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// \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) { } 374dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 375dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// \brief Note that a local declaration has been transformed by this 376dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// transformer. 377dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// 378dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /// 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 } 385dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 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. 390c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Decl *TransformDefinition(SourceLocation Loc, Decl *D) { 391c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 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 /// 397c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// 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. 403c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { 404c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); 4056cd219879ffce00920189ec1dcea927a42602961Douglas Gregor } 406c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 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 /// 436fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor /// \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 /// 466fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 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 /// 4907f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// By default, this operation transforms all of the template arguments 4917f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// in the input set using \c TransformTemplateArgument(), and appends 4927f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// 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 53043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType 53143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TransformTemplateSpecializationType(TypeLocBuilder &TLB, 53243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateSpecializationTypeLoc TL, 53343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template); 53443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 53543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType 53643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 53743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentTemplateSpecializationTypeLoc TL, 538087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor TemplateName Template, 539087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor CXXScopeSpec &SS); 540a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 541a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 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 57443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) \ 57560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Transform##Node(Node *S); 576b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent) \ 57760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Transform##Node(Node *E); 5787381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 5794bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 5801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 581577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new pointer type given its pointee type. 582577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 583577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the pointer type. 584577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 58585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); 586577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 587577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new block pointer type given its pointee type. 588577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 5891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, performs semantic analysis when building the block pointer 590577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// type. Subclasses may override this routine to provide different behavior. 59185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); 592577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 59385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// \brief Build a new reference type given the type it references. 594577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 59585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// By default, performs semantic analysis when building the 59685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// reference type. Subclasses may override this routine to provide 59785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// different behavior. 598577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 59985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// \param LValue whether the type was written with an lvalue sigil 60085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// or an rvalue sigil. 60185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildReferenceType(QualType ReferentType, 60285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall bool LValue, 60385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil); 6041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 605577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new member pointer type given the pointee type and the 606577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// class type it refers into. 607577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 608577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the member pointer 609577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// type. Subclasses may override this routine to provide different behavior. 61085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, 61185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil); 6121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 613577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new array type given the element type, size 614577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// modifier, size of the array (if known), size expression, and index type 615577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// qualifiers. 616577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 617577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 618577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Also by default, all of the other Rebuild*Array 620577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildArrayType(QualType ElementType, 621577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 622577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt *Size, 623577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Expr *SizeExpr, 624577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 625577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange); 6261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 627577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new constant array type given the element type, size 628577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// modifier, (known) size of the array, and index type qualifiers. 629577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 630577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 631577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildConstantArrayType(QualType ElementType, 633577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 634577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt &Size, 63585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 63685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange); 637577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 638577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new incomplete array type given the element type, size 639577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// modifier, and index type qualifiers. 640577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 641577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 642577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildIncompleteArrayType(QualType ElementType, 644577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 64585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 64685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange); 647577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 6481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new variable-length array type given the element type, 649577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// size modifier, size expression, and index type qualifiers. 650577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 651577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 652577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildVariableArrayType(QualType ElementType, 654577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 6559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 656577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 657577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange); 658577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 6591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new dependent-sized array type given the element type, 660577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// size modifier, size expression, and index type qualifiers. 661577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 662577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 663577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildDependentSizedArrayType(QualType ElementType, 665577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 6669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 667577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 668577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange); 669577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 670577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new vector type given the element type and 671577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// number of elements. 672577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 673577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the vector type. 674577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 67582287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson QualType RebuildVectorType(QualType ElementType, unsigned NumElements, 676e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::VectorKind VecKind); 6771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 678577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new extended vector type given the element type and 679577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// number of elements. 680577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 681577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the vector type. 682577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 683577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, 684577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc); 6851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new potentially dependently-sized extended vector type 687577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// given the element type and number of elements. 688577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 689577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the vector type. 690577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildDependentSizedExtVectorType(QualType ElementType, 6929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 693577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc); 6941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 695577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new function type. 696577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 697577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the function type. 698577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 699577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildFunctionProtoType(QualType T, 7001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType *ParamTypes, 701577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumParamTypes, 702eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith bool Variadic, bool HasTrailingReturn, 703eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith unsigned Quals, 704c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind RefQualifier, 705fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman const FunctionType::ExtInfo &Info); 7061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 707a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// \brief Build a new unprototyped function type. 708a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType RebuildFunctionNoProtoType(QualType ResultType); 709a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 710ed97649e9574b9d854fa4d6109c9333ae0993554John McCall /// \brief Rebuild an unresolved typename type, given the decl that 711ed97649e9574b9d854fa4d6109c9333ae0993554John McCall /// the UnresolvedUsingTypenameDecl was transformed to. 712ed97649e9574b9d854fa4d6109c9333ae0993554John McCall QualType RebuildUnresolvedUsingType(Decl *D); 713ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 714577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new typedef type. 715162e1c1b487352434552147967c3dd296ebee2f7Richard Smith QualType RebuildTypedefType(TypedefNameDecl *Typedef) { 716577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeDeclType(Typedef); 717577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 718577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 719577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new class/struct/union type. 720577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildRecordType(RecordDecl *Record) { 721577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeDeclType(Record); 722577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 723577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 724577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new Enum type. 725577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildEnumType(EnumDecl *Enum) { 726577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeDeclType(Enum); 727577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 7287da2431c23ef1ee8acb114e39692246e1801afc2John McCall 7291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new typeof(expr) type. 730577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 731577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the typeof type. 732577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 7332a984cad5ac3fdceeff2bd99daa7b90979313475John McCall QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); 734577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 7351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new typeof(type) type. 736577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 737577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, builds a new TypeOfType with the given underlying type. 738577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildTypeOfType(QualType Underlying); 739577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 740ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt /// \brief Build a new unary transform type. 741ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType RebuildUnaryTransformType(QualType BaseType, 742ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType::UTTKind UKind, 743ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt SourceLocation Loc); 744ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 7451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new C++0x decltype type. 746577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 747577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the decltype type. 748577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 7492a984cad5ac3fdceeff2bd99daa7b90979313475John McCall QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); 7501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 75134b41d939a1328f484511c6002ba2456db879a29Richard Smith /// \brief Build a new C++0x auto type. 75234b41d939a1328f484511c6002ba2456db879a29Richard Smith /// 75334b41d939a1328f484511c6002ba2456db879a29Richard Smith /// By default, builds a new AutoType with the given deduced type. 75434b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType RebuildAutoType(QualType Deduced) { 75534b41d939a1328f484511c6002ba2456db879a29Richard Smith return SemaRef.Context.getAutoType(Deduced); 75634b41d939a1328f484511c6002ba2456db879a29Richard Smith } 75734b41d939a1328f484511c6002ba2456db879a29Richard Smith 758577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new template specialization type. 759577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 760577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the template 761577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// specialization type. Subclasses may override this routine to provide 762577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// different behavior. 763577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildTemplateSpecializationType(TemplateName Template, 764833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation TemplateLoc, 76567714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor TemplateArgumentListInfo &Args); 7661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 767075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// \brief Build a new parenthesized type. 768075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// 769075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// By default, builds a new ParenType type from the inner type. 770075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// Subclasses may override this routine to provide different behavior. 771075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType RebuildParenType(QualType InnerType) { 772075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return SemaRef.Context.getParenType(InnerType); 773075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 774075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 775577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new qualified name type. 776577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 777465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// By default, builds a new ElaboratedType type from the keyword, 778465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// the nested-name-specifier and the named type. 779465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// Subclasses may override this routine to provide different behavior. 78021e413fe6305a198564d436ac515497716c47844John McCall QualType RebuildElaboratedType(SourceLocation KeywordLoc, 78121e413fe6305a198564d436ac515497716c47844John McCall ElaboratedTypeKeyword Keyword, 7829e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 7839e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualType Named) { 7849e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor return SemaRef.Context.getElaboratedType(Keyword, 7859e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 7869e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor Named); 7871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 788577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 789577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new typename type that refers to a template-id. 790577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 791e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// By default, builds a new DependentNameType type from the 792e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// nested-name-specifier and the given type. Subclasses may override 793e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// this routine to provide different behavior. 79433500955d731c73717af52088b7fc0e7a85681e7John McCall QualType RebuildDependentTemplateSpecializationType( 79594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor ElaboratedTypeKeyword Keyword, 79694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 79794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor const IdentifierInfo *Name, 79894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor SourceLocation NameLoc, 79967714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor TemplateArgumentListInfo &Args) { 80094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Rebuild the template name. 80194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // TODO: avoid TemplateName abstraction 802fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor CXXScopeSpec SS; 803fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SS.Adopt(QualifierLoc); 80494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor TemplateName InstName 805fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(), 0); 80694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 80794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (InstName.isNull()) 80894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return QualType(); 80994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 81094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // If it's still dependent, make a dependent specialization. 81194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (InstName.getAsDependentTemplateName()) 81294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return SemaRef.Context.getDependentTemplateSpecializationType(Keyword, 81394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 81494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor Name, 81594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor Args); 81694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 81794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Otherwise, make an elaborated type wrapping a non-dependent 81894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // specialization. 81994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualType T = 82094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); 82194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (T.isNull()) return QualType(); 82294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 82394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == 0) 82494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return T; 82594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 82694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return SemaRef.Context.getElaboratedType(Keyword, 82794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 82894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor T); 82994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor } 83094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 831577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new typename type that refers to an identifier. 832577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 833577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the typename type 834e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// (or elaborated type). Subclasses may override this routine to provide 835577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// different behavior. 836e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, 837e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SourceLocation KeywordLoc, 8382494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 8392494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor const IdentifierInfo *Id, 840e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SourceLocation IdLoc) { 8414033642464e8ba0982f88f34cffad808d247b393Douglas Gregor CXXScopeSpec SS; 8422494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor SS.Adopt(QualifierLoc); 843e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara 8442494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor if (QualifierLoc.getNestedNameSpecifier()->isDependent()) { 8454033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // If the name is still dependent, just build a new dependent name type. 8464033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (!SemaRef.computeDeclContext(SS)) 8472494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor return SemaRef.Context.getDependentNameType(Keyword, 8482494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 8492494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor Id); 8504033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 8514033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 852465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara if (Keyword == ETK_None || Keyword == ETK_Typename) 8532494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc, 854e29425bd22fbb9200bbec7b743197b9c6dad3e40Douglas Gregor *Id, IdLoc); 855465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 856465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); 857465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 858e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara // We had a dependent elaborated-type-specifier that has been transformed 8594033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // into a non-dependent elaborated-type-specifier. Find the tag we're 8604033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // referring to. 861e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); 8624033642464e8ba0982f88f34cffad808d247b393Douglas Gregor DeclContext *DC = SemaRef.computeDeclContext(SS, false); 8634033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (!DC) 8644033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 8654033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 8665613876991c80a684595fe8de1f039296a0657ffJohn McCall if (SemaRef.RequireCompleteDeclContext(SS, DC)) 8675613876991c80a684595fe8de1f039296a0657ffJohn McCall return QualType(); 8685613876991c80a684595fe8de1f039296a0657ffJohn McCall 8694033642464e8ba0982f88f34cffad808d247b393Douglas Gregor TagDecl *Tag = 0; 8704033642464e8ba0982f88f34cffad808d247b393Douglas Gregor SemaRef.LookupQualifiedName(Result, DC); 8714033642464e8ba0982f88f34cffad808d247b393Douglas Gregor switch (Result.getResultKind()) { 8724033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::NotFound: 8734033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::NotFoundInCurrentInstantiation: 8744033642464e8ba0982f88f34cffad808d247b393Douglas Gregor break; 875c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8764033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::Found: 8774033642464e8ba0982f88f34cffad808d247b393Douglas Gregor Tag = Result.getAsSingle<TagDecl>(); 8784033642464e8ba0982f88f34cffad808d247b393Douglas Gregor break; 879c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8804033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::FoundOverloaded: 8814033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::FoundUnresolvedValue: 8824033642464e8ba0982f88f34cffad808d247b393Douglas Gregor llvm_unreachable("Tag lookup cannot find non-tags"); 883c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8844033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::Ambiguous: 8854033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // Let the LookupResult structure handle ambiguities. 8864033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 8874033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 8884033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 8894033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (!Tag) { 890446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky // Check where the name exists but isn't a tag type and use that to emit 891446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky // better diagnostics. 892446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); 893446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.LookupQualifiedName(Result, DC); 894446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky switch (Result.getResultKind()) { 895446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky case LookupResult::Found: 896446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky case LookupResult::FoundOverloaded: 897446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky case LookupResult::FoundUnresolvedValue: { 8983e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NamedDecl *SomeDecl = Result.getRepresentativeDecl(); 899446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky unsigned Kind = 0; 900446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky if (isa<TypedefDecl>(SomeDecl)) Kind = 1; 901162e1c1b487352434552147967c3dd296ebee2f7Richard Smith else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2; 902162e1c1b487352434552147967c3dd296ebee2f7Richard Smith else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3; 903446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind; 904446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at); 905446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky break; 9063e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 907446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky default: 908446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky // FIXME: Would be nice to highlight just the source range. 909446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) 910446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky << Kind << Id << DC; 911446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky break; 912446e4029c75b651475e9055dc9dd18fbc7b6dabeNick Lewycky } 9134033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 9144033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 915465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 916bbf34c024398e7bae825686dcff4c3b901ec9f89Richard Trieu if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false, 917bbf34c024398e7bae825686dcff4c3b901ec9f89Richard Trieu IdLoc, *Id)) { 918e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; 9194033642464e8ba0982f88f34cffad808d247b393Douglas Gregor SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); 9204033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 9214033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 9224033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 9234033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // Build the elaborated-type-specifier type. 9244033642464e8ba0982f88f34cffad808d247b393Douglas Gregor QualType T = SemaRef.Context.getTypeDeclType(Tag); 9252494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor return SemaRef.Context.getElaboratedType(Keyword, 9262494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor QualifierLoc.getNestedNameSpecifier(), 9272494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor T); 928dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor } 9291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9302fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// \brief Build a new pack expansion type. 9312fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// 9322fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// By default, builds a new PackExpansionType type from the given pattern. 9332fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor /// Subclasses may override this routine to provide different behavior. 9342fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor QualType RebuildPackExpansionType(QualType Pattern, 9352fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor SourceRange PatternRange, 936cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor SourceLocation EllipsisLoc, 937cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 938cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc, 939cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions); 9402fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor } 9412fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor 942b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman /// \brief Build a new atomic type given its value type. 943b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman /// 944b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman /// By default, performs semantic analysis when building the atomic type. 945b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman /// Subclasses may override this routine to provide different behavior. 946b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc); 947b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 948d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// \brief Build a new template name given a nested name specifier, a flag 949d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// indicating whether the "template" keyword was provided, and the template 950d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// that the template name refers to. 951d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// 952d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// By default, builds the new template name directly. Subclasses may override 953d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// this routine to provide different behavior. 954fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName RebuildTemplateName(CXXScopeSpec &SS, 955d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor bool TemplateKW, 956d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TemplateDecl *Template); 957d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor 958d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// \brief Build a new template name given a nested name specifier and the 959d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// name that is referred to as a template. 960d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// 961d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// By default, performs semantic analysis to determine whether the name can 962d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// be resolved to a specific template, then builds the appropriate kind of 963d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// template name. Subclasses may override this routine to provide different 964d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// behavior. 965fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName RebuildTemplateName(CXXScopeSpec &SS, 966fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor const IdentifierInfo &Name, 967fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 96843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 96943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope); 9701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 971ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// \brief Build a new template name given a nested name specifier and the 972ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// overloaded operator name that is referred to as a template. 973ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// 974ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// By default, performs semantic analysis to determine whether the name can 975ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// be resolved to a specific template, then builds the appropriate kind of 976ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// template name. Subclasses may override this routine to provide different 977ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// behavior. 978fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName RebuildTemplateName(CXXScopeSpec &SS, 979ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor OverloadedOperatorKind Operator, 980fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 981ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor QualType ObjectType); 9821aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 9831aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// \brief Build a new template name given a template template parameter pack 9841aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// and the 9851aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// 9861aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// By default, performs semantic analysis to determine whether the name can 9871aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// be resolved to a specific template, then builds the appropriate kind of 9881aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// template name. Subclasses may override this routine to provide different 9891aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor /// behavior. 9901aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param, 9911aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor const TemplateArgument &ArgPack) { 9921aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack); 9931aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor } 9941aee05d08b2184acadeb36de300e216390780d6cDouglas Gregor 99543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new compound statement. 99643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 99743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 99843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 99960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, 100043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor MultiStmtArg Statements, 100143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation RBraceLoc, 100243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool IsStmtExpr) { 10039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, 100443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor IsStmtExpr); 100543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 100643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 100743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new case statement. 100843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 100943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 101043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 101160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCaseStmt(SourceLocation CaseLoc, 10129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *LHS, 101343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation EllipsisLoc, 10149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *RHS, 101543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation ColonLoc) { 10169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, 101743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor ColonLoc); 101843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 102043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Attach the body to a new case statement. 102143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 102243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 102343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 102460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { 10259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall getSema().ActOnCaseStmtBody(S, Body); 10269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return S; 102743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 102943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new default statement. 103043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 103143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 103243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 103360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, 103443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation ColonLoc, 10359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *SubStmt) { 10369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, 103743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /*CurScope=*/0); 103843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 104043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new label statement. 104143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 104243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 104343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 104457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L, 104557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner SourceLocation ColonLoc, Stmt *SubStmt) { 104657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt); 104743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1049534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith /// \brief Build a new label statement. 1050534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith /// 1051534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith /// By default, performs semantic analysis to build the new statement. 1052534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith /// Subclasses may override this routine to provide different behavior. 1053534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult RebuildAttributedStmt(SourceLocation AttrLoc, const AttrVec &Attrs, 1054534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith Stmt *SubStmt) { 1055534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt); 1056534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith } 1057534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 105843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new "if" statement. 105943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 106043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 106143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 106260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, 106357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner VarDecl *CondVar, Stmt *Then, 106457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner SourceLocation ElseLoc, Stmt *Else) { 106544aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); 106643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 106843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Start building a new switch statement. 106943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 107043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 107143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 107260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, 107357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Expr *Cond, VarDecl *CondVar) { 10749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, 1075d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall CondVar); 107643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 107843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Attach the body to the switch statement. 107943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 108043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 108143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 108260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, 108357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Stmt *Switch, Stmt *Body) { 10849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); 108543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 108643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 108743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new while statement. 108843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 108943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 109043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 109157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond, 109257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner VarDecl *CondVar, Stmt *Body) { 10939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); 109443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 109643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new do-while statement. 109743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 109843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 109943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 110060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, 1101ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation WhileLoc, SourceLocation LParenLoc, 1102ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner Expr *Cond, SourceLocation RParenLoc) { 11039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, 11049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond, RParenLoc); 110543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 110643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 110743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new for statement. 110843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 110943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 111043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1111ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc, 1112ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner Stmt *Init, Sema::FullExprArg Cond, 1113ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner VarDecl *CondVar, Sema::FullExprArg Inc, 1114ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation RParenLoc, Stmt *Body) { 11159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, 1116ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner CondVar, Inc, RParenLoc, Body); 111743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 11181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 111943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new goto statement. 112043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 112143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 112243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1123ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc, 1124ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner LabelDecl *Label) { 112557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label); 112643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 112743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 112843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new indirect goto statement. 112943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 113043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 113143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 113260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, 1133ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation StarLoc, 1134ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner Expr *Target) { 11359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); 113643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 11371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 113843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new return statement. 113943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 114043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 114143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1142ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) { 11439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnReturnStmt(ReturnLoc, Result); 114443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 11451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 114643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new declaration statement. 114743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 114843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 114943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 115060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, 11511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation StartLoc, 115243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation EndLoc) { 1153406c38e8c1f105acfd438f94dfbc17af817aa4a5Richard Smith Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls, NumDecls); 1154406c38e8c1f105acfd438f94dfbc17af817aa4a5Richard Smith return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc); 115543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 11561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1157703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// \brief Build a new inline asm statement. 1158703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// 1159703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// By default, performs semantic analysis to build the new statement. 1160703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// Subclasses may override this routine to provide different behavior. 116160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildAsmStmt(SourceLocation AsmLoc, 1162703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool IsSimple, 1163703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool IsVolatile, 1164703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson unsigned NumOutputs, 1165703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson unsigned NumInputs, 1166ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo **Names, 1167703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson MultiExprArg Constraints, 1168703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson MultiExprArg Exprs, 11699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *AsmString, 1170703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson MultiExprArg Clobbers, 1171703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson SourceLocation RParenLoc, 1172703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool MSAsm) { 1173c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, 1174703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson NumInputs, Names, move(Constraints), 11759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs, AsmString, Clobbers, 1176703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson RParenLoc, MSAsm); 1177703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 11784dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 11798cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier /// \brief Build a new MS style inline asm statement. 11808cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier /// 11818cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier /// By default, performs semantic analysis to build the new statement. 11828cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier /// Subclasses may override this routine to provide different behavior. 11838cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, 11848cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier std::string &AsmString, 11858cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier SourceLocation EndLoc) { 11868cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier return getSema().ActOnMSAsmStmt(AsmLoc, AsmString, EndLoc); 11878cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier } 11888cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier 1189699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett /// \brief Build a new Objective-C \@try statement. 11904dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// 11914dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// By default, performs semantic analysis to build the new statement. 11924dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 119360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, 11949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *TryBody, 11958f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor MultiStmtArg CatchStmts, 11969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Finally) { 11979ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts), 11989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Finally); 11994dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 12004dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 1201be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// \brief Rebuild an Objective-C exception declaration. 1202be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// 1203be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// By default, performs semantic analysis to build the new declaration. 1204be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1205be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, 1206be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TypeSourceInfo *TInfo, QualType T) { 1207ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara return getSema().BuildObjCExceptionDecl(TInfo, T, 1208ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getInnerLocStart(), 1209ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getLocation(), 1210ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getIdentifier()); 1211be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 1212c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1213699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett /// \brief Build a new Objective-C \@catch statement. 1214be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// 1215be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// By default, performs semantic analysis to build the new statement. 1216be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// Subclasses may override this routine to provide different behavior. 121760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, 1218be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor SourceLocation RParenLoc, 1219be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *Var, 12209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Body) { 1221be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, 12229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Var, Body); 1223be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 1224c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1225699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett /// \brief Build a new Objective-C \@finally statement. 12264dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// 12274dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// By default, performs semantic analysis to build the new statement. 12284dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 122960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, 12309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Body) { 12319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); 12324dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 1233c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1234699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett /// \brief Build a new Objective-C \@throw statement. 1235d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor /// 1236d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor /// By default, performs semantic analysis to build the new statement. 1237d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor /// Subclasses may override this routine to provide different behavior. 123860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, 12399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand) { 12409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); 1241d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor } 1242c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1243699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett /// \brief Rebuild the operand to an Objective-C \@synchronized statement. 124407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall /// 124507524039dce5c820f111a1b3f772b4261f004b4aJohn McCall /// By default, performs semantic analysis to build the new statement. 124607524039dce5c820f111a1b3f772b4261f004b4aJohn McCall /// Subclasses may override this routine to provide different behavior. 124707524039dce5c820f111a1b3f772b4261f004b4aJohn McCall ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc, 124807524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Expr *object) { 124907524039dce5c820f111a1b3f772b4261f004b4aJohn McCall return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object); 125007524039dce5c820f111a1b3f772b4261f004b4aJohn McCall } 125107524039dce5c820f111a1b3f772b4261f004b4aJohn McCall 1252699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett /// \brief Build a new Objective-C \@synchronized statement. 12538fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// 12548fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// By default, performs semantic analysis to build the new statement. 12558fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// Subclasses may override this routine to provide different behavior. 125660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, 125707524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Expr *Object, Stmt *Body) { 125807524039dce5c820f111a1b3f772b4261f004b4aJohn McCall return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body); 12598fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor } 1260c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor 1261699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett /// \brief Build a new Objective-C \@autoreleasepool statement. 1262f85e193739c953358c865005855253af4f68a497John McCall /// 1263f85e193739c953358c865005855253af4f68a497John McCall /// By default, performs semantic analysis to build the new statement. 1264f85e193739c953358c865005855253af4f68a497John McCall /// Subclasses may override this routine to provide different behavior. 1265f85e193739c953358c865005855253af4f68a497John McCall StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc, 1266f85e193739c953358c865005855253af4f68a497John McCall Stmt *Body) { 1267f85e193739c953358c865005855253af4f68a497John McCall return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body); 1268f85e193739c953358c865005855253af4f68a497John McCall } 1269990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall 1270990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall /// \brief Build the collection operand to a new Objective-C fast 1271990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall /// enumeration statement. 1272990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall /// 1273990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall /// By default, performs semantic analysis to build the new statement. 1274990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall /// Subclasses may override this routine to provide different behavior. 1275990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall ExprResult RebuildObjCForCollectionOperand(SourceLocation forLoc, 1276990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall Expr *collection) { 1277990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall return getSema().ActOnObjCForCollectionOperand(forLoc, collection); 1278990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall } 1279f85e193739c953358c865005855253af4f68a497John McCall 1280c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// \brief Build a new Objective-C fast enumeration statement. 1281c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// 1282c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// By default, performs semantic analysis to build the new statement. 1283c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// Subclasses may override this routine to provide different behavior. 128460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, 1285f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall SourceLocation LParenLoc, 1286f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *Element, 1287f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Expr *Collection, 1288f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall SourceLocation RParenLoc, 1289f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *Body) { 1290c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, 12919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Element, 12929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Collection, 1293c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor RParenLoc, 12949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body); 1295c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor } 1296c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 129743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new C++ exception declaration. 129843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 129943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new decaration. 130043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1301ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, 1302a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Declarator, 1303ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation StartLoc, 1304ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara SourceLocation IdLoc, 1305ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara IdentifierInfo *Id) { 1306efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor VarDecl *Var = getSema().BuildExceptionDeclaration(0, Declarator, 1307efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor StartLoc, IdLoc, Id); 1308efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor if (Var) 1309efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor getSema().CurContext->addDecl(Var); 1310efdf988611c1eb02770643cd3fabd5df2f579353Douglas Gregor return Var; 131143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 131243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 131343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new C++ catch statement. 131443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 131543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 131643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 131760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, 1318f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall VarDecl *ExceptionDecl, 1319f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *Handler) { 13209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, 13219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Handler)); 132243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 13231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 132443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new C++ try statement. 132543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 132643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 132743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 132860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, 1329f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *TryBlock, 1330f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiStmtArg Handlers) { 13319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers)); 133243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 13331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1334ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// \brief Build a new C++0x range-based for statement. 1335ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// 1336ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// By default, performs semantic analysis to build the new statement. 1337ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// Subclasses may override this routine to provide different behavior. 1338ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc, 1339ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith SourceLocation ColonLoc, 1340ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Stmt *Range, Stmt *BeginEnd, 1341ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Expr *Cond, Expr *Inc, 1342ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Stmt *LoopVar, 1343ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith SourceLocation RParenLoc) { 1344ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd, 1345ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Cond, Inc, LoopVar, RParenLoc); 1346ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 1347ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 1348ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor /// \brief Build a new C++0x range-based for statement. 1349ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor /// 1350ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor /// By default, performs semantic analysis to build the new statement. 1351ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1352ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc, 1353ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor bool IsIfExists, 1354ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 1355ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor DeclarationNameInfo NameInfo, 1356ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor Stmt *Nested) { 1357ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists, 1358ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor QualifierLoc, NameInfo, Nested); 1359ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor } 1360ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 1361ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// \brief Attach body to a C++0x range-based for statement. 1362ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// 1363ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// By default, performs semantic analysis to finish the new statement. 1364ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith /// Subclasses may override this routine to provide different behavior. 1365ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) { 1366ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return getSema().FinishCXXForRangeStmt(ForRange, Body); 1367ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith } 1368ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 136928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult RebuildSEHTryStmt(bool IsCXXTry, 137028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley SourceLocation TryLoc, 137128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *TryBlock, 137228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Handler) { 137328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getSema().ActOnSEHTryBlock(IsCXXTry,TryLoc,TryBlock,Handler); 137428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 137528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 137628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult RebuildSEHExceptStmt(SourceLocation Loc, 137728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Expr *FilterExpr, 137828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block) { 137928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getSema().ActOnSEHExceptBlock(Loc,FilterExpr,Block); 138028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 138128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 138228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, 138328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Stmt *Block) { 138428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getSema().ActOnSEHFinallyBlock(Loc,Block); 138528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley } 138628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 1387b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression that references a declaration. 1388b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1389b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1390b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 139160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, 1392f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall LookupResult &R, 1393f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall bool RequiresADL) { 1394f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); 1395f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 1396f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 1397f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 1398f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// \brief Build a new expression that references a declaration. 1399f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// 1400f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// By default, performs semantic analysis to build the new expression. 1401f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// Subclasses may override this routine to provide different behavior. 140240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc, 1403f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall ValueDecl *VD, 1404f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall const DeclarationNameInfo &NameInfo, 1405f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TemplateArgumentListInfo *TemplateArgs) { 1406a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor CXXScopeSpec SS; 140740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor SS.Adopt(QualifierLoc); 1408dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 1409dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // FIXME: loses template args. 14102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 14112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); 1412b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 14131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1414b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression in parentheses. 14151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1416b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1417b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 141860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, 1419b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParen) { 14209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnParenExpr(LParen, RParen, SubExpr); 1421b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1422b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1423a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief Build a new pseudo-destructor expression. 14241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1425a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1426a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// Subclasses may override this routine to provide different behavior. 142760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, 1428f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SourceLocation OperatorLoc, 1429f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor bool isArrow, 1430f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor CXXScopeSpec &SS, 1431f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor TypeSourceInfo *ScopeType, 1432f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SourceLocation CCLoc, 1433f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SourceLocation TildeLoc, 1434a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed); 14351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1436b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new unary operator expression. 14371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1438b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1439b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 144060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildUnaryOperator(SourceLocation OpLoc, 14412de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc, 14429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr) { 14439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); 1444b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 14451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Build a new builtin offsetof expression. 14478ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// 14488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// By default, performs semantic analysis to build the new expression. 14498ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// Subclasses may override this routine to provide different behavior. 145060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, 14518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *Type, 1452f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::OffsetOfComponent *Components, 14538ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComponents, 14548ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) { 14558ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, 14568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor NumComponents, RParenLoc); 14578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1458c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1459f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne /// \brief Build a new sizeof, alignof or vec_step expression with a 1460f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne /// type argument. 14611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1462b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1463b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1464f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo, 1465f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceLocation OpLoc, 1466f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTrait ExprKind, 1467f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceRange R) { 1468f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R); 1469b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1470b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1471f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne /// \brief Build a new sizeof, alignof or vec step expression with an 1472f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne /// expression argument. 14731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1474b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1475b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1476f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc, 1477f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTrait ExprKind, 1478f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne SourceRange R) { 147960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 1480e72c55b9a11be9f00fa3f66f7ad6b73b2814e963Chandler Carruth = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind); 1481b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 1482f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 14831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1484b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return move(Result); 1485b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 14861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1487b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new array subscript expression. 14881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1489b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1490b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 149160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildArraySubscriptExpr(Expr *LHS, 1492b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LBracketLoc, 14939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *RHS, 1494b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RBracketLoc) { 14959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, 14969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LBracketLoc, RHS, 1497b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RBracketLoc); 1498b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1499b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1500b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new call expression. 15011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1502b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1503b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 150460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, 1505b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg Args, 1506e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne SourceLocation RParenLoc, 1507e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne Expr *ExecConfig = 0) { 15089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, 1509e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne move(Args), RParenLoc, ExecConfig); 1510b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1511b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1512b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new member access expression. 15131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1514b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1515b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 151660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, 1517f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall bool isArrow, 151840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 1519e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 1520f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const DeclarationNameInfo &MemberNameInfo, 1521f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ValueDecl *Member, 1522f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall NamedDecl *FoundDecl, 1523d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *ExplicitTemplateArgs, 1524f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall NamedDecl *FirstQualifierInScope) { 15259138b4e96429cbaae00c52c15c960f72b6645088Richard Smith ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base, 15269138b4e96429cbaae00c52c15c960f72b6645088Richard Smith isArrow); 1527d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson if (!Member->getDeclName()) { 1528f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // We have a reference to an unnamed field. This is always the 1529f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // base of an anonymous struct/union member access, i.e. the 1530f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // field is always of record type. 153140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!"); 1532f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall assert(Member->getType()->isRecordType() && 1533f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall "unnamed member not of record type?"); 15341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 15359138b4e96429cbaae00c52c15c960f72b6645088Richard Smith BaseResult = 15369138b4e96429cbaae00c52c15c960f72b6645088Richard Smith getSema().PerformObjectMemberConversion(BaseResult.take(), 1537429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley QualifierLoc.getNestedNameSpecifier(), 1538429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley FoundDecl, Member); 1539429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (BaseResult.isInvalid()) 1540f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 1541429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley Base = BaseResult.take(); 1542f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); 15431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump MemberExpr *ME = 15449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall new (getSema().Context) MemberExpr(Base, isArrow, 15452577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Member, MemberNameInfo, 1546f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall cast<FieldDecl>(Member)->getType(), 1547f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall VK, OK_Ordinary); 1548d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson return getSema().Owned(ME); 1549d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson } 15501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 155183f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor CXXScopeSpec SS; 155240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor SS.Adopt(QualifierLoc); 155383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 1554429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley Base = BaseResult.take(); 15559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall QualType BaseType = Base->getType(); 1556aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 15576bb8017bb9e828d118e15e59d71c66bba323c364John McCall // FIXME: this involves duplicating earlier analysis in a lot of 15586bb8017bb9e828d118e15e59d71c66bba323c364John McCall // cases; we should avoid this when possible. 15592577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); 15606bb8017bb9e828d118e15e59d71c66bba323c364John McCall R.addDecl(FoundDecl); 1561c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R.resolveKind(); 1562c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 15639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, 1564e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, TemplateKWLoc, 1565e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara FirstQualifierInScope, 1566c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R, ExplicitTemplateArgs); 1567b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1569b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new binary operator expression. 15701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1571b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1572b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 157360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildBinaryOperator(SourceLocation OpLoc, 15742de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc, 15759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *LHS, Expr *RHS) { 15769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); 1577b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1578b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1579b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new conditional operator expression. 15801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1581b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1582b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 158360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildConditionalOperator(Expr *Cond, 158456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation QuestionLoc, 158556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *LHS, 158656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall SourceLocation ColonLoc, 158756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall Expr *RHS) { 15889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, 15899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS, RHS); 1590b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1591b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1592b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C-style cast expression. 15931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1594b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1595b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 159660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, 15979d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1598b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc, 15999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr) { 1600b042fdfc9460e0018276412257e3c3226f9ea96eJohn McCall return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, 16019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr); 1602b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1604b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new compound literal expression. 16051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1606b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1607b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 160860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, 160942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *TInfo, 1610b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc, 16119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Init) { 161242f56b50062cd3b3c6b23fdb9053578ae9145664John McCall return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, 16139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init); 1614b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1616b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new extended vector element access expression. 16171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1618b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1619b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 162060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildExtVectorElementExpr(Expr *Base, 1621b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 1622b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation AccessorLoc, 1623b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor IdentifierInfo &Accessor) { 1624aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 1625129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall CXXScopeSpec SS; 16262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); 16279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, Base->getType(), 1628129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall OpLoc, /*IsArrow*/ false, 1629e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, SourceLocation(), 1630e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /*FirstQualifierInScope*/ 0, 16312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 1632129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /* TemplateArgs */ 0); 1633b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1635b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new initializer list expression. 16361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1637b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1638b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 163960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildInitList(SourceLocation LBraceLoc, 1640c8fc90a854b4ccba21c85884676a80334159dd94John McCall MultiExprArg Inits, 1641c8fc90a854b4ccba21c85884676a80334159dd94John McCall SourceLocation RBraceLoc, 1642c8fc90a854b4ccba21c85884676a80334159dd94John McCall QualType ResultTy) { 164360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 1644e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); 1645e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor if (Result.isInvalid() || ResultTy->isDependentType()) 1646e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor return move(Result); 1647c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1648e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor // Patch in the result type we were given, which may have been computed 1649e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor // when the initial InitListExpr was built. 1650e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); 1651e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor ILE->setType(ResultTy); 1652e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor return move(Result); 1653b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1655b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new designated initializer expression. 16561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1657b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1658b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 165960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildDesignatedInitExpr(Designation &Desig, 1660b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg ArrayExprs, 1661b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation EqualOrColonLoc, 1662b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool GNUSyntax, 16639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Init) { 166460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 1665b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, 16669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init); 1667b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 1668f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 16691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1670b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.release(); 1671b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return move(Result); 1672b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1674b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new value-initialized expression. 16751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds the implicit value initialization without performing 1677b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// any semantic analysis. Subclasses may override this routine to provide 1678b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// different behavior. 167960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildImplicitValueInitExpr(QualType T) { 1680b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); 1681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1683b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new \c va_arg expression. 16841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1685b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1686b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 168760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, 16889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, TypeSourceInfo *TInfo, 16892cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara SourceLocation RParenLoc) { 16902cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara return getSema().BuildVAArgExpr(BuiltinLoc, 16919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, TInfo, 16922cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara RParenLoc); 1693b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1694b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1695b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression list in parentheses. 16961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1697b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1698b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 169960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildParenListExpr(SourceLocation LParenLoc, 17005b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl MultiExprArg SubExprs, 17015b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl SourceLocation RParenLoc) { 17025b9cc5df25c2198f270dd1d5c438fdce70d4051dSebastian Redl return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, move(SubExprs)); 1703b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1705b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new address-of-label expression. 17061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 17071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, performs semantic analysis, using the name of the label 1708b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// rather than attempting to map the label statement itself. 1709b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 171060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, 1711ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner SourceLocation LabelLoc, LabelDecl *Label) { 171257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label); 1713b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1715b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new GNU statement expression. 17161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1717b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1718b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 171960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildStmtExpr(SourceLocation LParenLoc, 17209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *SubStmt, 1721b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 17229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); 1723b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1725b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new __builtin_choose_expr expression. 1726b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1727b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1728b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 172960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, 17309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Cond, Expr *LHS, Expr *RHS, 1731b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1732b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.ActOnChooseExpr(BuiltinLoc, 17339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond, LHS, RHS, 1734b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 1735b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1737f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// \brief Build a new generic selection expression. 1738f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// 1739f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// By default, performs semantic analysis to build the new expression. 1740f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne /// Subclasses may override this routine to provide different behavior. 1741f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc, 1742f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation DefaultLoc, 1743f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne SourceLocation RParenLoc, 1744f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr *ControllingExpr, 1745f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo **Types, 1746f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne Expr **Exprs, 1747f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne unsigned NumAssocs) { 1748f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, 1749f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ControllingExpr, Types, Exprs, 1750f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne NumAssocs); 1751f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 1752f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 1753b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new overloaded operator call expression. 1754b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1755b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1756b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// The semantic analysis provides the behavior of template instantiation, 1757b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// copying with transformations that turn what looks like an overloaded 17581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// operator call into a use of a builtin operator, performing 1759b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// argument-dependent lookup, etc. Subclasses may override this routine to 1760b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// provide different behavior. 176160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, 1762b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 17639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Callee, 17649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *First, 17659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Second); 17661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 17671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new C++ "named" cast expression, such as static_cast or 1768b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// reinterpret_cast. 1769b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1770b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, this routine dispatches to one of the more-specific routines 17711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). 1772b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 177360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, 1774b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Stmt::StmtClass Class, 1775b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 17769d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1777b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1778b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 17799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1780b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1781b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor switch (Class) { 1782b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXStaticCastExprClass: 17839d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, 17841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 1786b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1787b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXDynamicCastExprClass: 17889d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, 17891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 17911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1792b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXReinterpretCastExprClass: 17939d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, 17941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 17959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, 1796b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 17971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1798b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXConstCastExprClass: 17999d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, 18001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 18019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 18021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1803b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor default: 1804b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Invalid C++ named cast"); 1805b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1806b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1808b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ static_cast expression. 1809b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1810b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1811b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 181260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, 1813b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 18149d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1815b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1816b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 18179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1818b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1819c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, 18209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1821c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1822c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1823b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1824b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1825b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ dynamic_cast expression. 1826b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1827b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1828b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 182960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, 1830b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 18319d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1832b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1833b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 18349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1835b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1836c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, 18379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1838c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1839c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1840b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1841b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1842b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ reinterpret_cast expression. 1843b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1844b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1845b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 184660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, 1847b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 18489d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1849b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1850b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 18519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1852b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1853c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, 18549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1855c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1856c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1857b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1858b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1859b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ const_cast expression. 1860b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1861b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1862b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 186360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc, 1864b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 18659d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1866b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1867b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 18689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1869b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1870c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, 18719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1872c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1873c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1874b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1876b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ functional-style cast expression. 1877b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1878b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1879b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1880ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, 1881ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 1882ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor Expr *Sub, 1883ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 1884ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, 1885f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiExprArg(&Sub, 1), 1886b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 1887b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1889b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ typeid(type) expression. 1890b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1891b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1892b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 189360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, 189457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor SourceLocation TypeidLoc, 189557fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TypeSourceInfo *Operand, 1896b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1897c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, 189857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor RParenLoc); 1899b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 19001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 190101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 1902b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ typeid(expr) expression. 1903b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1904b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1905b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 190660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, 190757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor SourceLocation TypeidLoc, 19089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand, 1909b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 19109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, 191157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor RParenLoc); 19121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 19131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 191401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Build a new C++ __uuidof(type) expression. 191501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// 191601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// By default, performs semantic analysis to build the new expression. 191701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// Subclasses may override this routine to provide different behavior. 191801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, 191901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation TypeidLoc, 192001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TypeSourceInfo *Operand, 192101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation RParenLoc) { 192201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, 192301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet RParenLoc); 192401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 192501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 192601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Build a new C++ __uuidof(expr) expression. 192701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// 192801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// By default, performs semantic analysis to build the new expression. 192901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// Subclasses may override this routine to provide different behavior. 193001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, 193101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation TypeidLoc, 193201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Expr *Operand, 193301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation RParenLoc) { 193401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, 193501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet RParenLoc); 193601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 193701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 1938b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "this" expression. 1939b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1940b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds a new "this" expression without performing any 19411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// semantic analysis. Subclasses may override this routine to provide 1942b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// different behavior. 194360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, 1944ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor QualType ThisType, 1945ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor bool isImplicit) { 1946b69b42c55d56815bab62991bf839cdb41634d3afEli Friedman getSema().CheckCXXThisCapture(ThisLoc); 1947b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getSema().Owned( 1948828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, 1949828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor isImplicit)); 1950b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1951b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1952b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ throw expression. 1953b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1954b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1955b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1956bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub, 1957bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor bool IsThrownVariableInScope) { 1958bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope); 1959b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1960b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1961b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ default-argument expression. 1962b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1963b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds a new default-argument expression, which does not 1964b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// require any semantic analysis. Subclasses may override this routine to 1965b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// provide different behavior. 196660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, 1967036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor ParmVarDecl *Param) { 1968036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, 1969036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor Param)); 1970b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1971b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1972b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ zero-initialization expression. 1973b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1974b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1975b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1976ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, 1977ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 1978ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 1979ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, 19801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump MultiExprArg(getSema(), 0, 0), 1981ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor RParenLoc); 1982b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 19831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1984b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "new" expression. 1985b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1986b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1987b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 198860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXNewExpr(SourceLocation StartLoc, 19891bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor bool UseGlobal, 19901bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation PlacementLParen, 19911bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor MultiExprArg PlacementArgs, 19921bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation PlacementRParen, 19931bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceRange TypeIdParens, 19941bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor QualType AllocatedType, 19951bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *AllocatedTypeInfo, 19961bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor Expr *ArraySize, 19972aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl SourceRange DirectInitRange, 19982aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl Expr *Initializer) { 19991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getSema().BuildCXXNew(StartLoc, UseGlobal, 2000b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor PlacementLParen, 2001b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(PlacementArgs), 2002b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor PlacementRParen, 20034bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor TypeIdParens, 20041bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocatedType, 20051bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocatedTypeInfo, 20069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ArraySize, 20072aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl DirectInitRange, 20082aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl Initializer); 2009b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 20101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2011b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "delete" expression. 2012b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2013b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2014b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 201560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, 2016b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool IsGlobalDelete, 2017b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool IsArrayForm, 20189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand) { 2019b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, 20209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Operand); 2021b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 20221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2023b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new unary type trait expression. 2024b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2025b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2026b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 202760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, 20283d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor SourceLocation StartLoc, 20293d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *T, 20303d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor SourceLocation RParenLoc) { 20313d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); 2032b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2033b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 20346ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// \brief Build a new binary type trait expression. 20356ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// 20366ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// By default, performs semantic analysis to build the new expression. 20376ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// Subclasses may override this routine to provide different behavior. 20386ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, 20396ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation StartLoc, 20406ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *LhsT, 20416ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *RhsT, 20426ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation RParenLoc) { 20436ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); 20446ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 20456ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 20464ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// \brief Build a new type trait expression. 20474ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// 20484ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// By default, performs semantic analysis to build the new expression. 20494ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor /// Subclasses may override this routine to provide different behavior. 20504ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ExprResult RebuildTypeTrait(TypeTrait Trait, 20514ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor SourceLocation StartLoc, 20524ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ArrayRef<TypeSourceInfo *> Args, 20534ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor SourceLocation RParenLoc) { 20544ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc); 20554ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 20564ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 205721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// \brief Build a new array type trait expression. 205821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// 205921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// By default, performs semantic analysis to build the new expression. 206021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley /// Subclasses may override this routine to provide different behavior. 206121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait, 206221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SourceLocation StartLoc, 206321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *TSInfo, 206421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley Expr *DimExpr, 206521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SourceLocation RParenLoc) { 206621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc); 206721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 206821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 2069552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// \brief Build a new expression trait expression. 2070552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// 2071552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// By default, performs semantic analysis to build the new expression. 2072552622067dc45013d240f73952fece703f5e63bdJohn Wiegley /// Subclasses may override this routine to provide different behavior. 2073552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExprResult RebuildExpressionTrait(ExpressionTrait Trait, 2074552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation StartLoc, 2075552622067dc45013d240f73952fece703f5e63bdJohn Wiegley Expr *Queried, 2076552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SourceLocation RParenLoc) { 2077552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc); 2078552622067dc45013d240f73952fece703f5e63bdJohn Wiegley } 2079552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 20801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new (previously unresolved) declaration reference 2081b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// expression. 2082b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2083b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2084b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 208500cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor ExprResult RebuildDependentScopeDeclRefExpr( 208600cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc, 2087e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 20882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 2089f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall const TemplateArgumentListInfo *TemplateArgs) { 2090b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXScopeSpec SS; 209100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor SS.Adopt(QualifierLoc); 2092f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 20939d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara if (TemplateArgs || TemplateKWLoc.isValid()) 2094e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, 20959d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara NameInfo, TemplateArgs); 2096f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 20979d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo); 2098b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2099b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2100b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new template-id expression. 2101b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2102b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2103b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 210460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, 2105e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 2106e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara LookupResult &R, 2107e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara bool RequiresADL, 21089d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara const TemplateArgumentListInfo *TemplateArgs) { 2109e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL, 2110e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateArgs); 2111b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2112b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2113b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 2114b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2115b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2116b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 211760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXConstructExpr(QualType T, 21187cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara SourceLocation Loc, 21197cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara CXXConstructorDecl *Constructor, 21207cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool IsElidable, 21217cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara MultiExprArg Args, 21227cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool HadMultipleCandidates, 21237cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara bool RequiresZeroInit, 2124428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth CXXConstructExpr::ConstructionKind ConstructKind, 21257cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara SourceRange ParenRange) { 2126ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> ConvertedArgs(SemaRef); 2127c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, 21284411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor ConvertedArgs)) 2129f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2130c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 21314411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, 21328c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor move_arg(ConvertedArgs), 21337cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara HadMultipleCandidates, 2134428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth RequiresZeroInit, ConstructKind, 2135428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth ParenRange); 2136b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2137b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2138b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 2139b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2140b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2141b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 2142ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, 2143ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 2144ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor MultiExprArg Args, 2145ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 2146ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, 2147b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LParenLoc, 2148b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(Args), 2149b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 2150b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2151b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2152b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 2153b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2154b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2155b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 2156ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, 2157ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 2158ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor MultiExprArg Args, 2159ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 2160ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, 2161b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LParenLoc, 2162b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(Args), 2163b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 2164b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 21651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2166b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new member reference expression. 2167b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2168b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2169b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 217060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, 21717c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualType BaseType, 21727c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor bool IsArrow, 21737c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor SourceLocation OperatorLoc, 21747c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc, 2175e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 2176129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall NamedDecl *FirstQualifierInScope, 21772577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &MemberNameInfo, 2178129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall const TemplateArgumentListInfo *TemplateArgs) { 2179b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXScopeSpec SS; 21807c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor SS.Adopt(QualifierLoc); 21811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, 2183aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OperatorLoc, IsArrow, 2184e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, TemplateKWLoc, 2185e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara FirstQualifierInScope, 21862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberNameInfo, 21872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TemplateArgs); 2188b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 2189b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2190129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Build a new member reference expression. 21913b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// 21923b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// By default, performs semantic analysis to build the new expression. 21933b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// Subclasses may override this routine to provide different behavior. 21949138b4e96429cbaae00c52c15c960f72b6645088Richard Smith ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType, 21959138b4e96429cbaae00c52c15c960f72b6645088Richard Smith SourceLocation OperatorLoc, 21969138b4e96429cbaae00c52c15c960f72b6645088Richard Smith bool IsArrow, 21979138b4e96429cbaae00c52c15c960f72b6645088Richard Smith NestedNameSpecifierLoc QualifierLoc, 2198e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc, 21999138b4e96429cbaae00c52c15c960f72b6645088Richard Smith NamedDecl *FirstQualifierInScope, 22009138b4e96429cbaae00c52c15c960f72b6645088Richard Smith LookupResult &R, 2201129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall const TemplateArgumentListInfo *TemplateArgs) { 22023b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor CXXScopeSpec SS; 22034c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor SS.Adopt(QualifierLoc); 22041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, 2206aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OperatorLoc, IsArrow, 2207e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, TemplateKWLoc, 2208e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara FirstQualifierInScope, 2209c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R, TemplateArgs); 22103b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 22111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22122e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// \brief Build a new noexcept expression. 22132e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// 22142e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// By default, performs semantic analysis to build the new expression. 22152e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// Subclasses may override this routine to provide different behavior. 22162e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { 22172e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); 22182e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl } 22192e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 2220ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Build a new expression to compute the length of a parameter pack. 2221ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, 2222ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation PackLoc, 2223ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation RParenLoc, 2224089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor llvm::Optional<unsigned> Length) { 2225089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor if (Length) 2226089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), 2227089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor OperatorLoc, Pack, PackLoc, 2228089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor RParenLoc, *Length); 2229089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor 2230ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), 2231ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor OperatorLoc, Pack, PackLoc, 2232089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor RParenLoc); 2233ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor } 2234ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2235eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard /// \brief Build a new Objective-C boxed expression. 2236eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard /// 2237eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard /// By default, performs semantic analysis to build the new expression. 2238eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard /// Subclasses may override this routine to provide different behavior. 2239eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) { 2240eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard return getSema().BuildObjCBoxedExpr(SR, ValueExpr); 2241eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard } 2242eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard 2243ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Build a new Objective-C array literal. 2244ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// 2245ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// By default, performs semantic analysis to build the new expression. 2246ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// Subclasses may override this routine to provide different behavior. 2247ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult RebuildObjCArrayLiteral(SourceRange Range, 2248ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr **Elements, unsigned NumElements) { 2249ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return getSema().BuildObjCArrayLiteral(Range, 2250ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek MultiExprArg(Elements, NumElements)); 2251ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 2252ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2253ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB, 2254ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expr *Base, Expr *Key, 2255ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *getterMethod, 2256ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCMethodDecl *setterMethod) { 2257ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return getSema().BuildObjCSubscriptExpression(RB, Base, Key, 2258ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek getterMethod, setterMethod); 2259ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 2260ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2261ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// \brief Build a new Objective-C dictionary literal. 2262ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// 2263ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// By default, performs semantic analysis to build the new expression. 2264ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /// Subclasses may override this routine to provide different behavior. 2265ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult RebuildObjCDictionaryLiteral(SourceRange Range, 2266ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCDictionaryElement *Elements, 2267ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek unsigned NumElements) { 2268ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements); 2269ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 2270ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 2271699c9044c7d53a2774d0dd261a6901dd2c4a545fJames Dennett /// \brief Build a new Objective-C \@encode expression. 2272b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2273b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2274b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 227560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, 227681d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *EncodeTypeInfo, 2277b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 227881d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, 2279b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc)); 22801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 2281b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 228292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /// \brief Build a new Objective-C class message. 228360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, 228492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Selector Sel, 2285207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelectorLocs, 228692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ObjCMethodDecl *Method, 2287c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation LBracLoc, 228892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor MultiExprArg Args, 228992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor SourceLocation RBracLoc) { 229092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return SemaRef.BuildClassMessage(ReceiverTypeInfo, 229192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ReceiverTypeInfo->getType(), 229292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /*SuperLoc=*/SourceLocation(), 2293207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Sel, Method, LBracLoc, SelectorLocs, 2294f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis RBracLoc, move(Args)); 229592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 229692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 229792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /// \brief Build a new Objective-C instance message. 229860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCMessageExpr(Expr *Receiver, 229992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Selector Sel, 2300207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis ArrayRef<SourceLocation> SelectorLocs, 230192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ObjCMethodDecl *Method, 2302c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation LBracLoc, 230392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor MultiExprArg Args, 230492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor SourceLocation RBracLoc) { 23059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildInstanceMessage(Receiver, 23069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Receiver->getType(), 230792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /*SuperLoc=*/SourceLocation(), 2308207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis Sel, Method, LBracLoc, SelectorLocs, 2309f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis RBracLoc, move(Args)); 231092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 231192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 2312f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// \brief Build a new Objective-C ivar reference expression. 2313f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// 2314f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// By default, performs semantic analysis to build the new expression. 2315f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// Subclasses may override this routine to provide different behavior. 231660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, 2317f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor SourceLocation IvarLoc, 2318f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor bool IsArrow, bool IsFreeIvar) { 2319f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // FIXME: We lose track of the IsFreeIvar bit. 2320f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor CXXScopeSpec SS; 2321429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Base = getSema().Owned(BaseArg); 2322f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, 2323f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Sema::LookupMemberName); 232460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2325f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FIME:*/IvarLoc, 2326d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, 2327ad00b7705f9bbee81beeac428e7c6587734ab5a6John McCall false); 2328429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Result.isInvalid() || Base.isInvalid()) 2329f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2330c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2331f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Result.get()) 2332f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor return move(Result); 2333c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2334429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), 2335e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /*FIXME:*/IvarLoc, IsArrow, 2336e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, SourceLocation(), 2337f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FirstQualifierInScope=*/0, 2338c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt R, 2339f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*TemplateArgs=*/0); 2340f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor } 2341e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor 2342e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// \brief Build a new Objective-C property reference expression. 2343e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// 2344e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2345e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 234660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, 23473c3b7f90a863af43fa63043d396553ecf205351cJohn McCall ObjCPropertyDecl *Property, 23483c3b7f90a863af43fa63043d396553ecf205351cJohn McCall SourceLocation PropertyLoc) { 2349e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor CXXScopeSpec SS; 2350429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Base = getSema().Owned(BaseArg); 2351e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, 2352e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor Sema::LookupMemberName); 2353e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor bool IsArrow = false; 235460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2355e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*FIME:*/PropertyLoc, 2356d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, false); 2357429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Result.isInvalid() || Base.isInvalid()) 2358f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2359c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2360e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (Result.get()) 2361e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor return move(Result); 2362c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2363429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), 2364c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /*FIXME:*/PropertyLoc, IsArrow, 2365e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, SourceLocation(), 2366e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*FirstQualifierInScope=*/0, 2367c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt R, 2368e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*TemplateArgs=*/0); 2369e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor } 2370c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 237112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// \brief Build a new Objective-C property reference expression. 23729cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor /// 23739cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor /// By default, performs semantic analysis to build the new expression. 237412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// Subclasses may override this routine to provide different behavior. 237512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, 237612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *Getter, 237712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *Setter, 237812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation PropertyLoc) { 237912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // Since these expressions can only be value-dependent, we do not 238012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // need to perform semantic analysis again. 238112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return Owned( 238212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, 238312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall VK_LValue, OK_ObjCProperty, 238412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall PropertyLoc, Base)); 23859cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor } 23869cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor 2387f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// \brief Build a new Objective-C "isa" expression. 2388f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// 2389f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// By default, performs semantic analysis to build the new expression. 2390f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// Subclasses may override this routine to provide different behavior. 239160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, 2392f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor bool IsArrow) { 2393f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor CXXScopeSpec SS; 2394429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Base = getSema().Owned(BaseArg); 2395f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, 2396f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Sema::LookupMemberName); 239760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2398f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FIME:*/IsaLoc, 2399d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, false); 2400429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Result.isInvalid() || Base.isInvalid()) 2401f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2402c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2403f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Result.get()) 2404f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor return move(Result); 2405c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2406429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return getSema().BuildMemberReferenceExpr(Base.get(), Base.get()->getType(), 2407e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /*FIXME:*/IsaLoc, IsArrow, 2408e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, SourceLocation(), 2409f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FirstQualifierInScope=*/0, 2410c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt R, 2411f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*TemplateArgs=*/0); 2412f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor } 2413c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2414b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new shuffle vector expression. 2415b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2416b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2417b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 241860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, 2419f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall MultiExprArg SubExprs, 2420f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation RParenLoc) { 2421b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Find the declaration for __builtin_shufflevector 24221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const IdentifierInfo &Name 2423b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.Context.Idents.get("__builtin_shufflevector"); 2424b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); 2425b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); 2426b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); 24271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2428b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Build a reference to the __builtin_shufflevector builtin 2429b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); 2430429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult Callee 2431f4b88a45902af1802a1cb42ba48b1c474474f228John McCall = SemaRef.Owned(new (SemaRef.Context) DeclRefExpr(Builtin, false, 2432f4b88a45902af1802a1cb42ba48b1c474474f228John McCall Builtin->getType(), 2433429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley VK_LValue, BuiltinLoc)); 2434429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley Callee = SemaRef.UsualUnaryConversions(Callee.take()); 2435429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley if (Callee.isInvalid()) 2436429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return ExprError(); 24371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Build the CallExpr 2439b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor unsigned NumSubExprs = SubExprs.size(); 2440b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Expr **Subs = (Expr **)SubExprs.release(); 2441429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley ExprResult TheCall = SemaRef.Owned( 2442429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley new (SemaRef.Context) CallExpr(SemaRef.Context, Callee.take(), 2443b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Subs, NumSubExprs, 24445291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor Builtin->getCallResultType(), 2445f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr::getValueKindForType(Builtin->getResultType()), 2446429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley RParenLoc)); 24471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2448b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Type-check the __builtin_shufflevector expression. 2449429bb276991ff2dbc7c5b438828b9b7737cb15ebJohn Wiegley return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.take())); 2450b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 245143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 24528491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \brief Build a new template argument pack expansion. 24538491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 24548491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// By default, performs semantic analysis to build a new pack expansion 24558491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// for a template argument. Subclasses may override this routine to provide 24568491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// different behavior. 24578491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, 2458cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor SourceLocation EllipsisLoc, 2459cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions) { 24608491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor switch (Pattern.getArgument().getKind()) { 24617a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor case TemplateArgument::Expression: { 24627a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor ExprResult Result 246367fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor = getSema().CheckPackExpansion(Pattern.getSourceExpression(), 246467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor EllipsisLoc, NumExpansions); 24657a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor if (Result.isInvalid()) 24667a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor return TemplateArgumentLoc(); 24677a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor 24687a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor return TemplateArgumentLoc(Result.get(), Result.get()); 24697a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor } 2470dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 24718491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Template: 2472a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor return TemplateArgumentLoc(TemplateArgument( 2473a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor Pattern.getArgument().getAsTemplate(), 24742be29f423acad3bbe39099a78db2805acb5bdf17Douglas Gregor NumExpansions), 2475b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Pattern.getTemplateQualifierLoc(), 2476a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor Pattern.getTemplateNameLoc(), 2477a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor EllipsisLoc); 24788491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 24798491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Null: 24808491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Integral: 24818491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Declaration: 24828491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Pack: 2483a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 24848491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor llvm_unreachable("Pack expansion pattern has no parameter packs"); 24858491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 24868491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Type: 24878491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (TypeSourceInfo *Expansion 24888491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), 2489cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor EllipsisLoc, 2490cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions)) 24918491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), 24928491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Expansion); 24938491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor break; 24948491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 24958491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 24968491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return TemplateArgumentLoc(); 24978491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 24988491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 2499dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// \brief Build a new expression pack expansion. 2500dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// 2501dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// By default, performs semantic analysis to build a new pack expansion 2502dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// for an expression. Subclasses may override this routine to provide 2503dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// different behavior. 250467fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc, 250567fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> NumExpansions) { 250667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions); 2507dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2508dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 2509dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman /// \brief Build a new atomic operation expression. 2510dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman /// 2511dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman /// By default, performs semantic analysis to build the new expression. 2512dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman /// Subclasses may override this routine to provide different behavior. 2513dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc, 2514dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman MultiExprArg SubExprs, 2515dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman QualType RetTy, 2516dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman AtomicExpr::AtomicOp Op, 2517dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman SourceLocation RParenLoc) { 2518dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman // Just create the expression; there is not any interesting semantic 2519dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman // analysis here because we can't actually build an AtomicExpr until 2520dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman // we are sure it is semantically sound. 2521dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman unsigned NumSubExprs = SubExprs.size(); 2522dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman Expr **Subs = (Expr **)SubExprs.release(); 2523dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman return new (SemaRef.Context) AtomicExpr(BuiltinLoc, Subs, 2524dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman NumSubExprs, RetTy, Op, 2525dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman RParenLoc); 2526dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman } 2527dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 252843fed0de4f5bc189e45562491f83d5193eb8dac0John McCallprivate: 2529c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TypeLoc TransformTypeInObjectScope(TypeLoc TL, 2530c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType, 2531c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *FirstQualifierInScope, 2532c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor CXXScopeSpec &SS); 2533b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 2534b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo, 2535b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor QualType ObjectType, 2536b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor NamedDecl *FirstQualifierInScope, 2537b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor CXXScopeSpec &SS); 2538577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}; 2539b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 254043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 254160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { 254243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!S) 254343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return SemaRef.Owned(S); 25441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 254543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor switch (S->getStmtClass()) { 254643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor case Stmt::NoStmtClass: break; 25471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 254843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform individual statement nodes 254943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) \ 255043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); 255163c00d7f35fa060c0a446c9df3a4402d9c7757feJohn McCall#define ABSTRACT_STMT(Node) 255243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) 25534bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 25541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 255543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform expressions by calling TransformExpr. 255643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) 25577381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 255843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) case Stmt::Node##Class: 25594bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 256043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor { 256160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); 256243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (E.isInvalid()) 2563f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 25641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take())); 256643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 25671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 25681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25693fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 257043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 25711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2573670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregortemplate<typename Derived> 257460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { 2575b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!E) 2576b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.Owned(E); 2577b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2578b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor switch (E->getStmtClass()) { 2579b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::NoStmtClass: break; 2580b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define STMT(Node, Parent) case Stmt::Node##Class: break; 25817381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 2582b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent) \ 2583454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); 25844bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 25851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 25861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 25873fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 2588657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor} 2589657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor 2590657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregortemplate<typename Derived> 2591aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorbool TreeTransform<Derived>::TransformExprs(Expr **Inputs, 2592aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor unsigned NumInputs, 2593aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool IsCall, 2594686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<Expr *> &Outputs, 2595aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool *ArgChanged) { 2596aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor for (unsigned I = 0; I != NumInputs; ++I) { 2597aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor // If requested, drop call arguments that need to be dropped. 2598aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (IsCall && getDerived().DropCallArgument(Inputs[I])) { 2599aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (ArgChanged) 2600aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor *ArgChanged = true; 2601aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2602aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor break; 2603aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 2604aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2605dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { 2606dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Expr *Pattern = Expansion->getPattern(); 2607dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2608686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<UnexpandedParameterPack, 2> Unexpanded; 2609dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 2610dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 2611dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2612dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // Determine whether the set of unexpanded parameter packs can and should 2613dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // be expanded. 2614dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor bool Expand = true; 2615d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 261667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> OrigNumExpansions 261767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor = Expansion->getNumExpansions(); 261867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; 2619dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), 2620dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Pattern->getSourceRange(), 2621a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 2622d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Expand, RetainExpansion, 2623d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) 2624dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2625dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2626dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (!Expand) { 2627dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // The transform has determined that we should perform a simple 2628dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // transformation on the pack expansion, producing another pack 2629dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // expansion. 2630dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 2631dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult OutPattern = getDerived().TransformExpr(Pattern); 2632dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (OutPattern.isInvalid()) 2633dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2634dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2635dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), 263667fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor Expansion->getEllipsisLoc(), 263767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor NumExpansions); 2638dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (Out.isInvalid()) 2639dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2640dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2641dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (ArgChanged) 2642dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor *ArgChanged = true; 2643dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Outputs.push_back(Out.get()); 2644dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor continue; 2645dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2646c8fc90a854b4ccba21c85884676a80334159dd94John McCall 2647c8fc90a854b4ccba21c85884676a80334159dd94John McCall // Record right away that the argument was changed. This needs 2648c8fc90a854b4ccba21c85884676a80334159dd94John McCall // to happen even if the array expands to nothing. 2649c8fc90a854b4ccba21c85884676a80334159dd94John McCall if (ArgChanged) *ArgChanged = true; 2650dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2651dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // The transform has determined that we should perform an elementwise 2652dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // expansion of the pattern. Do so. 2653cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 2654dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 2655dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult Out = getDerived().TransformExpr(Pattern); 2656dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (Out.isInvalid()) 2657dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2658dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 265977d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.get()->containsUnexpandedParameterPack()) { 266067fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor Out = RebuildPackExpansion(Out.get(), Expansion->getEllipsisLoc(), 266167fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor OrigNumExpansions); 266277d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.isInvalid()) 266377d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor return true; 266477d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor } 266577d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor 2666dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Outputs.push_back(Out.get()); 2667dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2668dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2669dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor continue; 2670dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2671dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2672aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor ExprResult Result = getDerived().TransformExpr(Inputs[I]); 2673aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (Result.isInvalid()) 2674aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return true; 2675aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2676aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (Result.get() != Inputs[I] && ArgChanged) 2677aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor *ArgChanged = true; 2678aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2679aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Outputs.push_back(Result.get()); 2680aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 2681aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2682aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return false; 2683aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor} 2684aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2685aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregortemplate<typename Derived> 2686c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorNestedNameSpecifierLoc 2687c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas GregorTreeTransform<Derived>::TransformNestedNameSpecifierLoc( 2688c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc NNS, 2689c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType, 2690c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *FirstQualifierInScope) { 2691686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<NestedNameSpecifierLoc, 4> Qualifiers; 2692c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier; 2693c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Qualifier = Qualifier.getPrefix()) 2694c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Qualifiers.push_back(Qualifier); 2695c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2696c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor CXXScopeSpec SS; 2697c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor while (!Qualifiers.empty()) { 2698c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifierLoc Q = Qualifiers.pop_back_val(); 2699c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier(); 2700c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2701c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor switch (QNNS->getKind()) { 2702c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::Identifier: 2703c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/0, 2704c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor *QNNS->getAsIdentifier(), 2705c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalBeginLoc(), 2706c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalEndLoc(), 2707c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor ObjectType, false, SS, 2708c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor FirstQualifierInScope, false)) 2709c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(); 2710c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2711c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2712c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2713c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::Namespace: { 2714c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamespaceDecl *NS 2715c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast_or_null<NamespaceDecl>( 2716c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor getDerived().TransformDecl( 2717c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalBeginLoc(), 2718c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QNNS->getAsNamespace())); 2719c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc()); 2720c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2721c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 2722c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2723c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::NamespaceAlias: { 2724c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamespaceAliasDecl *Alias 2725c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast_or_null<NamespaceAliasDecl>( 2726c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor getDerived().TransformDecl(Q.getLocalBeginLoc(), 2727c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QNNS->getAsNamespaceAlias())); 2728c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(), 2729c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalEndLoc()); 2730c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2731c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 2732c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2733c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::Global: 2734c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // There is no meaningful transformation that one could perform on the 2735c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // global scope. 2736c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc()); 2737c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2738c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2739c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::TypeSpecWithTemplate: 2740c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor case NestedNameSpecifier::TypeSpec: { 2741c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType, 2742c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor FirstQualifierInScope, SS); 2743c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2744c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (!TL) 2745c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(); 2746c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2747c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (TL.getType()->isDependentType() || TL.getType()->isRecordType() || 27484e4d08403ca5cfd4d558fa2936215d3a4e5a528dDavid Blaikie (SemaRef.getLangOpts().CPlusPlus0x && 2749c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TL.getType()->isEnumeralType())) { 2750c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor assert(!TL.getType().hasLocalQualifiers() && 2751c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor "Can't get cv-qualifiers here"); 275295aafb2453e1fecec8dcfd9e125cd78277f45859Richard Smith if (TL.getType()->isEnumeralType()) 275395aafb2453e1fecec8dcfd9e125cd78277f45859Richard Smith SemaRef.Diag(TL.getBeginLoc(), 275495aafb2453e1fecec8dcfd9e125cd78277f45859Richard Smith diag::warn_cxx98_compat_enum_nested_name_spec); 2755c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL, 2756c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Q.getLocalEndLoc()); 2757c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor break; 2758c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 275900c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu // If the nested-name-specifier is an invalid type def, don't emit an 276000c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu // error because a previous error should have already been emitted. 276100c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu TypedefTypeLoc* TTL = dyn_cast<TypedefTypeLoc>(&TL); 276200c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu if (!TTL || !TTL->getTypedefNameDecl()->isInvalidDecl()) { 276300c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag) 276400c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu << TL.getType() << SS.getRange(); 276500c93a10c3504b77dad4467766bfca3248defbfbRichard Trieu } 2766c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(); 2767c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 27687c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor } 2769c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 27707c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor // The qualifier-in-scope and object type only apply to the leftmost entity. 2771c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor FirstQualifierInScope = 0; 27727c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor ObjectType = QualType(); 2773c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 2774c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2775c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // Don't rebuild the nested-name-specifier if we don't have to. 2776c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (SS.getScopeRep() == NNS.getNestedNameSpecifier() && 2777c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor !getDerived().AlwaysRebuild()) 2778c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NNS; 2779c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2780c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // If we can re-use the source-location data from the original 2781c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // nested-name-specifier, do so. 2782c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (SS.location_size() == NNS.getDataLength() && 2783c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0) 2784c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData()); 2785c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2786c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // Allocate new nested-name-specifier location information. 2787c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor return SS.getWithLocInContext(SemaRef.Context); 2788c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor} 2789c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 2790c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived> 27912577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclarationNameInfo 27922577743c5650c646fb705df01403707e94f2df04Abramo BagnaraTreeTransform<Derived> 279343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { 27942577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName Name = NameInfo.getName(); 279581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor if (!Name) 27962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(); 279781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor 279881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor switch (Name.getNameKind()) { 279981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::Identifier: 280081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCZeroArgSelector: 280181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCOneArgSelector: 280281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCMultiArgSelector: 280381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXOperatorName: 28043e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt case DeclarationName::CXXLiteralOperatorName: 280581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXUsingDirective: 28062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return NameInfo; 28071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 280881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXConstructorName: 280981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXDestructorName: 281081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXConversionFunctionName: { 28112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TypeSourceInfo *NewTInfo; 28122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara CanQualType NewCanTy; 28132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { 281443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NewTInfo = getDerived().TransformType(OldTInfo); 281543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (!NewTInfo) 281643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return DeclarationNameInfo(); 281743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); 28182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 28192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara else { 28202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewTInfo = 0; 28212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); 282243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType NewT = getDerived().TransformType(Name.getCXXNameType()); 28232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (NewT.isNull()) 28242577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(); 28252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewCanTy = SemaRef.Context.getCanonicalType(NewT); 28262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 28271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName NewName 28292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), 28302577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewCanTy); 28312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NewNameInfo(NameInfo); 28322577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewNameInfo.setName(NewName); 28332577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewNameInfo.setNamedTypeInfo(NewTInfo); 28342577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return NewNameInfo; 283581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor } 28361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 28371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2838b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Unknown name kind."); 283981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor} 284081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor 284181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregortemplate<typename Derived> 28421eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 2843fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS, 2844fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName Name, 2845fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 2846fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor QualType ObjectType, 2847fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor NamedDecl *FirstQualifierInScope) { 2848fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { 2849fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateDecl *Template = QTN->getTemplateDecl(); 2850fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor assert(Template && "qualified template name must refer to a template"); 2851fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2852fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateDecl *TransTemplate 2853fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, 2854fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor Template)); 2855fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!TransTemplate) 2856fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 2857fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2858fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2859fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SS.getScopeRep() == QTN->getQualifier() && 2860fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransTemplate == Template) 2861fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 2862fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2863fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(), 2864fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransTemplate); 2865fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2866fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2867fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { 2868fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (SS.getScopeRep()) { 2869fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor // These apply to the scope specifier, not the template. 2870fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType = QualType(); 2871fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor FirstQualifierInScope = 0; 2872fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2873fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2874fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2875fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SS.getScopeRep() == DTN->getQualifier() && 2876fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType.isNull()) 2877fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 2878fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2879fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (DTN->isIdentifier()) { 2880fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(SS, 2881fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor *DTN->getIdentifier(), 2882fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor NameLoc, 2883fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType, 2884fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor FirstQualifierInScope); 2885fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2886fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2887fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc, 2888fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor ObjectType); 2889fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2890fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2891fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (TemplateDecl *Template = Name.getAsTemplateDecl()) { 2892fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateDecl *TransTemplate 2893fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc, 2894fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor Template)); 2895fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!TransTemplate) 2896fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 2897fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2898fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2899fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransTemplate == Template) 2900fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 2901fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2902fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(TransTemplate); 2903fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2904fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2905fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (SubstTemplateTemplateParmPackStorage *SubstPack 2906fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = Name.getAsSubstTemplateTemplateParmPack()) { 2907fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateTemplateParmDecl *TransParam 2908fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = cast_or_null<TemplateTemplateParmDecl>( 2909fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack())); 2910fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!TransParam) 2911fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return TemplateName(); 2912fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2913fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor if (!getDerived().AlwaysRebuild() && 2914fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TransParam == SubstPack->getParameterPack()) 2915fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return Name; 2916fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2917fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return getDerived().RebuildTemplateName(TransParam, 2918fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SubstPack->getArgumentPack()); 2919fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor } 2920fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2921fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor // These should be getting filtered out before they reach the AST. 2922fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor llvm_unreachable("overloaded function decl survived to here"); 2923fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor} 2924fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor 2925fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregortemplate<typename Derived> 2926833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallvoid TreeTransform<Derived>::InventTemplateArgumentLoc( 2927833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgument &Arg, 2928833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &Output) { 2929833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation Loc = getDerived().getBaseLocation(); 2930670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor switch (Arg.getKind()) { 2931670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Null: 29329f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin llvm_unreachable("null template argument in TreeTransform"); 2933833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2934833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2935833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Type: 2936833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(Arg, 2937a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); 2938c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2939833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2940833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2941788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: 2942b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor case TemplateArgument::TemplateExpansion: { 2943b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor NestedNameSpecifierLocBuilder Builder; 2944b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor TemplateName Template = Arg.getAsTemplate(); 2945b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) 2946b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc); 2947b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName()) 2948b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc); 2949b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor 2950b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (Arg.getKind() == TemplateArgument::Template) 2951b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Output = TemplateArgumentLoc(Arg, 2952b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.getWithLocInContext(SemaRef.Context), 2953b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Loc); 2954b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor else 2955b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Output = TemplateArgumentLoc(Arg, 2956b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Builder.getWithLocInContext(SemaRef.Context), 2957b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Loc, Loc); 2958b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor 2959a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor break; 2960b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor } 2961a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 2962833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Expression: 2963833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); 2964833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2965833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2966833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Declaration: 2967670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Integral: 2968833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Pack: 2969828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); 2970833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2971833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 2972833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 2973833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2974833ca991c1bfc967f0995974ca86f66ba1f666b5John McCalltemplate<typename Derived> 2975833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TreeTransform<Derived>::TransformTemplateArgument( 2976833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc &Input, 2977833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &Output) { 2978833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgument &Arg = Input.getArgument(); 2979833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall switch (Arg.getKind()) { 2980833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Null: 2981833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Integral: 2982833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = Input; 2983833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 29841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2985670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Type: { 2986a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *DI = Input.getTypeSourceInfo(); 2987833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (DI == NULL) 2988a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall DI = InventTypeSourceInfo(Input.getArgument().getAsType()); 2989833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2990833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall DI = getDerived().TransformType(DI); 2991833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!DI) return true; 2992833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2993833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); 2994833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2995670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 29961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2997670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Declaration: { 2998833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: we should never have to transform one of these. 2999972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor DeclarationName Name; 3000972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) 3001972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor Name = ND->getDeclName(); 3002788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor TemporaryBase Rebase(*this, Input.getLocation(), Name); 30037c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); 3004833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!D) return true; 3005833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 3006828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Expr *SourceExpr = Input.getSourceDeclExpression(); 3007828bff2079b6a91ecd7ed5b842c59527d7682789John McCall if (SourceExpr) { 3008828bff2079b6a91ecd7ed5b842c59527d7682789John McCall EnterExpressionEvaluationContext Unevaluated(getSema(), 3009f6702a3927147655206ae729a84339c4fda4c651Richard Smith Sema::ConstantEvaluated); 301060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(SourceExpr); 3011ac6260187b6b2f26faa9264d170d649a501f58a9Eli Friedman E = SemaRef.ActOnConstantExpression(E); 30129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SourceExpr = (E.isInvalid() ? 0 : E.take()); 3013828bff2079b6a91ecd7ed5b842c59527d7682789John McCall } 3014828bff2079b6a91ecd7ed5b842c59527d7682789John McCall 3015828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); 3016833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 3017670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 30181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3019788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: { 3020b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc(); 3021b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (QualifierLoc) { 3022b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc); 3023b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor if (!QualifierLoc) 3024b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor return true; 3025b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor } 3026b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor 30271d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor CXXScopeSpec SS; 30281d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor SS.Adopt(QualifierLoc); 3029788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor TemplateName Template 30301d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(), 30311d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor Input.getTemplateNameLoc()); 3032788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor if (Template.isNull()) 3033788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return true; 3034c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3035b6744efecba58792cce20d2d7b9ee39927c5422eDouglas Gregor Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc, 3036788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor Input.getTemplateNameLoc()); 3037788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return false; 3038788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor } 3039a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 3040a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor case TemplateArgument::TemplateExpansion: 3041a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor llvm_unreachable("Caller should expand pack expansions"); 3042a7fc901a2e39bfe55bfcff5934b2d9fdf9656491Douglas Gregor 3043670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Expression: { 3044f6702a3927147655206ae729a84339c4fda4c651Richard Smith // Template argument expressions are constant expressions. 30451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EnterExpressionEvaluationContext Unevaluated(getSema(), 3046f6702a3927147655206ae729a84339c4fda4c651Richard Smith Sema::ConstantEvaluated); 30471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3048833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Expr *InputExpr = Input.getSourceExpression(); 3049833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); 3050833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 3051223de2497fdaacf3a6b0a123c12265ca837abf19Chris Lattner ExprResult E = getDerived().TransformExpr(InputExpr); 3052ac6260187b6b2f26faa9264d170d649a501f58a9Eli Friedman E = SemaRef.ActOnConstantExpression(E); 3053833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (E.isInvalid()) return true; 30549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); 3055833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 3056670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 30571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3058670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Pack: { 3059686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<TemplateArgument, 4> TransformedArgs; 3060670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor TransformedArgs.reserve(Arg.pack_size()); 30611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (TemplateArgument::pack_iterator A = Arg.pack_begin(), 3062670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor AEnd = Arg.pack_end(); 3063670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor A != AEnd; ++A) { 30641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3065833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: preserve source information here when we start 3066833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // caring about parameter packs. 3067833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 3068828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TemplateArgumentLoc InputArg; 3069828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TemplateArgumentLoc OutputArg; 3070828bff2079b6a91ecd7ed5b842c59527d7682789John McCall getDerived().InventTemplateArgumentLoc(*A, InputArg); 3071828bff2079b6a91ecd7ed5b842c59527d7682789John McCall if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) 3072833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 3073833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 3074828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TransformedArgs.push_back(OutputArg.getArgument()); 3075670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 3076910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor 3077910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TemplateArgument *TransformedArgsPtr 3078910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor = new (getSema().Context) TemplateArgument[TransformedArgs.size()]; 3079910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor std::copy(TransformedArgs.begin(), TransformedArgs.end(), 3080910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TransformedArgsPtr); 3081910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr, 3082910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TransformedArgs.size()), 3083910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor Input.getLocInfo()); 3084833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 3085670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 3086670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 30871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3088670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Work around bogus GCC warning 3089833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 3090670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor} 3091670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor 30927ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// \brief Iterator adaptor that invents template argument location information 30937ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// for each of the template arguments in its underlying iterator. 30947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename Derived, typename InputIterator> 30957ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorclass TemplateArgumentLocInventIterator { 30967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TreeTransform<Derived> &Self; 30977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Iter; 30987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 30997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorpublic: 31007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc value_type; 31017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc reference; 31027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef typename std::iterator_traits<InputIterator>::difference_type 31037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor difference_type; 31047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef std::input_iterator_tag iterator_category; 31057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 31067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class pointer { 31077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Arg; 3108fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 31097ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 31107ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } 31117ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 31127ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLoc *operator->() const { return &Arg; } 31137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 31147ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 31157ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator() { } 31167ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 31177ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, 31187ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Iter) 31197ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor : Self(Self), Iter(Iter) { } 31207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 31217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator &operator++() { 31227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++Iter; 31237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return *this; 3124fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor } 3125fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 31267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator operator++(int) { 31277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator Old(*this); 31287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++(*this); 31297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Old; 31307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 31317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 31327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor reference operator*() const { 31337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Result; 31347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor Self.InventTemplateArgumentLoc(*Iter, Result); 31357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Result; 31367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 31377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 31387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor pointer operator->() const { return pointer(**this); } 31397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 31407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator==(const TemplateArgumentLocInventIterator &X, 31417ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLocInventIterator &Y) { 31427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Iter == Y.Iter; 31437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 3144fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 31457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator!=(const TemplateArgumentLocInventIterator &X, 31467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLocInventIterator &Y) { 31477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Iter != Y.Iter; 31487ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 31497ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor}; 31507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 31517f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregortemplate<typename Derived> 31527ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename InputIterator> 31537ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorbool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, 31547ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Last, 31557f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor TemplateArgumentListInfo &Outputs) { 31567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor for (; First != Last; ++First) { 31577f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor TemplateArgumentLoc Out; 31587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc In = *First; 31598491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 31608491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (In.getArgument().getKind() == TemplateArgument::Pack) { 31618491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // Unpack argument packs, which we translate them into separate 31628491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // arguments. 31637ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // FIXME: We could do much better if we could guarantee that the 31647ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // TemplateArgumentLocInfo for the pack expansion would be usable for 31657ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // all of the template arguments in the argument pack. 31667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLocInventIterator<Derived, 31677ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgument::pack_iterator> 31687ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor PackLocIterator; 31697ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor if (TransformTemplateArguments(PackLocIterator(*this, 31707ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor In.getArgument().pack_begin()), 31717ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor PackLocIterator(*this, 31727ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor In.getArgument().pack_end()), 31737ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor Outputs)) 31747ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return true; 31758491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 31768491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 31778491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 31788491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 31798491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (In.getArgument().isPackExpansion()) { 31808491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // We have a pack expansion, for which we will be substituting into 31818491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // the pattern. 31828491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor SourceLocation Ellipsis; 3183cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> OrigNumExpansions; 31848491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc Pattern 3185cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor = In.getPackExpansionPattern(Ellipsis, OrigNumExpansions, 3186cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor getSema().Context); 31878491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 3188686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<UnexpandedParameterPack, 2> Unexpanded; 31898491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 31908491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 31918491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 31928491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // Determine whether the set of unexpanded parameter packs can and should 31938491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // be expanded. 31948491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor bool Expand = true; 3195d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 3196cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; 31978491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TryExpandParameterPacks(Ellipsis, 31988491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Pattern.getSourceRange(), 3199a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 3200d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor Expand, 3201d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor RetainExpansion, 3202d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) 32038491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 32048491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 32058491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (!Expand) { 32068491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The transform has determined that we should perform a simple 32078491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // transformation on the pack expansion, producing another pack 32088491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // expansion. 32098491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc OutPattern; 32108491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 32118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) 32128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 32138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 3214cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis, 3215cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions); 32168491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (Out.getArgument().isNull()) 32178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 32188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 32198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Outputs.addArgument(Out); 32208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 32218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 32228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 32238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The transform has determined that we should perform an elementwise 32248491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // expansion of the pattern. Do so. 3225cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 32268491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 32278491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 32288491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, Out)) 32298491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 32308491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 323177d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.getArgument().containsUnexpandedParameterPack()) { 3232cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Out = getDerived().RebuildPackExpansion(Out, Ellipsis, 3233cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor OrigNumExpansions); 323477d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor if (Out.getArgument().isNull()) 323577d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor return true; 323677d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor } 323777d6bb9e223496aa5288294f34e7225d1f65dddcDouglas Gregor 32388491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Outputs.addArgument(Out); 32398491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 32408491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 32413cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 32423cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // forgetting the partially-substituted parameter pack. 32433cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (RetainExpansion) { 32443cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 32453cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 32463cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, Out)) 32473cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor return true; 32483cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 3249cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor Out = getDerived().RebuildPackExpansion(Out, Ellipsis, 3250cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor OrigNumExpansions); 32513cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (Out.getArgument().isNull()) 32523cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor return true; 32533cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 32543cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor Outputs.addArgument(Out); 32553cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor } 3256d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 32578491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 32588491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 32598491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 32608491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The simple case: 32618491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(In, Out)) 32627f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return true; 32637f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 32647f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor Outputs.addArgument(Out); 32657f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor } 32667f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 32677f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return false; 32687f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 32697f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor} 32707f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 3271577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 3272577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// Type transformation 3273577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 3274577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3275577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 327643fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::TransformType(QualType T) { 3277577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (getDerived().AlreadyTransformed(T)) 3278577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return T; 32791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3280a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Temporary workaround. All of these transformations should 3281a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // eventually turn into transformations on TypeLocs. 3282c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T, 3283c21c7e9c2cded68f91be15be6847c9649242dc17Douglas Gregor getDerived().getBaseLocation()); 3284c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 328543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeSourceInfo *NewDI = getDerived().TransformType(DI); 32861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3287a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (!NewDI) 3288a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 32891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3290a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return NewDI->getType(); 3291577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 32921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3293577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 329443fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { 3295f6702a3927147655206ae729a84339c4fda4c651Richard Smith // Refine the base location to the type's location. 3296f6702a3927147655206ae729a84339c4fda4c651Richard Smith TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(), 3297f6702a3927147655206ae729a84339c4fda4c651Richard Smith getDerived().getBaseEntity()); 3298a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlreadyTransformed(DI->getType())) 3299a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return DI; 33001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3301a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder TLB; 33021bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 3303a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLoc TL = DI->getTypeLoc(); 3304a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TLB.reserve(TL.getFullDataSize()); 33051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 330643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result = getDerived().TransformType(TLB, TL); 3307a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3308a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return 0; 33091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3310a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall return TLB.getTypeSourceInfo(SemaRef.Context, Result); 3311577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 33121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3314a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 331543fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { 3316a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall switch (T.getTypeLocClass()) { 3317a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT) 3318a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT) \ 3319a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall case TypeLoc::CLASS: \ 332043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); 3321a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def" 3322a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3323577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 33249f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin llvm_unreachable("unhandled type loc!"); 3325577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 33261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3327a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// FIXME: By default, this routine adds type qualifiers only to types 3328a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that can have qualifiers, and silently suppresses those qualifiers 3329a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that are not permitted (e.g., qualifiers on reference or function 3330a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// types). This is the right thing for template instantiation, but 3331a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// probably not for other clients. 33321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 33331eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3334a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, 333543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualifiedTypeLoc T) { 3336a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor Qualifiers Quals = T.getType().getLocalQualifiers(); 3337a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 333843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); 3339a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3340577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 33411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3342a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Silently suppress qualifiers if the result type can't be qualified. 3343a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: this is the right thing for template instantiation, but 3344a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // probably not for other clients. 3345a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result->isFunctionType() || Result->isReferenceType()) 3346a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 33471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3348f85e193739c953358c865005855253af4f68a497John McCall // Suppress Objective-C lifetime qualifiers if they don't make sense for the 3349e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // resulting type. 3350e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor if (Quals.hasObjCLifetime()) { 3351e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor if (!Result->isObjCLifetimeType() && !Result->isDependentType()) 3352e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Quals.removeObjCLifetime(); 33534020caec546d221170072d2388b57d151cb26111Douglas Gregor else if (Result.getObjCLifetime()) { 3354e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // Objective-C ARC: 3355e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // A lifetime qualifier applied to a substituted template parameter 3356e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor // overrides the lifetime qualifier from the template argument. 3357e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor if (const SubstTemplateTypeParmType *SubstTypeParam 3358e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor = dyn_cast<SubstTemplateTypeParmType>(Result)) { 3359e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor QualType Replacement = SubstTypeParam->getReplacementType(); 3360e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Qualifiers Qs = Replacement.getQualifiers(); 3361e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Qs.removeObjCLifetime(); 3362e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Replacement 3363e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(), 3364e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Qs); 3365e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Result = SemaRef.Context.getSubstTemplateTypeParmType( 3366e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor SubstTypeParam->getReplacedParameter(), 3367e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Replacement); 3368e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor TLB.TypeWasModifiedSafely(Result); 3369e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } else { 33704020caec546d221170072d2388b57d151cb26111Douglas Gregor // Otherwise, complain about the addition of a qualifier to an 33714020caec546d221170072d2388b57d151cb26111Douglas Gregor // already-qualified type. 33724020caec546d221170072d2388b57d151cb26111Douglas Gregor SourceRange R = TLB.getTemporaryTypeLoc(Result).getSourceRange(); 3373b8b0313e84700b5c6d597b3be4de41c97b7550f1Argyrios Kyrtzidis SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant) 33744020caec546d221170072d2388b57d151cb26111Douglas Gregor << Result << R; 33754020caec546d221170072d2388b57d151cb26111Douglas Gregor 3376e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor Quals.removeObjCLifetime(); 3377e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } 3378e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } 3379e559ca1672ecef59345a928af0a6809b09282d2cDouglas Gregor } 33802865474261a608c7873b87ba4af110d17907896dJohn McCall if (!Quals.empty()) { 33812865474261a608c7873b87ba4af110d17907896dJohn McCall Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); 33822865474261a608c7873b87ba4af110d17907896dJohn McCall TLB.push<QualifiedTypeLoc>(Result); 33832865474261a608c7873b87ba4af110d17907896dJohn McCall // No location information to preserve. 33842865474261a608c7873b87ba4af110d17907896dJohn McCall } 3385a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3386a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3387a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 3388a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 338943fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived> 3390b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTypeLoc 3391b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL, 339243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 339343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *UnqualLookup, 3394b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor CXXScopeSpec &SS) { 3395b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor QualType T = TL.getType(); 339643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (getDerived().AlreadyTransformed(T)) 3397b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TL; 3398b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 339943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeLocBuilder TLB; 340043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result; 3401b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 340243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (isa<TemplateSpecializationType>(T)) { 3403b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TemplateSpecializationTypeLoc SpecTL 3404b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = cast<TemplateSpecializationTypeLoc>(TL); 3405b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 340643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template = 3407b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor getDerived().TransformTemplateName(SS, 3408b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL.getTypePtr()->getTemplateName(), 3409b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL.getTemplateNameLoc(), 341043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType, UnqualLookup); 3411b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor if (Template.isNull()) 3412b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TypeLoc(); 3413b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 3414b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, 3415b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Template); 341643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } else if (isa<DependentTemplateSpecializationType>(T)) { 3417b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor DependentTemplateSpecializationTypeLoc SpecTL 3418b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = cast<DependentTemplateSpecializationTypeLoc>(TL); 3419a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 3420b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TemplateName Template 3421b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = getDerived().RebuildTemplateName(SS, 3422b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor *SpecTL.getTypePtr()->getIdentifier(), 342355d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara SpecTL.getTemplateNameLoc(), 3424b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor ObjectType, UnqualLookup); 3425a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (Template.isNull()) 3426b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TypeLoc(); 3427b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 3428b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Result = getDerived().TransformDependentTemplateSpecializationType(TLB, 3429b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor SpecTL, 3430087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor Template, 3431087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor SS); 343243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } else { 343343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // Nothing special needs to be done for these. 3434b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor Result = getDerived().TransformType(TLB, TL); 343543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } 3436b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 3437b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor if (Result.isNull()) 3438b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TypeLoc(); 3439b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor 3440b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TLB.getTypeSourceInfo(SemaRef.Context, Result)->getTypeLoc(); 344143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall} 344243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 3443c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregortemplate<typename Derived> 3444b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTypeSourceInfo * 3445b71d821d64af88749fc9860fd43a5164d8d819c8Douglas GregorTreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo, 3446c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType ObjectType, 3447c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor NamedDecl *UnqualLookup, 3448c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor CXXScopeSpec &SS) { 3449c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // FIXME: Painfully copy-paste from the above! 3450c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3451b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor QualType T = TSInfo->getType(); 3452c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (getDerived().AlreadyTransformed(T)) 3453b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TSInfo; 3454c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3455c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TypeLocBuilder TLB; 3456c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor QualType Result; 3457c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3458b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TypeLoc TL = TSInfo->getTypeLoc(); 3459c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (isa<TemplateSpecializationType>(T)) { 3460c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor TemplateSpecializationTypeLoc SpecTL 3461c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast<TemplateSpecializationTypeLoc>(TL); 3462c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3463b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor TemplateName Template 3464b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor = getDerived().TransformTemplateName(SS, 3465fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SpecTL.getTypePtr()->getTemplateName(), 3466fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SpecTL.getTemplateNameLoc(), 3467c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor ObjectType, UnqualLookup); 3468c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (Template.isNull()) 3469b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return 0; 3470c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3471c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL, 3472c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Template); 3473c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } else if (isa<DependentTemplateSpecializationType>(T)) { 3474c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor DependentTemplateSpecializationTypeLoc SpecTL 3475c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor = cast<DependentTemplateSpecializationTypeLoc>(TL); 3476c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3477a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateName Template 3478fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor = getDerived().RebuildTemplateName(SS, 34797c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor *SpecTL.getTypePtr()->getIdentifier(), 348055d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara SpecTL.getTemplateNameLoc(), 34817c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor ObjectType, UnqualLookup); 3482a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (Template.isNull()) 3483b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return 0; 3484a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 3485c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Result = getDerived().TransformDependentTemplateSpecializationType(TLB, 3486a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor SpecTL, 3487087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor Template, 3488087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor SS); 3489c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } else { 3490c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor // Nothing special needs to be done for these. 3491c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor Result = getDerived().TransformType(TLB, TL); 3492c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor } 3493c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3494c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor if (Result.isNull()) 3495b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return 0; 3496c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3497b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor return TLB.getTypeSourceInfo(SemaRef.Context, Result); 3498c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor} 3499c22b5fff39a7520207f165fb16a27a34b944bd9cDouglas Gregor 3500a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate <class TyLoc> static inline 3501a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { 3502a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TyLoc NewT = TLB.push<TyLoc>(T.getType()); 3503a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewT.setNameLoc(T.getNameLoc()); 3504a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return T.getType(); 3505a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 3506a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3507a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3508a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, 350943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall BuiltinTypeLoc T) { 3510ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); 3511ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor NewT.setBuiltinLoc(T.getBuiltinLoc()); 3512ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor if (T.needsExtraLocalData()) 3513ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); 3514ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return T.getType(); 3515577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3516577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 35171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3518a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, 351943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ComplexTypeLoc T) { 3520a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: recurse? 3521a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return TransformTypeSpecType(TLB, T); 3522a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 35231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3524a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3525a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, 352643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall PointerTypeLoc TL) { 3527c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt QualType PointeeType 3528c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt = getDerived().TransformType(TLB, TL.getPointeeLoc()); 352992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (PointeeType.isNull()) 353092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return QualType(); 353192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 353292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor QualType Result = TL.getType(); 3533c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (PointeeType->getAs<ObjCObjectType>()) { 353492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // A dependent pointer type 'T *' has is being transformed such 353592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // that an Objective-C class type is being replaced for 'T'. The 353692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // resulting pointer type is an ObjCObjectPointerType, not a 353792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // PointerType. 3538c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); 3539c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3540c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); 3541c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall NewT.setStarLoc(TL.getStarLoc()); 354292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return Result; 354392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 354443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 354592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (getDerived().AlwaysRebuild() || 354692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor PointeeType != TL.getPointeeLoc().getType()) { 354792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); 354892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (Result.isNull()) 354992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return QualType(); 355092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 3551f85e193739c953358c865005855253af4f68a497John McCall 3552f85e193739c953358c865005855253af4f68a497John McCall // Objective-C ARC can add lifetime qualifiers to the type that we're 3553f85e193739c953358c865005855253af4f68a497John McCall // pointing to. 3554f85e193739c953358c865005855253af4f68a497John McCall TLB.TypeWasModifiedSafely(Result->getPointeeType()); 3555f85e193739c953358c865005855253af4f68a497John McCall 355692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); 355792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor NewT.setSigilLoc(TL.getSigilLoc()); 3558c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return Result; 3559577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3560577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 35611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 35621eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3563a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, 356443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall BlockPointerTypeLoc TL) { 3565db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor QualType PointeeType 3566c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt = getDerived().TransformType(TLB, TL.getPointeeLoc()); 3567c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (PointeeType.isNull()) 3568c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return QualType(); 3569c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3570c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt QualType Result = TL.getType(); 3571c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (getDerived().AlwaysRebuild() || 3572c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt PointeeType != TL.getPointeeLoc().getType()) { 3573c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Result = getDerived().RebuildBlockPointerType(PointeeType, 3574db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor TL.getSigilLoc()); 3575db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor if (Result.isNull()) 3576db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor return QualType(); 3577db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor } 3578db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor 357939968adc66ab02275d2f561e372a20ae454bd4e7Douglas Gregor BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); 3580db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor NewT.setSigilLoc(TL.getSigilLoc()); 3581db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor return Result; 3582a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 35831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 358485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// Transforms a reference type. Note that somewhat paradoxically we 358585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// don't care whether the type itself is an l-value type or an r-value 358685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// type; we only care if the type was *written* as an l-value type 358785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// or an r-value type. 358885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCalltemplate<typename Derived> 358985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType 359085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, 359143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ReferenceTypeLoc TL) { 359285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall const ReferenceType *T = TL.getTypePtr(); 359385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 359485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall // Note that this works with the pointee-as-written. 359585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 359685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (PointeeType.isNull()) 359785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return QualType(); 359885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 359985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType Result = TL.getType(); 360085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (getDerived().AlwaysRebuild() || 360185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall PointeeType != T->getPointeeTypeAsWritten()) { 360285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Result = getDerived().RebuildReferenceType(PointeeType, 360385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->isSpelledAsLValue(), 360485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getSigilLoc()); 360585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (Result.isNull()) 360685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return QualType(); 360785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall } 360885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 3609f85e193739c953358c865005855253af4f68a497John McCall // Objective-C ARC can add lifetime qualifiers to the type that we're 3610f85e193739c953358c865005855253af4f68a497John McCall // referring to. 3611f85e193739c953358c865005855253af4f68a497John McCall TLB.TypeWasModifiedSafely( 3612f85e193739c953358c865005855253af4f68a497John McCall Result->getAs<ReferenceType>()->getPointeeTypeAsWritten()); 3613f85e193739c953358c865005855253af4f68a497John McCall 361485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall // r-value references can be rebuilt as l-value references. 361585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall ReferenceTypeLoc NewTL; 361685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (isa<LValueReferenceType>(Result)) 361785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL = TLB.push<LValueReferenceTypeLoc>(Result); 361885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall else 361985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL = TLB.push<RValueReferenceTypeLoc>(Result); 362085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL.setSigilLoc(TL.getSigilLoc()); 362185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 362285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return Result; 362385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall} 362485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 3625a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3626a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3627a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, 362843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall LValueReferenceTypeLoc TL) { 362943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TransformReferenceType(TLB, TL); 3630a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 36311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3632a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3633a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3634a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, 363543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall RValueReferenceTypeLoc TL) { 363643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TransformReferenceType(TLB, TL); 3637577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 36381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3639577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 36401eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3641a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, 364243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall MemberPointerTypeLoc TL) { 3643a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 3644577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (PointeeType.isNull()) 3645577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3647b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara TypeSourceInfo* OldClsTInfo = TL.getClassTInfo(); 3648b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara TypeSourceInfo* NewClsTInfo = 0; 3649b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (OldClsTInfo) { 3650b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsTInfo = getDerived().TransformType(OldClsTInfo); 3651b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (!NewClsTInfo) 3652b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara return QualType(); 3653b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara } 3654b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara 3655b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara const MemberPointerType *T = TL.getTypePtr(); 3656b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara QualType OldClsType = QualType(T->getClass(), 0); 3657b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara QualType NewClsType; 3658b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (NewClsTInfo) 3659b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsType = NewClsTInfo->getType(); 3660b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara else { 3661b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsType = getDerived().TransformType(OldClsType); 3662b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara if (NewClsType.isNull()) 3663b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara return QualType(); 3664b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara } 36651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3666a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3667a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3668a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall PointeeType != T->getPointeeType() || 3669b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewClsType != OldClsType) { 3670b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType, 367185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getStarLoc()); 3672a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3673a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3674a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3675577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3676a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); 3677a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSigilLoc(TL.getSigilLoc()); 3678b6ab6c1ca733fda2302a1c5066bdfc6218c89e41Abramo Bagnara NewTL.setClassTInfo(NewClsTInfo); 3679a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3680a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3681577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3682577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 36831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 36841eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3685a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, 368643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ConstantArrayTypeLoc TL) { 3687f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const ConstantArrayType *T = TL.getTypePtr(); 3688a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3689577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3690577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3692a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3693a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3694a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3695a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildConstantArrayType(ElementType, 3696a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 3697a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSize(), 369885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->getIndexTypeCVRQualifiers(), 369985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3700a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3701a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3702a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3703457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman 3704457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman // We might have either a ConstantArrayType or a VariableArrayType now: 3705457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman // a ConstantArrayType is allowed to have an element type which is a 3706457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman // VariableArrayType if the type is dependent. Fortunately, all array 3707457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman // types have the same location layout. 3708457a377ac8566ddc0c455a64843ecf5e675cfff8Eli Friedman ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); 3709a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3710a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 37111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3712a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Expr *Size = TL.getSizeExpr(); 3713a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Size) { 3714f6702a3927147655206ae729a84339c4fda4c651Richard Smith EnterExpressionEvaluationContext Unevaluated(SemaRef, 3715f6702a3927147655206ae729a84339c4fda4c651Richard Smith Sema::ConstantEvaluated); 3716a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); 3717ac6260187b6b2f26faa9264d170d649a501f58a9Eli Friedman Size = SemaRef.ActOnConstantExpression(Size).take(); 3718a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3719a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(Size); 3720a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3721a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3722577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 37231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3724577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 3725577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformIncompleteArrayType( 3726a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 372743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall IncompleteArrayTypeLoc TL) { 3728f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const IncompleteArrayType *T = TL.getTypePtr(); 3729a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3730577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3731577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 37321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3733a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3734a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3735a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3736a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildIncompleteArrayType(ElementType, 3737a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 373885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->getIndexTypeCVRQualifiers(), 373985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3740a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3741a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3742a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3743c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3744a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); 3745a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3746a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 3747a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(0); 3748577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3749a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3750577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 37511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3752577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 3753a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3754a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, 375543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall VariableArrayTypeLoc TL) { 3756f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const VariableArrayType *T = TL.getTypePtr(); 3757a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3758577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3759577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 37601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 376160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SizeResult 3762a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall = getDerived().TransformExpr(T->getSizeExpr()); 3763a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (SizeResult.isInvalid()) 3764577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 37651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Size = SizeResult.take(); 3767a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3768a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3769a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3770a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType() || 3771a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Size != T->getSizeExpr()) { 3772a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildVariableArrayType(ElementType, 3773a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 37749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Size, 3775a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getIndexTypeCVRQualifiers(), 377685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3777a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3778a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3779577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 3780c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3781a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); 3782a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3783a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 3784a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(Size); 37851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3786a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3787577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 37881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 37891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3790a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3791a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, 379243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentSizedArrayTypeLoc TL) { 3793f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentSizedArrayType *T = TL.getTypePtr(); 3794a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3795577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3796577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 37971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3798f6702a3927147655206ae729a84339c4fda4c651Richard Smith // Array bounds are constant expressions. 3799f6702a3927147655206ae729a84339c4fda4c651Richard Smith EnterExpressionEvaluationContext Unevaluated(SemaRef, 3800f6702a3927147655206ae729a84339c4fda4c651Richard Smith Sema::ConstantEvaluated); 38011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38023b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall // Prefer the expression from the TypeLoc; the other may have been uniqued. 38033b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Expr *origSize = TL.getSizeExpr(); 38043b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (!origSize) origSize = T->getSizeExpr(); 38053b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall 38063b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall ExprResult sizeResult 38073b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall = getDerived().TransformExpr(origSize); 3808ac6260187b6b2f26faa9264d170d649a501f58a9Eli Friedman sizeResult = SemaRef.ActOnConstantExpression(sizeResult); 38093b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall if (sizeResult.isInvalid()) 3810577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 38111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38123b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall Expr *size = sizeResult.get(); 3813a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3814a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3815a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3816a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType() || 38173b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall size != origSize) { 3818a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildDependentSizedArrayType(ElementType, 3819a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 38203b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall size, 3821a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getIndexTypeCVRQualifiers(), 382285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3823a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3824a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3825577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 38261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3827a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // We might have any sort of array type now, but fortunately they 3828a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // all have the same location layout. 3829a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); 3830a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3831a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 38323b6575108a5b6d8b92ac3a9a7794bf6c3a210907John McCall NewTL.setSizeExpr(size); 3833a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3834a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3835577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 38361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3838577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( 3839a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 384043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentSizedExtVectorTypeLoc TL) { 3841f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentSizedExtVectorType *T = TL.getTypePtr(); 3842a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3843a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: ext vector locs should be nested 3844577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3845577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3846577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 38471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3848f6702a3927147655206ae729a84339c4fda4c651Richard Smith // Vector sizes are constant expressions. 3849f6702a3927147655206ae729a84339c4fda4c651Richard Smith EnterExpressionEvaluationContext Unevaluated(SemaRef, 3850f6702a3927147655206ae729a84339c4fda4c651Richard Smith Sema::ConstantEvaluated); 3851670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor 385260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); 3853ac6260187b6b2f26faa9264d170d649a501f58a9Eli Friedman Size = SemaRef.ActOnConstantExpression(Size); 3854577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (Size.isInvalid()) 3855577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 38561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3857a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3858a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3859eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall ElementType != T->getElementType() || 3860eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall Size.get() != T->getSizeExpr()) { 3861a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, 38629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Size.take(), 3863577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor T->getAttributeLoc()); 3864a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3865a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3866a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3867a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3868a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Result might be dependent or not. 3869a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (isa<DependentSizedExtVectorType>(Result)) { 3870a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall DependentSizedExtVectorTypeLoc NewTL 3871a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall = TLB.push<DependentSizedExtVectorTypeLoc>(Result); 3872a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 3873a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } else { 3874a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); 3875a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 3876a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3877a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3878a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3879577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 38801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3882a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, 388343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall VectorTypeLoc TL) { 3884f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const VectorType *T = TL.getTypePtr(); 3885577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3886577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3887577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 3888577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3889a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3890a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3891a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 389282287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), 3893e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson T->getVectorKind()); 3894a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3895a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3896a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3897c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3898a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); 3899a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 39001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3901a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3902577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 39031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3905a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, 390643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ExtVectorTypeLoc TL) { 3907f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const VectorType *T = TL.getTypePtr(); 3908577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3909577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3910577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 39111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3912a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3913a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3914a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3915a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildExtVectorType(ElementType, 3916a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getNumElements(), 3917a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /*FIXME*/ SourceLocation()); 3918a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3919a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3920a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3921c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3922a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); 3923a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 39241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3925a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3926577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3927577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 39281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 392921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallParmVarDecl * 39306a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas GregorTreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm, 3931fb44de956f27875def889482b5393475060392afJohn McCall int indexAdjustment, 3932d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor llvm::Optional<unsigned> NumExpansions, 3933d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor bool ExpectParameterPack) { 393421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); 39356a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeSourceInfo *NewDI = 0; 39366a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 39376a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) { 39386a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor // If we're substituting into a pack expansion type and we know the 3939d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor // length we want to expand to, just substitute for the pattern. 39406a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeLoc OldTL = OldDI->getTypeLoc(); 39416a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor PackExpansionTypeLoc OldExpansionTL = cast<PackExpansionTypeLoc>(OldTL); 39426a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 39436a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeLocBuilder TLB; 39446a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TypeLoc NewTL = OldDI->getTypeLoc(); 39456a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor TLB.reserve(NewTL.getFullDataSize()); 39466a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 39476a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor QualType Result = getDerived().TransformType(TLB, 39486a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OldExpansionTL.getPatternLoc()); 39496a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor if (Result.isNull()) 39506a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor return 0; 39516a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 39526a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor Result = RebuildPackExpansionType(Result, 39536a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OldExpansionTL.getPatternLoc().getSourceRange(), 39546a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor OldExpansionTL.getEllipsisLoc(), 39556a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NumExpansions); 39566a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor if (Result.isNull()) 39576a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor return 0; 39586a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor 39596a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor PackExpansionTypeLoc NewExpansionTL 39606a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = TLB.push<PackExpansionTypeLoc>(Result); 39616a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc()); 39626a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result); 39636a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor } else 39646a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NewDI = getDerived().TransformType(OldDI); 396521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall if (!NewDI) 396621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return 0; 396721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 3968fb44de956f27875def889482b5393475060392afJohn McCall if (NewDI == OldDI && indexAdjustment == 0) 396921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return OldParm; 3970fb44de956f27875def889482b5393475060392afJohn McCall 3971fb44de956f27875def889482b5393475060392afJohn McCall ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context, 3972fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getDeclContext(), 3973fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getInnerLocStart(), 3974fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getLocation(), 3975fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getIdentifier(), 3976fb44de956f27875def889482b5393475060392afJohn McCall NewDI->getType(), 3977fb44de956f27875def889482b5393475060392afJohn McCall NewDI, 3978fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getStorageClass(), 3979fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getStorageClassAsWritten(), 3980fb44de956f27875def889482b5393475060392afJohn McCall /* DefArg */ NULL); 3981fb44de956f27875def889482b5393475060392afJohn McCall newParm->setScopeInfo(OldParm->getFunctionScopeDepth(), 3982fb44de956f27875def889482b5393475060392afJohn McCall OldParm->getFunctionScopeIndex() + indexAdjustment); 3983fb44de956f27875def889482b5393475060392afJohn McCall return newParm; 398421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall} 398521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 398621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived> 398721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallbool TreeTransform<Derived>:: 3988a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TransformFunctionTypeParams(SourceLocation Loc, 3989a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParmVarDecl **Params, unsigned NumParams, 3990a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor const QualType *ParamTypes, 3991686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<QualType> &OutParamTypes, 3992686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVectorImpl<ParmVarDecl*> *PVars) { 3993fb44de956f27875def889482b5393475060392afJohn McCall int indexAdjustment = 0; 3994fb44de956f27875def889482b5393475060392afJohn McCall 3995a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor for (unsigned i = 0; i != NumParams; ++i) { 3996a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (ParmVarDecl *OldParm = Params[i]) { 3997fb44de956f27875def889482b5393475060392afJohn McCall assert(OldParm->getFunctionScopeIndex() == i); 3998fb44de956f27875def889482b5393475060392afJohn McCall 39996a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor llvm::Optional<unsigned> NumExpansions; 4000406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor ParmVarDecl *NewParm = 0; 4001603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (OldParm->isParameterPack()) { 4002603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We have a function parameter pack that may need to be expanded. 4003686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<UnexpandedParameterPack, 2> Unexpanded; 4004603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4005603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Find the parameter packs that could be expanded. 4006c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc(); 4007c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(TL); 4008c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor TypeLoc Pattern = ExpansionTL.getPatternLoc(); 4009c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded); 4010406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor assert(Unexpanded.size() > 0 && "Could not find parameter packs!"); 4011406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor 4012603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Determine whether we should expand the parameter packs. 4013603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor bool ShouldExpand = false; 4014d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 40156a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor llvm::Optional<unsigned> OrigNumExpansions 40166a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = ExpansionTL.getTypePtr()->getNumExpansions(); 40176a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor NumExpansions = OrigNumExpansions; 4018c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), 4019c8a16fbb78c0e0ae2d2ebdb00bd6761d9d6714d2Douglas Gregor Pattern.getSourceRange(), 4020a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 4021d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ShouldExpand, 4022d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor RetainExpansion, 4023d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) { 4024603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 4025603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4026603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4027603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (ShouldExpand) { 4028603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Expand the function parameter pack into multiple, separate 4029603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // parameters. 403012c9c00024a01819e3a70ef6d951d32efaeb9312Douglas Gregor getDerived().ExpandingFunctionParameterPack(OldParm); 4031cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 4032603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 4033603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor ParmVarDecl *NewParm 40346a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = getDerived().TransformFunctionTypeParam(OldParm, 4035fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment++, 4036d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor OrigNumExpansions, 4037d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor /*ExpectParameterPack=*/false); 4038603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (!NewParm) 4039603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 4040603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4041a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewParm->getType()); 4042a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 4043a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(NewParm); 4044603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4045d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 4046d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 4047d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor // forgetting the partially-substituted parameter pack. 4048d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (RetainExpansion) { 4049d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 4050d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ParmVarDecl *NewParm 40516a24bfda084f06a0b252b7befe8cbb17fce7f94eDouglas Gregor = getDerived().TransformFunctionTypeParam(OldParm, 4052fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment++, 4053d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor OrigNumExpansions, 4054d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor /*ExpectParameterPack=*/false); 4055d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (!NewParm) 4056d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor return true; 4057d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 4058d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor OutParamTypes.push_back(NewParm->getType()); 4059d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor if (PVars) 4060d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor PVars->push_back(NewParm); 4061d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor } 4062d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 4063fb44de956f27875def889482b5393475060392afJohn McCall // The next parameter should have the same adjustment as the 4064fb44de956f27875def889482b5393475060392afJohn McCall // last thing we pushed, but we post-incremented indexAdjustment 4065fb44de956f27875def889482b5393475060392afJohn McCall // on every push. Also, if we push nothing, the adjustment should 4066fb44de956f27875def889482b5393475060392afJohn McCall // go down by one. 4067fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment--; 4068fb44de956f27875def889482b5393475060392afJohn McCall 4069603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We're done with the pack expansion. 4070603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor continue; 4071603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4072603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4073603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We'll substitute the parameter now without expanding the pack 4074603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // expansion. 4075406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 4076406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewParm = getDerived().TransformFunctionTypeParam(OldParm, 4077fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment, 4078d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor NumExpansions, 4079d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor /*ExpectParameterPack=*/true); 4080406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor } else { 4081406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewParm = getDerived().TransformFunctionTypeParam(OldParm, 4082fb44de956f27875def889482b5393475060392afJohn McCall indexAdjustment, 4083d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor llvm::Optional<unsigned>(), 4084d1bb4ae6cbc0f8bea4b329e040f58b18c03388e7Douglas Gregor /*ExpectParameterPack=*/false); 4085603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4086406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor 408721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall if (!NewParm) 408821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return true; 4089603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4090a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewParm->getType()); 4091a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 4092a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(NewParm); 4093603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor continue; 4094603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4095a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4096a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Deal with the possibility that we don't have a parameter 4097a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // declaration for this parameter. 4098a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor QualType OldType = ParamTypes[i]; 4099603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor bool IsPackExpansion = false; 4100cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions; 4101406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor QualType NewType; 4102603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (const PackExpansionType *Expansion 4103603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor = dyn_cast<PackExpansionType>(OldType)) { 4104603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We have a function parameter pack that may need to be expanded. 4105603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor QualType Pattern = Expansion->getPattern(); 4106686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<UnexpandedParameterPack, 2> Unexpanded; 4107603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 4108603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4109603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Determine whether we should expand the parameter packs. 4110603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor bool ShouldExpand = false; 4111d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 4112a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (getDerived().TryExpandParameterPacks(Loc, SourceRange(), 4113a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 4114d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ShouldExpand, 4115d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor RetainExpansion, 4116d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) { 411721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return true; 4118603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4119603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4120603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (ShouldExpand) { 4121603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // Expand the function parameter pack into multiple, separate 4122603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // parameters. 4123cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 4124603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 4125603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor QualType NewType = getDerived().TransformType(Pattern); 4126603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (NewType.isNull()) 4127603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 4128603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4129a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewType); 4130a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 4131a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(0); 4132603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4133603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4134603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We're done with the pack expansion. 4135603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor continue; 4136603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4137603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 41383cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 41393cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor // forgetting the partially-substituted parameter pack. 41403cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (RetainExpansion) { 41413cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 41423cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor QualType NewType = getDerived().TransformType(Pattern); 41433cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (NewType.isNull()) 41443cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor return true; 41453cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor 41463cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor OutParamTypes.push_back(NewType); 41473cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor if (PVars) 41483cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor PVars->push_back(0); 41493cae5c9a79bfd2e27eb44c32b13dfacd2ce5c66fDouglas Gregor } 4150d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor 4151603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // We'll substitute the parameter now without expanding the pack 4152603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor // expansion. 4153603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor OldType = Expansion->getPattern(); 4154603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor IsPackExpansion = true; 4155406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 4156406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewType = getDerived().TransformType(OldType); 4157406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor } else { 4158406f98f6a5a7bde5707085af8d66204e7e76af45Douglas Gregor NewType = getDerived().TransformType(OldType); 4159a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4160603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4161603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (NewType.isNull()) 4162603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor return true; 41631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4164603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor if (IsPackExpansion) 4165cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NewType = getSema().Context.getPackExpansionType(NewType, 4166cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor NumExpansions); 4167603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor 4168a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor OutParamTypes.push_back(NewType); 4169a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (PVars) 4170a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor PVars->push_back(0); 4171577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 41721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4173fb44de956f27875def889482b5393475060392afJohn McCall#ifndef NDEBUG 4174fb44de956f27875def889482b5393475060392afJohn McCall if (PVars) { 4175fb44de956f27875def889482b5393475060392afJohn McCall for (unsigned i = 0, e = PVars->size(); i != e; ++i) 4176fb44de956f27875def889482b5393475060392afJohn McCall if (ParmVarDecl *parm = (*PVars)[i]) 4177fb44de956f27875def889482b5393475060392afJohn McCall assert(parm->getFunctionScopeIndex() == i); 4178603cfb4da2f7ba08a1c3452c2fbf70585b8e7621Douglas Gregor } 4179fb44de956f27875def889482b5393475060392afJohn McCall#endif 4180fb44de956f27875def889482b5393475060392afJohn McCall 4181fb44de956f27875def889482b5393475060392afJohn McCall return false; 4182fb44de956f27875def889482b5393475060392afJohn McCall} 418321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 418421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived> 418521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallQualType 418621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallTreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, 418743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FunctionProtoTypeLoc TL) { 4188cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor return getDerived().TransformFunctionProtoType(TLB, TL, 0, 0); 4189cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor} 4190cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor 4191cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregortemplate<typename Derived> 4192cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas GregorQualType 4193cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas GregorTreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, 4194cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor FunctionProtoTypeLoc TL, 4195cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor CXXRecordDecl *ThisContext, 4196cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor unsigned ThisTypeQuals) { 41977e010a04fef171049291d8cb3047f118566da090Douglas Gregor // Transform the parameters and return type. 41987e010a04fef171049291d8cb3047f118566da090Douglas Gregor // 4199e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith // We are required to instantiate the params and return type in source order. 4200dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // When the function has a trailing return type, we instantiate the 4201dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // parameters before the return type, since the return type can then refer 4202dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // to the parameters themselves (via decltype, sizeof, etc.). 4203dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // 4204686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<QualType, 4> ParamTypes; 4205686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<ParmVarDecl*, 4> ParamDecls; 4206f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const FunctionProtoType *T = TL.getTypePtr(); 42077e010a04fef171049291d8cb3047f118566da090Douglas Gregor 4208dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor QualType ResultType; 4209dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 4210dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (TL.getTrailingReturn()) { 4211a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), 4212a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getParmArray(), 4213a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getNumArgs(), 4214a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getTypePtr()->arg_type_begin(), 4215a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParamTypes, &ParamDecls)) 4216dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 4217dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 4218cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor { 4219cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor // C++11 [expr.prim.general]p3: 4220cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor // If a declaration declares a member function or member function 4221cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor // template of a class X, the expression this is a prvalue of type 4222cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq 4223cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor // and the end of the function-definition, member-declarator, or 4224cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor // declarator. 4225cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals); 4226cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor 4227cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 4228cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor if (ResultType.isNull()) 4229cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor return QualType(); 4230cefc3afac14d29de5aba7810cc8fe6c858949e9dDouglas Gregor } 4231dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor } 4232dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor else { 4233dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 4234dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (ResultType.isNull()) 4235dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 4236dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 4237a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor if (getDerived().TransformFunctionTypeParams(TL.getBeginLoc(), 4238a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getParmArray(), 4239a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getNumArgs(), 4240a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor TL.getTypePtr()->arg_type_begin(), 4241a009b59fc2c550a229b9146aabda8e33fe3a7771Douglas Gregor ParamTypes, &ParamDecls)) 4242dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 4243dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor } 4244dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 4245e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith // FIXME: Need to transform the exception-specification too. 4246e6975e9b0985ad7f7ff9187e38d95bfe9ac4181bRichard Smith 4247a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4248a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4249a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ResultType != T->getResultType() || 4250bd5f9f708aa31920d3bd73aa10fcb5de424c657aDouglas Gregor T->getNumArgs() != ParamTypes.size() || 4251a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { 4252a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildFunctionProtoType(ResultType, 4253a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ParamTypes.data(), 4254a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ParamTypes.size(), 4255a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->isVariadic(), 4256eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith T->hasTrailingReturn(), 4257fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman T->getTypeQuals(), 4258c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor T->getRefQualifier(), 4259fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman T->getExtInfo()); 4260a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4261a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4262a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 42631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4264a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); 4265796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); 4266796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); 4267dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor NewTL.setTrailingReturn(TL.getTrailingReturn()); 4268a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) 4269a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setArg(i, ParamDecls[i]); 4270a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4271a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4272577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 42731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4274577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4275577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformFunctionNoProtoType( 4276a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 427743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FunctionNoProtoTypeLoc TL) { 4278f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const FunctionNoProtoType *T = TL.getTypePtr(); 4279a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 4280a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (ResultType.isNull()) 4281a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4282a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4283a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4284a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4285a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ResultType != T->getResultType()) 4286a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildFunctionNoProtoType(ResultType); 4287a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4288a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); 4289796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeBegin(TL.getLocalRangeBegin()); 4290796aa443ab5ed036f42ef33fed629e1b4b34871bAbramo Bagnara NewTL.setLocalRangeEnd(TL.getLocalRangeEnd()); 4291dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor NewTL.setTrailingReturn(false); 4292a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4293a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4294577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 42951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4296ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> QualType 4297ed97649e9574b9d854fa4d6109c9333ae0993554John McCallTreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, 429843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall UnresolvedUsingTypeLoc TL) { 4299f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const UnresolvedUsingType *T = TL.getTypePtr(); 43007c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); 4301ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (!D) 4302ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return QualType(); 4303ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4304ed97649e9574b9d854fa4d6109c9333ae0993554John McCall QualType Result = TL.getType(); 4305ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (getDerived().AlwaysRebuild() || D != T->getDecl()) { 4306ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Result = getDerived().RebuildUnresolvedUsingType(D); 4307ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (Result.isNull()) 4308ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return QualType(); 4309ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 4310ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4311ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // We might get an arbitrary type spec type back. We should at 4312ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // least always get a type spec type, though. 4313ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); 4314ed97649e9574b9d854fa4d6109c9333ae0993554John McCall NewTL.setNameLoc(TL.getNameLoc()); 4315ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4316ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return Result; 4317ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 4318ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 4319577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4320a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, 432143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypedefTypeLoc TL) { 4322f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const TypedefType *T = TL.getTypePtr(); 4323162e1c1b487352434552147967c3dd296ebee2f7Richard Smith TypedefNameDecl *Typedef 4324162e1c1b487352434552147967c3dd296ebee2f7Richard Smith = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(), 4325162e1c1b487352434552147967c3dd296ebee2f7Richard Smith T->getDecl())); 4326577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Typedef) 4327577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 43281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4329a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4330a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4331a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Typedef != T->getDecl()) { 4332a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildTypedefType(Typedef); 4333a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4334a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4335a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4336a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4337a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); 4338a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 43391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4340a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4341577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 43421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4343577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4344a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, 434543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeOfExprTypeLoc TL) { 4346670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // typeof expressions are not potentially evaluated contexts 4347f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 43481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 434960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); 4350577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (E.isInvalid()) 4351577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 4352577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 435372b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman E = SemaRef.HandleExprEvaluationContextForTypeof(E.get()); 435472b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman if (E.isInvalid()) 435572b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman return QualType(); 435672b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman 4357a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4358a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4359cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall E.get() != TL.getUnderlyingExpr()) { 43602a984cad5ac3fdceeff2bd99daa7b90979313475John McCall Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); 4361a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4362a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4363577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 4364a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall else E.take(); 43651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4366a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); 4367cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setTypeofLoc(TL.getTypeofLoc()); 4368cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setLParenLoc(TL.getLParenLoc()); 4369cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setRParenLoc(TL.getRParenLoc()); 4370a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4371a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4372577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 43731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 43741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4375a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, 437643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeOfTypeLoc TL) { 4377cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); 4378cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); 4379cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall if (!New_Under_TI) 4380577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 43811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4382a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4383cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { 4384cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); 4385a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4386a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4387a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 43881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4389a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); 4390cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setTypeofLoc(TL.getTypeofLoc()); 4391cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setLParenLoc(TL.getLParenLoc()); 4392cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setRParenLoc(TL.getRParenLoc()); 4393cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setUnderlyingTInfo(New_Under_TI); 4394a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4395a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4396577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 43971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 43981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4399a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, 440043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DecltypeTypeLoc TL) { 4401f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DecltypeType *T = TL.getTypePtr(); 4402a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4403670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // decltype expressions are not potentially evaluated contexts 440476f3f69db1416425070177243e9f390122c553e0Richard Smith EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated, 0, 440576f3f69db1416425070177243e9f390122c553e0Richard Smith /*IsDecltype=*/ true); 44061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 440760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); 4408577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (E.isInvalid()) 4409577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 44101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 441176f3f69db1416425070177243e9f390122c553e0Richard Smith E = getSema().ActOnDecltypeExpression(E.take()); 441276f3f69db1416425070177243e9f390122c553e0Richard Smith if (E.isInvalid()) 441376f3f69db1416425070177243e9f390122c553e0Richard Smith return QualType(); 441476f3f69db1416425070177243e9f390122c553e0Richard Smith 4415a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4416a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4417a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall E.get() != T->getUnderlyingExpr()) { 44182a984cad5ac3fdceeff2bd99daa7b90979313475John McCall Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); 4419a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4420a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4421577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 4422a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall else E.take(); 4423a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4424a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); 4425a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 44261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4427a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4428577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 4429577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 4430577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4431ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType TreeTransform<Derived>::TransformUnaryTransformType( 4432ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt TypeLocBuilder &TLB, 4433ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformTypeLoc TL) { 4434ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType Result = TL.getType(); 4435ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt if (Result->isDependentType()) { 4436ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt const UnaryTransformType *T = TL.getTypePtr(); 4437ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt QualType NewBase = 4438ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt getDerived().TransformType(TL.getUnderlyingTInfo())->getType(); 4439ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt Result = getDerived().RebuildUnaryTransformType(NewBase, 4440ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt T->getUTTKind(), 4441ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt TL.getKWLoc()); 4442ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt if (Result.isNull()) 4443ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return QualType(); 4444ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt } 4445ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 4446ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result); 4447ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt NewTL.setKWLoc(TL.getKWLoc()); 4448ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt NewTL.setParensRange(TL.getParensRange()); 4449ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo()); 4450ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return Result; 4451ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt} 4452ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 4453ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunttemplate<typename Derived> 445434b41d939a1328f484511c6002ba2456db879a29Richard SmithQualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB, 445534b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoTypeLoc TL) { 445634b41d939a1328f484511c6002ba2456db879a29Richard Smith const AutoType *T = TL.getTypePtr(); 445734b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType OldDeduced = T->getDeducedType(); 445834b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType NewDeduced; 445934b41d939a1328f484511c6002ba2456db879a29Richard Smith if (!OldDeduced.isNull()) { 446034b41d939a1328f484511c6002ba2456db879a29Richard Smith NewDeduced = getDerived().TransformType(OldDeduced); 446134b41d939a1328f484511c6002ba2456db879a29Richard Smith if (NewDeduced.isNull()) 446234b41d939a1328f484511c6002ba2456db879a29Richard Smith return QualType(); 446334b41d939a1328f484511c6002ba2456db879a29Richard Smith } 446434b41d939a1328f484511c6002ba2456db879a29Richard Smith 446534b41d939a1328f484511c6002ba2456db879a29Richard Smith QualType Result = TL.getType(); 446634b41d939a1328f484511c6002ba2456db879a29Richard Smith if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced) { 446734b41d939a1328f484511c6002ba2456db879a29Richard Smith Result = getDerived().RebuildAutoType(NewDeduced); 446834b41d939a1328f484511c6002ba2456db879a29Richard Smith if (Result.isNull()) 446934b41d939a1328f484511c6002ba2456db879a29Richard Smith return QualType(); 447034b41d939a1328f484511c6002ba2456db879a29Richard Smith } 447134b41d939a1328f484511c6002ba2456db879a29Richard Smith 447234b41d939a1328f484511c6002ba2456db879a29Richard Smith AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result); 447334b41d939a1328f484511c6002ba2456db879a29Richard Smith NewTL.setNameLoc(TL.getNameLoc()); 447434b41d939a1328f484511c6002ba2456db879a29Richard Smith 447534b41d939a1328f484511c6002ba2456db879a29Richard Smith return Result; 447634b41d939a1328f484511c6002ba2456db879a29Richard Smith} 447734b41d939a1328f484511c6002ba2456db879a29Richard Smith 447834b41d939a1328f484511c6002ba2456db879a29Richard Smithtemplate<typename Derived> 4479a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, 448043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall RecordTypeLoc TL) { 4481f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const RecordType *T = TL.getTypePtr(); 4482577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor RecordDecl *Record 44837c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), 44847c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor T->getDecl())); 4485577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Record) 4486577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 44871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4488a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4489a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4490a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Record != T->getDecl()) { 4491a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildRecordType(Record); 4492a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4493a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4494a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 44951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4496a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); 4497a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 4498a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4499a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4500577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 45011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 45021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4503a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, 450443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall EnumTypeLoc TL) { 4505f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const EnumType *T = TL.getTypePtr(); 4506577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor EnumDecl *Enum 45077c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), 45087c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor T->getDecl())); 4509577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Enum) 4510577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 45111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4512a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4513a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 4514a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Enum != T->getDecl()) { 4515a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildEnumType(Enum); 4516a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4517a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4518a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4519a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4520a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); 4521a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 45221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4523a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4524577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 45257da2431c23ef1ee8acb114e39692246e1801afc2John McCall 45263cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCalltemplate<typename Derived> 45273cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallQualType TreeTransform<Derived>::TransformInjectedClassNameType( 45283cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TypeLocBuilder &TLB, 452943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall InjectedClassNameTypeLoc TL) { 45303cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall Decl *D = getDerived().TransformDecl(TL.getNameLoc(), 45313cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TL.getTypePtr()->getDecl()); 45323cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall if (!D) return QualType(); 45333cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 45343cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); 45353cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); 45363cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return T; 45373cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 45383cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 4539577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 4540577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateTypeParmType( 4541a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 454243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateTypeParmTypeLoc TL) { 4543a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return TransformTypeSpecType(TLB, TL); 4544577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 4545577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 45461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 454749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( 4548a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 454943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall SubstTemplateTypeParmTypeLoc TL) { 45500b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor const SubstTemplateTypeParmType *T = TL.getTypePtr(); 45510b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor 45520b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // Substitute into the replacement type, which itself might involve something 45530b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // that needs to be transformed. This only tends to occur with default 45540b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // template arguments of template template parameters. 45550b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName()); 45560b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor QualType Replacement = getDerived().TransformType(T->getReplacementType()); 45570b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor if (Replacement.isNull()) 45580b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor return QualType(); 45590b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor 45600b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // Always canonicalize the replacement type. 45610b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor Replacement = SemaRef.Context.getCanonicalType(Replacement); 45620b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor QualType Result 45630b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(), 45640b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor Replacement); 45650b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor 45660b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor // Propagate type-source information. 45670b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor SubstTemplateTypeParmTypeLoc NewTL 45680b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor = TLB.push<SubstTemplateTypeParmTypeLoc>(Result); 45690b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor NewTL.setNameLoc(TL.getNameLoc()); 45700b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor return Result; 45710b4bcb639a9aab9c466a9e6d6e61b3bd1bb36d68Douglas Gregor 457249a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall} 457349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 457449a832bd499d6f61c23655f1fac99f0dd229756eJohn McCalltemplate<typename Derived> 4575c3069d618f4661d923cb1b5c4525b082fce73b04Douglas GregorQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType( 4576c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor TypeLocBuilder &TLB, 4577c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor SubstTemplateTypeParmPackTypeLoc TL) { 4578c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor return TransformTypeSpecType(TLB, TL); 4579c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor} 4580c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregor 4581c3069d618f4661d923cb1b5c4525b082fce73b04Douglas Gregortemplate<typename Derived> 4582833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallQualType TreeTransform<Derived>::TransformTemplateSpecializationType( 458343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeLocBuilder &TLB, 458443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateSpecializationTypeLoc TL) { 458543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall const TemplateSpecializationType *T = TL.getTypePtr(); 4586828bff2079b6a91ecd7ed5b842c59527d7682789John McCall 45871d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor // The nested-name-specifier never matters in a TemplateSpecializationType, 45881d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor // because we can't have a dependent nested-name-specifier anyway. 45891d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor CXXScopeSpec SS; 459043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template 45911d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor = getDerived().TransformTemplateName(SS, T->getTemplateName(), 45921d752d7d68359fd8f7701585d4658aa70e129261Douglas Gregor TL.getTemplateNameLoc()); 459343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (Template.isNull()) 459443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return QualType(); 4595833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 459643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); 4597dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor} 459843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 4599b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmantemplate<typename Derived> 4600b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli FriedmanQualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB, 4601b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicTypeLoc TL) { 4602b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc()); 4603b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (ValueType.isNull()) 4604b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return QualType(); 4605b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4606b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman QualType Result = TL.getType(); 4607b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (getDerived().AlwaysRebuild() || 4608b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman ValueType != TL.getValueLoc().getType()) { 4609b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc()); 4610b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman if (Result.isNull()) 4611b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return QualType(); 4612b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman } 4613b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4614b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result); 4615b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman NewTL.setKWLoc(TL.getKWLoc()); 4616b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman NewTL.setLParenLoc(TL.getLParenLoc()); 4617b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman NewTL.setRParenLoc(TL.getRParenLoc()); 4618b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 4619b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return Result; 4620b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman} 4621b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 46227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregornamespace { 46237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \brief Simple iterator that traverses the template arguments in a 46247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// container that provides a \c getArgLoc() member function. 46257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// 46267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// This iterator is intended to be used with the iterator form of 46277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \c TreeTransform<Derived>::TransformTemplateArguments(). 46287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor template<typename ArgLocContainer> 46297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class TemplateArgumentLocContainerIterator { 46307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgLocContainer *Container; 46317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor unsigned Index; 46327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 46337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 46347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc value_type; 46357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc reference; 46367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef int difference_type; 46377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef std::input_iterator_tag iterator_category; 46387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 46397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class pointer { 46407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Arg; 46417ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 46427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 46437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } 46447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 46457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLoc *operator->() const { 46467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return &Arg; 46477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 46487ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 46497ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 46507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 46517ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator() {} 46527ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 46537ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator(ArgLocContainer &Container, 46547ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor unsigned Index) 46557ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor : Container(&Container), Index(Index) { } 46567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 46577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator &operator++() { 46587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++Index; 46597ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return *this; 46607ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 46617ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 46627ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator operator++(int) { 46637ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator Old(*this); 46647ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++(*this); 46657ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Old; 46667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 46677ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 46687ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc operator*() const { 46697ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Container->getArgLoc(Index); 46707ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 46717ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 46727ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor pointer operator->() const { 46737ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return pointer(Container->getArgLoc(Index)); 46747ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 46757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 46767ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator==(const TemplateArgumentLocContainerIterator &X, 4677f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor const TemplateArgumentLocContainerIterator &Y) { 46787ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Container == Y.Container && X.Index == Y.Index; 46797ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 46807ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 46817ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator!=(const TemplateArgumentLocContainerIterator &X, 4682f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor const TemplateArgumentLocContainerIterator &Y) { 46837ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return !(X == Y); 46847ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 46857ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 46867ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor} 46877ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 46887ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 468943fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate <typename Derived> 4690577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateSpecializationType( 4691833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TypeLocBuilder &TLB, 4692833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateSpecializationTypeLoc TL, 469343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template) { 4694d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo NewTemplateArgs; 4695d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 4696d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 46977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> 46987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgIterator; 46997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 47007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgIterator(TL, TL.getNumArgs()), 47017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor NewTemplateArgs)) 47027f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return QualType(); 47031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4704833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: maybe don't rebuild if all the template arguments are the same. 4705833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 4706833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall QualType Result = 4707833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall getDerived().RebuildTemplateSpecializationType(Template, 4708833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TL.getTemplateNameLoc(), 4709d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs); 47101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4711833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!Result.isNull()) { 47123e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // Specializations of template template parameters are represented as 47133e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // TemplateSpecializationTypes, and substitution of type alias templates 47143e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // within a dependent context can transform them into 47153e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // DependentTemplateSpecializationTypes. 47163e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith if (isa<DependentTemplateSpecializationType>(Result)) { 47173e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith DependentTemplateSpecializationTypeLoc NewTL 47183e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 471955d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara NewTL.setElaboratedKeywordLoc(SourceLocation()); 47203e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setQualifierLoc(NestedNameSpecifierLoc()); 472166581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 472255d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 47233e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setLAngleLoc(TL.getLAngleLoc()); 47243e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setRAngleLoc(TL.getRAngleLoc()); 47253e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 47263e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 47273e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith return Result; 47283e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 47293e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 4730833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateSpecializationTypeLoc NewTL 4731833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall = TLB.push<TemplateSpecializationTypeLoc>(Result); 473255d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 4733833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 4734833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setLAngleLoc(TL.getLAngleLoc()); 4735833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setRAngleLoc(TL.getRAngleLoc()); 4736833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 4737833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 4738833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 47391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4740833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return Result; 4741577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 47421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4743a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregortemplate <typename Derived> 4744a88f09f34e86125ee4e6949a757aaed314012664Douglas GregorQualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType( 4745a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TypeLocBuilder &TLB, 4746a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc TL, 4747087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor TemplateName Template, 4748087eb5a2d3c7988eb7c440cd86cc7479e57d5dc0Douglas Gregor CXXScopeSpec &SS) { 4749a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateArgumentListInfo NewTemplateArgs; 4750a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 4751a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 4752a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor typedef TemplateArgumentLocContainerIterator< 4753a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc> ArgIterator; 4754a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 4755a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor ArgIterator(TL, TL.getNumArgs()), 4756a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs)) 4757a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return QualType(); 4758a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4759a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor // FIXME: maybe don't rebuild if all the template arguments are the same. 4760a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4761a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) { 4762a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor QualType Result 4763a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = getSema().Context.getDependentTemplateSpecializationType( 4764a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TL.getTypePtr()->getKeyword(), 4765a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DTN->getQualifier(), 4766a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DTN->getIdentifier(), 4767a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs); 4768a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4769a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor DependentTemplateSpecializationTypeLoc NewTL 4770a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 477155d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 477294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context)); 477366581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 477455d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 4775a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setLAngleLoc(TL.getLAngleLoc()); 4776a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setRAngleLoc(TL.getRAngleLoc()); 4777a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 4778a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 4779a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return Result; 4780a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor } 4781a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4782a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor QualType Result 4783a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = getDerived().RebuildTemplateSpecializationType(Template, 478455d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara TL.getTemplateNameLoc(), 4785a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTemplateArgs); 4786a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4787a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor if (!Result.isNull()) { 4788a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor /// FIXME: Wrap this in an elaborated-type-specifier? 4789a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor TemplateSpecializationTypeLoc NewTL 4790a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor = TLB.push<TemplateSpecializationTypeLoc>(Result); 479166581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 479255d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 4793a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setLAngleLoc(TL.getLAngleLoc()); 4794a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setRAngleLoc(TL.getRAngleLoc()); 4795a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 4796a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 4797a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor } 4798a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 4799a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return Result; 4800a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor} 4801a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 48021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4803a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 4804465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, 480543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ElaboratedTypeLoc TL) { 4806f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const ElaboratedType *T = TL.getTypePtr(); 4807465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 48089e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 4809465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara // NOTE: the qualifier in an ElaboratedType is optional. 48109e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor if (TL.getQualifierLoc()) { 48119e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc 48129e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 48139e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor if (!QualifierLoc) 4814465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return QualType(); 4815465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 48161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 481743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); 481843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (NamedT.isNull()) 481943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return QualType(); 4820a63db84b164d3f1c987a3ea6251e3092db4f317bDaniel Dunbar 48213e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // C++0x [dcl.type.elab]p2: 48223e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // If the identifier resolves to a typedef-name or the simple-template-id 48233e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // resolves to an alias template specialization, the 48243e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith // elaborated-type-specifier is ill-formed. 48251804174e1591bf59118f317775b48edd0382c3f0Richard Smith if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) { 48261804174e1591bf59118f317775b48edd0382c3f0Richard Smith if (const TemplateSpecializationType *TST = 48271804174e1591bf59118f317775b48edd0382c3f0Richard Smith NamedT->getAs<TemplateSpecializationType>()) { 48281804174e1591bf59118f317775b48edd0382c3f0Richard Smith TemplateName Template = TST->getTemplateName(); 48291804174e1591bf59118f317775b48edd0382c3f0Richard Smith if (TypeAliasTemplateDecl *TAT = 48301804174e1591bf59118f317775b48edd0382c3f0Richard Smith dyn_cast_or_null<TypeAliasTemplateDecl>(Template.getAsTemplateDecl())) { 48311804174e1591bf59118f317775b48edd0382c3f0Richard Smith SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(), 48321804174e1591bf59118f317775b48edd0382c3f0Richard Smith diag::err_tag_reference_non_tag) << 4; 48331804174e1591bf59118f317775b48edd0382c3f0Richard Smith SemaRef.Diag(TAT->getLocation(), diag::note_declared_at); 48341804174e1591bf59118f317775b48edd0382c3f0Richard Smith } 48353e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 48363e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith } 48373e4c6c4c79a03f5cb0c4671d7c282d623c6dc35eRichard Smith 4838a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 4839a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 48409e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc != TL.getQualifierLoc() || 4841e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NamedT != T->getNamedType()) { 484238a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(), 48439e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor T->getKeyword(), 48449e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor QualifierLoc, NamedT); 4845a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4846a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4847a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 4848577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 4849465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 485038a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 48519e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 4852a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4853577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 48541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 48551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 48569d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCallQualType TreeTransform<Derived>::TransformAttributedType( 48579d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall TypeLocBuilder &TLB, 48589d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeLoc TL) { 48599d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall const AttributedType *oldType = TL.getTypePtr(); 48609d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc()); 48619d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (modifiedType.isNull()) 48629d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return QualType(); 48639d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 48649d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType result = TL.getType(); 48659d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 48669d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // FIXME: dependent operand expressions? 48679d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (getDerived().AlwaysRebuild() || 48689d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall modifiedType != oldType->getModifiedType()) { 48699d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // TODO: this is really lame; we should really be rebuilding the 48709d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall // equivalent type from first principles. 48719d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall QualType equivalentType 48729d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall = getDerived().TransformType(oldType->getEquivalentType()); 48739d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (equivalentType.isNull()) 48749d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return QualType(); 48759d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall result = SemaRef.Context.getAttributedType(oldType->getAttrKind(), 48769d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall modifiedType, 48779d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall equivalentType); 48789d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall } 48799d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 48809d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result); 48819d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrNameLoc(TL.getAttrNameLoc()); 48829d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (TL.hasAttrOperand()) 48839d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange()); 48849d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall if (TL.hasAttrExprOperand()) 48859d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrExprOperand(TL.getAttrExprOperand()); 48869d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall else if (TL.hasAttrEnumOperand()) 48879d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc()); 48889d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 48899d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall return result; 48909d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall} 48919d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCall 48929d156a7b1b2771e191f2f5a45a7b7a694129463bJohn McCalltemplate<typename Derived> 4893075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType 4894075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraTreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, 4895075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenTypeLoc TL) { 4896075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); 4897075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (Inner.isNull()) 4898075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(); 4899075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 4900075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Result = TL.getType(); 4901075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (getDerived().AlwaysRebuild() || 4902075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Inner != TL.getInnerLoc().getType()) { 4903075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Result = getDerived().RebuildParenType(Inner); 4904075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (Result.isNull()) 4905075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(); 4906075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 4907075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 4908075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); 4909075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara NewTL.setLParenLoc(TL.getLParenLoc()); 4910075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara NewTL.setRParenLoc(TL.getRParenLoc()); 4911075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return Result; 4912075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 4913075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 4914075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaratemplate<typename Derived> 49154714c12a1ab759156b78be8f109ea4c12213af57Douglas GregorQualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, 491643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentNameTypeLoc TL) { 4917f4c7371fb1d3cebcfb40abad4537bb82515704eaJohn McCall const DependentNameType *T = TL.getTypePtr(); 4918833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 49192494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor NestedNameSpecifierLoc QualifierLoc 49202494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 49212494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor if (!QualifierLoc) 4922577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 49231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 492433500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Result 49252494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor = getDerived().RebuildDependentNameType(T->getKeyword(), 492638a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara TL.getElaboratedKeywordLoc(), 49272494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor QualifierLoc, 49282494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor T->getIdentifier(), 492933500955d731c73717af52088b7fc0e7a85681e7John McCall TL.getNameLoc()); 4930a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 4931a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 4932a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 4933e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { 4934e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara QualType NamedT = ElabT->getNamedType(); 493533500955d731c73717af52088b7fc0e7a85681e7John McCall TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); 493633500955d731c73717af52088b7fc0e7a85681e7John McCall 4937e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 493838a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 49399e876876afc13aa671cc11a17c19907c599b9ab9Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 494033500955d731c73717af52088b7fc0e7a85681e7John McCall } else { 4941e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); 494238a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 49432494dd024b392b8def58bf067cc94b51c214cf77Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 4944e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setNameLoc(TL.getNameLoc()); 4945e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 4946a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 4947577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 49481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4949577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 495033500955d731c73717af52088b7fc0e7a85681e7John McCallQualType TreeTransform<Derived>:: 495133500955d731c73717af52088b7fc0e7a85681e7John McCall TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 495243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentTemplateSpecializationTypeLoc TL) { 495394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 495494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (TL.getQualifierLoc()) { 495594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualifierLoc 495694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc()); 495794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (!QualifierLoc) 4958a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor return QualType(); 4959a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor } 4960a88f09f34e86125ee4e6949a757aaed314012664Douglas Gregor 496143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived() 496294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc); 496343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall} 496443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 496543fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived> 496643fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>:: 496794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas GregorTransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 496894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor DependentTemplateSpecializationTypeLoc TL, 496994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NestedNameSpecifierLoc QualifierLoc) { 497094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor const DependentTemplateSpecializationType *T = TL.getTypePtr(); 497194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 497294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor TemplateArgumentListInfo NewTemplateArgs; 497394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 497494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 497594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 497694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor typedef TemplateArgumentLocContainerIterator< 497794fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor DependentTemplateSpecializationTypeLoc> ArgIterator; 497894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 497994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor ArgIterator(TL, TL.getNumArgs()), 498094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs)) 498194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return QualType(); 498294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 498394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualType Result 498494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), 498594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualifierLoc, 498694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor T->getIdentifier(), 498755d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara TL.getTemplateNameLoc(), 498894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTemplateArgs); 498994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (Result.isNull()) 499094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return QualType(); 499194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 499294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { 499394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor QualType NamedT = ElabT->getNamedType(); 499494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 499594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Copy information relevant to the template specialization. 499694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor TemplateSpecializationTypeLoc NamedTL 49970a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor = TLB.push<TemplateSpecializationTypeLoc>(NamedT); 499866581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 499955d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 500094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NamedTL.setLAngleLoc(TL.getLAngleLoc()); 500194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NamedTL.setRAngleLoc(TL.getRAngleLoc()); 5002944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 50030a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 500494fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 500594fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor // Copy information relevant to the elaborated type. 500694fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 500738a42916cb07fd368d9e2ae1e7915fa896f9ec06Abramo Bagnara NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 500894fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor NewTL.setQualifierLoc(QualifierLoc); 50090a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor } else if (isa<DependentTemplateSpecializationType>(Result)) { 50100a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor DependentTemplateSpecializationTypeLoc SpecTL 50110a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor = TLB.push<DependentTemplateSpecializationTypeLoc>(Result); 501255d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc()); 50130a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setQualifierLoc(QualifierLoc); 501466581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 501555d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 50160a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setLAngleLoc(TL.getLAngleLoc()); 50170a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setRAngleLoc(TL.getRAngleLoc()); 5018944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 50190a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 502094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor } else { 50210a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor TemplateSpecializationTypeLoc SpecTL 50220a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor = TLB.push<TemplateSpecializationTypeLoc>(Result); 502366581d41527628d4b37f7b05c288f77be7415d7dAbramo Bagnara SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc()); 502455d23c925b058be29b792008ddb7d68f6c4fa9a0Abramo Bagnara SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 50250a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setLAngleLoc(TL.getLAngleLoc()); 50260a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setRAngleLoc(TL.getRAngleLoc()); 5027944cdae86ecb2ab5deda96804099bd28f6a6cd39Douglas Gregor for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I) 50280a0367a479e2ad204a97f87ed72f18209169b775Douglas Gregor SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo()); 502994fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor } 503094fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor return Result; 503194fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor} 503294fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregor 503394fdffa4a572fc14ac296f5f1aae9db3734c72f1Douglas Gregortemplate<typename Derived> 50347536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas GregorQualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, 50357536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor PackExpansionTypeLoc TL) { 50362fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor QualType Pattern 50372fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor = getDerived().TransformType(TLB, TL.getPatternLoc()); 50382fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor if (Pattern.isNull()) 50392fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor return QualType(); 50402fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor 50412fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor QualType Result = TL.getType(); 50422fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor if (getDerived().AlwaysRebuild() || 50432fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor Pattern != TL.getPatternLoc().getType()) { 50442fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor Result = getDerived().RebuildPackExpansionType(Pattern, 50452fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor TL.getPatternLoc().getSourceRange(), 5046cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor TL.getEllipsisLoc(), 5047cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor TL.getTypePtr()->getNumExpansions()); 50482fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor if (Result.isNull()) 50492fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor return QualType(); 50502fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor } 50512fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor 50522fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result); 50532fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor NewT.setEllipsisLoc(TL.getEllipsisLoc()); 50542fc1bb76e719d0620b4a6e2134413933b21ca6b6Douglas Gregor return Result; 50557536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor} 50567536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 50577536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregortemplate<typename Derived> 5058a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 5059a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, 506043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCInterfaceTypeLoc TL) { 5061ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor // ObjCInterfaceType is never dependent. 5062c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 5063c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return TL.getType(); 5064c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 5065c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 5066c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCalltemplate<typename Derived> 5067c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallQualType 5068c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallTreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, 506943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCObjectTypeLoc TL) { 5070c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // ObjCObjectType is never dependent. 5071c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 5072ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor return TL.getType(); 5073577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 50741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 50751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 5076a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 5077a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, 507843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCObjectPointerTypeLoc TL) { 5079ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor // ObjCObjectPointerType is never dependent. 5080c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 5081ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor return TL.getType(); 508224fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis} 508324fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 5084577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 508543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor// Statement transformation 508643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===// 508743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 508860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 50891eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformNullStmt(NullStmt *S) { 50903fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 509143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 509243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 509343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 509460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 509543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { 509643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().TransformCompoundStmt(S, false); 509743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 509843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 509943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 510060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 51011eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, 510243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool IsStmtExpr) { 5103625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko Sema::CompoundScopeRAII CompoundScope(getSema()); 5104625bb569df0c34feec0d52c0ec5215f21ef2e054Dmitri Gribenko 51057114cbab7eb6e8b714eb22f014327daf2c741c08John McCall bool SubStmtInvalid = false; 510643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool SubStmtChanged = false; 5107ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Stmt*> Statements(getSema()); 510843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); 510943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor B != BEnd; ++B) { 511060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Result = getDerived().TransformStmt(*B); 51117114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (Result.isInvalid()) { 51127114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // Immediately fail if this was a DeclStmt, since it's very 51137114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // likely that this will cause problems for future statements. 51147114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (isa<DeclStmt>(*B)) 51157114cbab7eb6e8b714eb22f014327daf2c741c08John McCall return StmtError(); 51167114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 51177114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // Otherwise, just keep processing substatements and fail later. 51187114cbab7eb6e8b714eb22f014327daf2c741c08John McCall SubStmtInvalid = true; 51197114cbab7eb6e8b714eb22f014327daf2c741c08John McCall continue; 51207114cbab7eb6e8b714eb22f014327daf2c741c08John McCall } 51211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 512243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SubStmtChanged = SubStmtChanged || Result.get() != *B; 512343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Statements.push_back(Result.takeAs<Stmt>()); 512443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 51251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 51267114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (SubStmtInvalid) 51277114cbab7eb6e8b714eb22f014327daf2c741c08John McCall return StmtError(); 51287114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 512943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 513043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !SubStmtChanged) 51313fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 513243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 513343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildCompoundStmt(S->getLBracLoc(), 513443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor move_arg(Statements), 513543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getRBracLoc(), 513643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor IsStmtExpr); 513743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 51381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 513943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 514060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 51411eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { 514260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS, RHS; 5143264c1f8ec895952466eab59b84b8b06801e721faEli Friedman { 51446b3014b07c40a6ed8b0c8ed63950df02eeb82c28Eli Friedman EnterExpressionEvaluationContext Unevaluated(SemaRef, 51456b3014b07c40a6ed8b0c8ed63950df02eeb82c28Eli Friedman Sema::ConstantEvaluated); 51461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5147264c1f8ec895952466eab59b84b8b06801e721faEli Friedman // Transform the left-hand case value. 5148264c1f8ec895952466eab59b84b8b06801e721faEli Friedman LHS = getDerived().TransformExpr(S->getLHS()); 5149ac6260187b6b2f26faa9264d170d649a501f58a9Eli Friedman LHS = SemaRef.ActOnConstantExpression(LHS); 5150264c1f8ec895952466eab59b84b8b06801e721faEli Friedman if (LHS.isInvalid()) 5151f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5153264c1f8ec895952466eab59b84b8b06801e721faEli Friedman // Transform the right-hand case value (for the GNU case-range extension). 5154264c1f8ec895952466eab59b84b8b06801e721faEli Friedman RHS = getDerived().TransformExpr(S->getRHS()); 5155ac6260187b6b2f26faa9264d170d649a501f58a9Eli Friedman RHS = SemaRef.ActOnConstantExpression(RHS); 5156264c1f8ec895952466eab59b84b8b06801e721faEli Friedman if (RHS.isInvalid()) 5157f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5158264c1f8ec895952466eab59b84b8b06801e721faEli Friedman } 51591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 516043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Build the case statement. 516143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Case statements are always rebuilt so that they will attached to their 516243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transformed switch statement. 516360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), 51649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), 516543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getEllipsisLoc(), 51669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get(), 516743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getColonLoc()); 516843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Case.isInvalid()) 5169f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 517143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the statement following the case 517260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 517343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 5174f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 517643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Attach the body to the case statement 51779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); 517843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 517943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 518043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 518160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 51821eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { 518343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the statement following the default case 518460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 518543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 5186f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 518843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Default statements are always rebuilt 518943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), 51909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubStmt.get()); 519143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 51921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 519343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 519460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 51951eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { 519660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 519743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 5198f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 51991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 520057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(), 520157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner S->getDecl()); 520257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner if (!LD) 520357ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return StmtError(); 5204534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 5205534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 520643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // FIXME: Pass the real colon location in. 5207ad8dcf4a9df0e24051dc31bf9e6f3cd138a34298Chris Lattner return getDerived().RebuildLabelStmt(S->getIdentLoc(), 520857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner cast<LabelDecl>(LD), SourceLocation(), 520957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner SubStmt.get()); 521043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 52111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 521243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 521360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 5214534986f2b21e6050bf00163cd6423fd92155a6edRichard SmithTreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) { 5215534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 5216534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith if (SubStmt.isInvalid()) 5217534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith return StmtError(); 5218534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 5219534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith // TODO: transform attributes 5220534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith if (SubStmt.get() == S->getSubStmt() /* && attrs are the same */) 5221534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith return S; 5222534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 5223534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith return getDerived().RebuildAttributedStmt(S->getAttrLoc(), 5224534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith S->getAttrs(), 5225534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith SubStmt.get()); 5226534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith} 5227534986f2b21e6050bf00163cd6423fd92155a6edRichard Smith 5228534986f2b21e6050bf00163cd6423fd92155a6edRichard Smithtemplate<typename Derived> 5229534986f2b21e6050bf00163cd6423fd92155a6edRichard SmithStmtResult 52301eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIfStmt(IfStmt *S) { 523143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 523260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 52338cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor VarDecl *ConditionVar = 0; 52348cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor if (S->getConditionVariable()) { 5235c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 52368cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor = cast_or_null<VarDecl>( 5237aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5238aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5239aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 52408cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor if (!ConditionVar) 5241f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 524299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 52438cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 5244c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 524599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5246f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5247eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 5248eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor // Convert the condition to a boolean value. 5249afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 52508491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), 52518491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 5252afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 5253f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5254eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 52559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE.get(); 5256afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 525799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 5258c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 52599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 52609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 5261f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5262eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 526343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the "then" branch. 526460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Then = getDerived().TransformStmt(S->getThen()); 526543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Then.isInvalid()) 5266f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 526843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the "else" branch. 526960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Else = getDerived().TransformStmt(S->getElse()); 527043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Else.isInvalid()) 5271f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 52721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 527343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 52749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 527599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor ConditionVar == S->getConditionVariable() && 527643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Then.get() == S->getThen() && 527743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Else.get() == S->getElse()) 52783fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 52791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5280eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, 528144aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis Then.get(), 52829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall S->getElseLoc(), Else.get()); 528343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 528443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 528543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 528660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 52871eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { 528843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition. 528960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 5290d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor VarDecl *ConditionVar = 0; 5291d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor if (S->getConditionVariable()) { 5292c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 5293d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor = cast_or_null<VarDecl>( 5294aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5295aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5296aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 5297d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor if (!ConditionVar) 5298f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 529999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 5300d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 5301c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 530299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5303f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 530499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 53051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 530643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Rebuild the switch statement. 530760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Switch 53089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), 5309586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor ConditionVar); 531043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Switch.isInvalid()) 5311f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 53121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 531343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body of the switch statement. 531460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 531543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5316f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 53171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 531843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Complete the switch statement. 53199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), 53209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 532143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 53221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 532343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 532460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 53251eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { 532643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 532760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 53285656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor VarDecl *ConditionVar = 0; 53295656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor if (S->getConditionVariable()) { 5330c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 53315656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor = cast_or_null<VarDecl>( 5332aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5333aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5334aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 53355656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor if (!ConditionVar) 5336f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 533799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 53385656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 5339c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 534099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5341f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5342afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 5343afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 5344afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor // Convert the condition to a boolean value. 53458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), 53468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 5347afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 5348f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 53499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE; 5350afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 535199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 53521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 53539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 53549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 5355f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5356eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 535743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 535860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 535943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5360f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 53611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 536243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 53639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 536499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor ConditionVar == S->getConditionVariable() && 536543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 53669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Owned(S); 53671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5368eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, 53699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ConditionVar, Body.get()); 537043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 53711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 537243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 537360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 537443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformDoStmt(DoStmt *S) { 537543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 537660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 537743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5378f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 53791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5380eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor // Transform the condition 538160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(S->getCond()); 5382eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor if (Cond.isInvalid()) 5383f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5384eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 538543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 538643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Cond.get() == S->getCond() && 538743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 53883fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 53891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 53909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), 53919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall /*FIXME:*/S->getWhileLoc(), Cond.get(), 539243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getRParenLoc()); 539343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 53941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 539543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 539660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 53971eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformForStmt(ForStmt *S) { 539843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the initialization statement 539960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Init = getDerived().TransformStmt(S->getInit()); 540043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Init.isInvalid()) 5401f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 54021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 540343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 540460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 540599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor VarDecl *ConditionVar = 0; 540699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (S->getConditionVariable()) { 5407c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 540899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor = cast_or_null<VarDecl>( 5409aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 5410aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 5411aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 541299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (!ConditionVar) 5413f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 541499e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 541599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 5416c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 541799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 5418f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5419afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 5420afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 5421afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor // Convert the condition to a boolean value. 54228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), 54238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 5424afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 5425f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5426afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 54279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE.get(); 5428afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 542999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 54301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 54319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 54329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 5433f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5434eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 543543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the increment 543660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Inc = getDerived().TransformExpr(S->getInc()); 543743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Inc.isInvalid()) 5438f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 54391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 54409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get())); 54419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (S->getInc() && !FullInc.get()) 5442f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5443eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 544443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 544560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 544643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 5447f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 54481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 544943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 545043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Init.get() == S->getInit() && 54519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 545243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Inc.get() == S->getInc() && 545343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 54543fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 54551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 545643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), 54579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init.get(), FullCond, ConditionVar, 54589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullInc, S->getRParenLoc(), Body.get()); 545943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 546043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 546143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 546260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 54631eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { 546457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(), 546557ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner S->getLabel()); 546657ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner if (!LD) 546757ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return StmtError(); 546857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 546943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Goto statements must always be rebuilt, to resolve the label. 54701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), 547157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner cast<LabelDecl>(LD)); 547243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 547343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 547443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 547560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 54761eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { 547760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Target = getDerived().TransformExpr(S->getTarget()); 547843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Target.isInvalid()) 5479f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5480d29975fd08713eb9d1777e60536addaa62df8995Eli Friedman Target = SemaRef.MaybeCreateExprWithCleanups(Target.take()); 54811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 548243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 548343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Target.get() == S->getTarget()) 54843fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 548543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 548643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), 54879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Target.get()); 548843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 548943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 549043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 549160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 54921eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { 54933fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 549443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 54951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 549643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 549760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 54981eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { 54993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 550043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 55011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 550243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 550360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 55041eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { 550560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(S->getRetValue()); 550643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Result.isInvalid()) 5507f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 550843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 55091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // FIXME: We always rebuild the return statement because there is no way 551043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // to tell whether the return type of the function has changed. 55119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); 551243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 55131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 551443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 551560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 55161eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { 551743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool DeclChanged = false; 5518686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<Decl *, 4> Decls; 551943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); 552043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor D != DEnd; ++D) { 5521aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), 5522aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor *D); 552343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!Transformed) 5524f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 55251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 552643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Transformed != *D) 552743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor DeclChanged = true; 55281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 552943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Decls.push_back(Transformed); 553043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 55311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 553243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && !DeclChanged) 55333fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 55341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 55351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), 553643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getStartLoc(), S->getEndLoc()); 553743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 55381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 553943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 554060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 554143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { 5542c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5543ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Constraints(getSema()); 5544ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Exprs(getSema()); 5545686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<IdentifierInfo *, 4> Names; 5546a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson 554760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult AsmString; 5548ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Clobbers(getSema()); 5549703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5550703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool ExprsChanged = false; 5551c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5552703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the outputs. 5553703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { 5554ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson Names.push_back(S->getOutputIdentifier(I)); 5555c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5556703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the constraint literal. 55573fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Constraints.push_back(S->getOutputConstraintLiteral(I)); 5558c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5559703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Transform the output expr. 5560703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson Expr *OutputExpr = S->getOutputExpr(I); 556160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(OutputExpr); 5562703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (Result.isInvalid()) 5563f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5564c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5565703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson ExprsChanged |= Result.get() != OutputExpr; 5566c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 55679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs.push_back(Result.get()); 5568703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 5569c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5570703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the inputs. 5571703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { 5572ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson Names.push_back(S->getInputIdentifier(I)); 5573c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5574703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the constraint literal. 55753fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Constraints.push_back(S->getInputConstraintLiteral(I)); 5576c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5577703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Transform the input expr. 5578703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson Expr *InputExpr = S->getInputExpr(I); 557960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(InputExpr); 5580703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (Result.isInvalid()) 5581f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5582c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5583703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson ExprsChanged |= Result.get() != InputExpr; 5584c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 55859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs.push_back(Result.get()); 5586703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 5587c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5588703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (!getDerived().AlwaysRebuild() && !ExprsChanged) 55893fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 5590703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5591703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the clobbers. 5592703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) 55933fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Clobbers.push_back(S->getClobber(I)); 5594703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5595703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the asm string literal. 5596703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson AsmString = SemaRef.Owned(S->getAsmString()); 5597703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 5598703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson return getDerived().RebuildAsmStmt(S->getAsmLoc(), 5599703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isSimple(), 5600703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isVolatile(), 5601703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getNumOutputs(), 5602703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getNumInputs(), 5603a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson Names.data(), 5604703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson move_arg(Constraints), 5605703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson move_arg(Exprs), 56069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall AsmString.get(), 5607703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson move_arg(Clobbers), 5608703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getRParenLoc(), 5609703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isMSAsm()); 561043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 561143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 56128cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosiertemplate<typename Derived> 56138cd64b4c5553fa6284d248336cb7c82dc960a394Chad RosierStmtResult 56148cd64b4c5553fa6284d248336cb7c82dc960a394Chad RosierTreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) { 56158cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier // No need to transform the asm string literal. 56168cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), 56178cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier *S->getAsmString(), 56188cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier S->getEndLoc()); 56198cd64b4c5553fa6284d248336cb7c82dc960a394Chad Rosier} 562043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 562143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 562260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 56231eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { 56244dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the body of the @try. 562560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); 56264dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (TryBody.isInvalid()) 5627f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5628c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 56298f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor // Transform the @catch statements (if present). 56308f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor bool AnyCatchChanged = false; 5631ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Stmt*> CatchStmts(SemaRef); 56328f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { 563360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); 56344dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Catch.isInvalid()) 5635f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 56368f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor if (Catch.get() != S->getCatchStmt(I)) 56378f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor AnyCatchChanged = true; 56388f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor CatchStmts.push_back(Catch.release()); 56394dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 5640c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 56414dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the @finally statement (if present). 564260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Finally; 56434dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (S->getFinallyStmt()) { 56444dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Finally = getDerived().TransformStmt(S->getFinallyStmt()); 56454dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Finally.isInvalid()) 5646f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 56474dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 56484dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 56494dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // If nothing changed, just retain this statement. 56504dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (!getDerived().AlwaysRebuild() && 56514dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor TryBody.get() == S->getTryBody() && 56528f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor !AnyCatchChanged && 56534dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Finally.get() == S->getFinallyStmt()) 56543fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 5655c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 56564dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Build a new statement. 56579ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), 56589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall move_arg(CatchStmts), Finally.get()); 565943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 56601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 566143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 566260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 56631eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { 5664be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor // Transform the @catch parameter, if there is one. 5665be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *Var = 0; 5666be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (VarDecl *FromVar = S->getCatchParamDecl()) { 5667be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TypeSourceInfo *TSInfo = 0; 5668be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (FromVar->getTypeSourceInfo()) { 5669be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); 5670be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (!TSInfo) 5671f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5672be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 5673c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5674be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor QualType T; 5675be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (TSInfo) 5676be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor T = TSInfo->getType(); 5677be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor else { 5678be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor T = getDerived().TransformType(FromVar->getType()); 5679be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (T.isNull()) 5680f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5681be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 5682c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5683be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); 5684be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (!Var) 5685f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5686be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 5687c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 568860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); 5689be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (Body.isInvalid()) 5690f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5691c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5692c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), 5693be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor S->getRParenLoc(), 56949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Var, Body.get()); 569543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 56961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 569743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 569860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 56991eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { 57004dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the body. 570160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); 57024dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Body.isInvalid()) 5703f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5704c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 57054dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // If nothing changed, just retain this statement. 57064dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (!getDerived().AlwaysRebuild() && 57074dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Body.get() == S->getFinallyBody()) 57083fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 57094dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 57104dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Build a new statement. 57114dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), 57129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 571343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 57141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 571543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 571660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 57171eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { 571860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Operand; 5719d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (S->getThrowExpr()) { 5720d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor Operand = getDerived().TransformExpr(S->getThrowExpr()); 5721d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (Operand.isInvalid()) 5722f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5723d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor } 5724c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5725d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (!getDerived().AlwaysRebuild() && 5726d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor Operand.get() == S->getThrowExpr()) 57273fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return getSema().Owned(S); 5728c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 57299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); 573043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 57311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 573243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 573360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 573443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCAtSynchronizedStmt( 57351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCAtSynchronizedStmt *S) { 57368fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Transform the object we are locking. 573760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); 57388fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (Object.isInvalid()) 5739f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 574007524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Object = 574107524039dce5c820f111a1b3f772b4261f004b4aJohn McCall getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(), 574207524039dce5c820f111a1b3f772b4261f004b4aJohn McCall Object.get()); 574307524039dce5c820f111a1b3f772b4261f004b4aJohn McCall if (Object.isInvalid()) 574407524039dce5c820f111a1b3f772b4261f004b4aJohn McCall return StmtError(); 5745c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 57468fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Transform the body. 574760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); 57488fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (Body.isInvalid()) 5749f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5750c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 57518fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // If nothing change, just retain the current statement. 57528fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (!getDerived().AlwaysRebuild() && 57538fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor Object.get() == S->getSynchExpr() && 57548fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor Body.get() == S->getSynchBody()) 57553fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 57568fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor 57578fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Build a new statement. 57588fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), 57599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Object.get(), Body.get()); 576043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 576143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 576243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 576360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 5764f85e193739c953358c865005855253af4f68a497John McCallTreeTransform<Derived>::TransformObjCAutoreleasePoolStmt( 5765f85e193739c953358c865005855253af4f68a497John McCall ObjCAutoreleasePoolStmt *S) { 5766f85e193739c953358c865005855253af4f68a497John McCall // Transform the body. 5767f85e193739c953358c865005855253af4f68a497John McCall StmtResult Body = getDerived().TransformStmt(S->getSubStmt()); 5768f85e193739c953358c865005855253af4f68a497John McCall if (Body.isInvalid()) 5769f85e193739c953358c865005855253af4f68a497John McCall return StmtError(); 5770f85e193739c953358c865005855253af4f68a497John McCall 5771f85e193739c953358c865005855253af4f68a497John McCall // If nothing changed, just retain this statement. 5772f85e193739c953358c865005855253af4f68a497John McCall if (!getDerived().AlwaysRebuild() && 5773f85e193739c953358c865005855253af4f68a497John McCall Body.get() == S->getSubStmt()) 5774f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(S); 5775f85e193739c953358c865005855253af4f68a497John McCall 5776f85e193739c953358c865005855253af4f68a497John McCall // Build a new statement. 5777f85e193739c953358c865005855253af4f68a497John McCall return getDerived().RebuildObjCAutoreleasePoolStmt( 5778f85e193739c953358c865005855253af4f68a497John McCall S->getAtLoc(), Body.get()); 5779f85e193739c953358c865005855253af4f68a497John McCall} 5780f85e193739c953358c865005855253af4f68a497John McCall 5781f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived> 5782f85e193739c953358c865005855253af4f68a497John McCallStmtResult 578343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCForCollectionStmt( 57841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCForCollectionStmt *S) { 5785c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the element statement. 578660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Element = getDerived().TransformStmt(S->getElement()); 5787c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Element.isInvalid()) 5788f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5789c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5790c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the collection expression. 579160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Collection = getDerived().TransformExpr(S->getCollection()); 5792c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Collection.isInvalid()) 5793f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5794990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall Collection = getDerived().RebuildObjCForCollectionOperand(S->getForLoc(), 5795990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall Collection.take()); 5796990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall if (Collection.isInvalid()) 5797990567cb60e8530ba01b41d4e056e32b44b95ec0John McCall return StmtError(); 5798c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5799c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the body. 580060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 5801c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Body.isInvalid()) 5802f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 5803c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5804c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // If nothing changed, just retain this statement. 5805c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (!getDerived().AlwaysRebuild() && 5806c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Element.get() == S->getElement() && 5807c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Collection.get() == S->getCollection() && 5808c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Body.get() == S->getBody()) 58093fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 5810c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5811c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Build a new statement. 5812c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), 5813c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /*FIXME:*/S->getForLoc(), 58149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Element.get(), 58159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Collection.get(), 5816c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor S->getRParenLoc(), 58179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 581843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 581943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 582043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 582143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 582260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 582343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { 582443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the exception declaration, if any. 582543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor VarDecl *Var = 0; 582643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (S->getExceptionDecl()) { 582743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor VarDecl *ExceptionDecl = S->getExceptionDecl(); 582883cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor TypeSourceInfo *T = getDerived().TransformType( 582983cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor ExceptionDecl->getTypeSourceInfo()); 583083cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor if (!T) 5831f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 58321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 583383cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, 5834ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getInnerLocStart(), 5835ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getLocation(), 5836ff676cb48fe8bf7be2feaa251dc7c5fb15af4730Abramo Bagnara ExceptionDecl->getIdentifier()); 5837ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor if (!Var || Var->isInvalidDecl()) 5838f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 583943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 58401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 584143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the actual exception handler. 584260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); 5843ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor if (Handler.isInvalid()) 5844f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 58451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 584643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 584743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !Var && 584843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Handler.get() == S->getHandlerBlock()) 58493fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 585043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 585143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), 585243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Var, 58539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Handler.get()); 585443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 58551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 585643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 585760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 585843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { 585943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the try block itself. 586060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TryBlock 586143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor = getDerived().TransformCompoundStmt(S->getTryBlock()); 586243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (TryBlock.isInvalid()) 5863f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 58641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 586543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the handlers. 586643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool HandlerChanged = false; 5867ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Stmt*> Handlers(SemaRef); 586843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { 586960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Handler 587043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor = getDerived().TransformCXXCatchStmt(S->getHandler(I)); 587143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Handler.isInvalid()) 5872f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 58731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 587443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); 587543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Handlers.push_back(Handler.takeAs<Stmt>()); 587643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 58771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 587843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 587943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor TryBlock.get() == S->getTryBlock() && 588043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !HandlerChanged) 58813fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 588243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 58839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), 58841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump move_arg(Handlers)); 588543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 58861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5887ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smithtemplate<typename Derived> 5888ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithStmtResult 5889ad762fcdc16b9e4705b12b09d92b8c026212b906Richard SmithTreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) { 5890ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult Range = getDerived().TransformStmt(S->getRangeStmt()); 5891ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Range.isInvalid()) 5892ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5893ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5894ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt()); 5895ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (BeginEnd.isInvalid()) 5896ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5897ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5898ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ExprResult Cond = getDerived().TransformExpr(S->getCond()); 5899ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Cond.isInvalid()) 5900ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5901c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman if (Cond.get()) 5902c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman Cond = SemaRef.CheckBooleanCondition(Cond.take(), S->getColonLoc()); 5903c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman if (Cond.isInvalid()) 5904c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman return StmtError(); 5905c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman if (Cond.get()) 5906c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.take()); 5907ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5908ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith ExprResult Inc = getDerived().TransformExpr(S->getInc()); 5909ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Inc.isInvalid()) 5910ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5911c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman if (Inc.get()) 5912c6c14e56e34864c5d9343d9ea62ab688cf301eeeEli Friedman Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.take()); 5913ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5914ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt()); 5915ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (LoopVar.isInvalid()) 5916ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5917ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5918ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith StmtResult NewStmt = S; 5919ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (getDerived().AlwaysRebuild() || 5920ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Range.get() != S->getRangeStmt() || 5921ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith BeginEnd.get() != S->getBeginEndStmt() || 5922ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Cond.get() != S->getCond() || 5923ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Inc.get() != S->getInc() || 5924ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith LoopVar.get() != S->getLoopVarStmt()) 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 StmtResult Body = getDerived().TransformStmt(S->getBody()); 5932ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Body.isInvalid()) 5933ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return StmtError(); 5934ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5935ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith // Body has changed but we didn't rebuild the for-range statement. Rebuild 5936ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith // it now so we have a new statement to attach the body to. 5937ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (Body.get() != S->getBody() && NewStmt.get() == S) 5938ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(), 5939ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getColonLoc(), Range.get(), 5940ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith BeginEnd.get(), Cond.get(), 5941ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith Inc.get(), LoopVar.get(), 5942ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith S->getRParenLoc()); 5943ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5944ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith if (NewStmt.get() == S) 5945ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return SemaRef.Owned(S); 5946ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 5947ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith return FinishCXXForRangeStmt(NewStmt.get(), Body.get()); 5948ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith} 5949ad762fcdc16b9e4705b12b09d92b8c026212b906Richard Smith 595028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 595128bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 5952ba0513de93d2fab6db5ab30b6927209fcc883078Douglas GregorTreeTransform<Derived>::TransformMSDependentExistsStmt( 5953ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor MSDependentExistsStmt *S) { 5954ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // Transform the nested-name-specifier, if any. 5955ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 5956ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (S->getQualifierLoc()) { 5957ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor QualifierLoc 5958ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc()); 5959ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (!QualifierLoc) 5960ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return StmtError(); 5961ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor } 5962ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5963ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // Transform the declaration name. 5964ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor DeclarationNameInfo NameInfo = S->getNameInfo(); 5965ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (NameInfo.getName()) { 5966ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 5967ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (!NameInfo.getName()) 5968ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return StmtError(); 5969ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor } 5970ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5971ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // Check whether anything changed. 5972ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (!getDerived().AlwaysRebuild() && 5973ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor QualifierLoc == S->getQualifierLoc() && 5974ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NameInfo.getName() == S->getNameInfo().getName()) 5975ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return S; 5976ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5977ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // Determine whether this name exists, if we can. 5978ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor CXXScopeSpec SS; 5979ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor SS.Adopt(QualifierLoc); 5980ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor bool Dependent = false; 5981ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/0, SS, NameInfo)) { 5982ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor case Sema::IER_Exists: 5983ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (S->isIfExists()) 5984ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor break; 5985ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5986ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return new (getSema().Context) NullStmt(S->getKeywordLoc()); 5987ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5988ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor case Sema::IER_DoesNotExist: 5989ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (S->isIfNotExists()) 5990ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor break; 5991ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5992ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return new (getSema().Context) NullStmt(S->getKeywordLoc()); 5993ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 5994ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor case Sema::IER_Dependent: 5995ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor Dependent = true; 5996ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor break; 599765019acfc46ffb191fac4e781ac0c4b8d0c8434eDouglas Gregor 599865019acfc46ffb191fac4e781ac0c4b8d0c8434eDouglas Gregor case Sema::IER_Error: 599965019acfc46ffb191fac4e781ac0c4b8d0c8434eDouglas Gregor return StmtError(); 6000ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor } 6001ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 6002ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // We need to continue with the instantiation, so do so now. 6003ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt()); 6004ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (SubStmt.isInvalid()) 6005ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return StmtError(); 6006ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 6007ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // If we have resolved the name, just transform to the substatement. 6008ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor if (!Dependent) 6009ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return SubStmt; 6010ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 6011ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor // The name is still dependent, so build a dependent expression again. 6012ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(), 6013ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor S->isIfExists(), 6014ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor QualifierLoc, 6015ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor NameInfo, 6016ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor SubStmt.get()); 6017ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor} 6018ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregor 6019ba0513de93d2fab6db5ab30b6927209fcc883078Douglas Gregortemplate<typename Derived> 6020ba0513de93d2fab6db5ab30b6927209fcc883078Douglas GregorStmtResult 602128bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) { 602228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult TryBlock; // = getDerived().TransformCompoundStmt(S->getTryBlock()); 602328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(TryBlock.isInvalid()) return StmtError(); 602428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 602528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler()); 602628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(!getDerived().AlwaysRebuild() && 602728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley TryBlock.get() == S->getTryBlock() && 602828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Handler.get() == S->getHandler()) 602928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return SemaRef.Owned(S); 603028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 603128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), 603228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley S->getTryLoc(), 603328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley TryBlock.take(), 603428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Handler.take()); 603528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 603628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 603728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 603828bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 603928bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) { 604028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); 604128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(Block.isInvalid()) return StmtError(); 604228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 604328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), 604428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Block.take()); 604528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 604628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 604728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 604828bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 604928bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) { 605028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr()); 605128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(FilterExpr.isInvalid()) return StmtError(); 605228bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 605328bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley StmtResult Block; // = getDerived().TransformCompoundStatement(S->getBlock()); 605428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(Block.isInvalid()) return StmtError(); 605528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 605628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), 605728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley FilterExpr.take(), 605828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley Block.take()); 605928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 606028bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 606128bbe4b8acc338476fe0825769b41fb32b423c72John Wiegleytemplate<typename Derived> 606228bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyStmtResult 606328bbe4b8acc338476fe0825769b41fb32b423c72John WiegleyTreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) { 606428bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley if(isa<SEHFinallyStmt>(Handler)) 606528bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler)); 606628bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley else 606728bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler)); 606828bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley} 606928bbe4b8acc338476fe0825769b41fb32b423c72John Wiegley 607043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===// 6071b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Expression transformation 6072577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 60731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 607460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6075454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { 60763fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 60771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 60781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 608060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6081454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { 608240d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc; 608340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (E->getQualifierLoc()) { 608440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc 608540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 608640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!QualifierLoc) 6087f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6088a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 6089dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 6090dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *ND 60917c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), 60927c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getDecl())); 6093b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!ND) 6094f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 60951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6096ec8045d3f0375302eadaa63deb373bacaf25a569John McCall DeclarationNameInfo NameInfo = E->getNameInfo(); 6097ec8045d3f0375302eadaa63deb373bacaf25a569John McCall if (NameInfo.getName()) { 6098ec8045d3f0375302eadaa63deb373bacaf25a569John McCall NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 6099ec8045d3f0375302eadaa63deb373bacaf25a569John McCall if (!NameInfo.getName()) 6100f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6101ec8045d3f0375302eadaa63deb373bacaf25a569John McCall } 61022577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 61032577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!getDerived().AlwaysRebuild() && 610440d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc == E->getQualifierLoc() && 6105a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor ND == E->getDecl() && 61062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getDecl()->getDeclName() && 6107096832c5ed5b9106fa177ebc148489760c3bc496John McCall !E->hasExplicitTemplateArgs()) { 61081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6109dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // Mark it referenced in the new context regardless. 6110dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // FIXME: this is a bit instantiation-specific. 61115f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkDeclRefReferenced(E); 6112a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 61133fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6114a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 6115dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 6116dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; 6117096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (E->hasExplicitTemplateArgs()) { 6118dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TemplateArgs = &TransArgs; 6119dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TransArgs.setLAngleLoc(E->getLAngleLoc()); 6120dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TransArgs.setRAngleLoc(E->getRAngleLoc()); 6121fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 6122fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 6123fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 6124fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 6125dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall } 6126dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 612740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo, 612840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor TemplateArgs); 6129577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 61301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6131b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 613260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6133454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { 61343fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6135577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 61361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6137b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 613860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6139454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { 61403fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6141b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 61421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6143b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 614460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6145454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { 61463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6147b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 61481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 61491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 615060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6151454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { 61523fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6153b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 61541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6155b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 615660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6157454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { 61583fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6159b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 61601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6161b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 616260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 61639fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard SmithTreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) { 61649fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith return SemaRef.MaybeBindToTemporary(E); 61659fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith} 61669fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smith 61679fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard Smithtemplate<typename Derived> 61689fcce65e7e1307b5b8da9be13e4092d6bb94dc1dRichard SmithExprResult 6169f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneTreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) { 6170f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult ControllingExpr = 6171f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne getDerived().TransformExpr(E->getControllingExpr()); 6172f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (ControllingExpr.isInvalid()) 6173f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ExprError(); 6174f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 6175686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<Expr *, 4> AssocExprs; 6176686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<TypeSourceInfo *, 4> AssocTypes; 6177f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne for (unsigned i = 0; i != E->getNumAssocs(); ++i) { 6178f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i); 6179f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (TS) { 6180f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne TypeSourceInfo *AssocType = getDerived().TransformType(TS); 6181f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (!AssocType) 6182f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ExprError(); 6183f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes.push_back(AssocType); 6184f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } else { 6185f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes.push_back(0); 6186f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 6187f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 6188f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i)); 6189f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne if (AssocExpr.isInvalid()) 6190f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return ExprError(); 6191f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs.push_back(AssocExpr.release()); 6192f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne } 6193f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 6194f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(), 6195f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E->getDefaultLoc(), 6196f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E->getRParenLoc(), 6197f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne ControllingExpr.release(), 6198f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocTypes.data(), 6199f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne AssocExprs.data(), 6200f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne E->getNumAssocs()); 6201f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne} 6202f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbourne 6203f111d935722ed488144600cea5ed03a6b5069e8fPeter Collingbournetemplate<typename Derived> 6204f111d935722ed488144600cea5ed03a6b5069e8fPeter CollingbourneExprResult 6205454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { 620660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 6207b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6208f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6210b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) 62113fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 62121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), 6214b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParen()); 6215b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6216b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 62171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 621860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6219454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { 622060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 6221b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6222f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6224b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) 62253fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 62261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6227b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), 6228b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOpcode(), 62299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get()); 6230b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 62311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6232b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 623360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 62348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorTreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { 62358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Transform the type. 62368ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); 62378ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (!Type) 6238f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6239c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 62408ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Transform all of the components into components similar to what the 62418ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // parser uses. 6242c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // FIXME: It would be slightly more efficient in the non-dependent case to 6243c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // just map FieldDecls, rather than requiring the rebuilder to look for 6244c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // the fields again. However, __builtin_offsetof is rare enough in 62458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // template code that we don't care. 62468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor bool ExprChanged = false; 6247f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall typedef Sema::OffsetOfComponent Component; 62488ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor typedef OffsetOfExpr::OffsetOfNode Node; 6249686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<Component, 4> Components; 62508ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { 62518ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor const Node &ON = E->getComponent(I); 62528ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Component Comp; 625372be24f39c162448e53dd73cf57cc6357114361eDouglas Gregor Comp.isBrackets = true; 625406dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara Comp.LocStart = ON.getSourceRange().getBegin(); 625506dec892b5300b43263d25c5476b506c9d6cfbadAbramo Bagnara Comp.LocEnd = ON.getSourceRange().getEnd(); 62568ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor switch (ON.getKind()) { 62578ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Array: { 62588ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); 625960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Index = getDerived().TransformExpr(FromIndex); 62608ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (Index.isInvalid()) 6261f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6262c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 62638ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor ExprChanged = ExprChanged || Index.get() != FromIndex; 62648ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.isBrackets = true; 62659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Comp.U.E = Index.get(); 62668ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor break; 62678ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 6268c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 62698ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Field: 62708ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Identifier: 62718ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.isBrackets = false; 62728ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.U.IdentInfo = ON.getFieldName(); 627329d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor if (!Comp.U.IdentInfo) 627429d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor continue; 6275c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 62768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor break; 6277c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6278cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor case Node::Base: 6279cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor // Will be recomputed during the rebuild. 6280cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor continue; 62818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 6282c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 62838ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Components.push_back(Comp); 62848ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 6285c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 62868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // If nothing changed, retain the existing expression. 62878ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (!getDerived().AlwaysRebuild() && 62888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Type == E->getTypeSourceInfo() && 62898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor !ExprChanged) 62903fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6291c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 62928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Build a new offsetof expression. 62938ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, 62948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Components.data(), Components.size(), 62958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor E->getRParenLoc()); 62967cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall} 62977cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall 62987cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCalltemplate<typename Derived> 62997cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallExprResult 63007cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallTreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { 63017cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall assert(getDerived().AlreadyTransformed(E->getType()) && 63027cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall "opaque value expression requires transformation"); 63037cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall return SemaRef.Owned(E); 63048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 63058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 63068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregortemplate<typename Derived> 630760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 63084b9c2d235fb9449e249d74f48ecfec601650de93John McCallTreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) { 630901e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // Rebuild the syntactic form. The original syntactic form has 631001e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // opaque-value expressions in it, so strip those away and rebuild 631101e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // the result. This is a really awful way of doing this, but the 631201e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // better solution (rebuilding the semantic expressions and 631301e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // rebinding OVEs as necessary) doesn't work; we'd need 631401e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall // TreeTransform to not strip away implicit conversions. 631501e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E); 631601e19be69a37bc4ab7746c454cfaa6aec7bb7c6aJohn McCall ExprResult result = getDerived().TransformExpr(newSyntacticForm); 63174b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (result.isInvalid()) return ExprError(); 63184b9c2d235fb9449e249d74f48ecfec601650de93John McCall 63194b9c2d235fb9449e249d74f48ecfec601650de93John McCall // If that gives us a pseudo-object result back, the pseudo-object 63204b9c2d235fb9449e249d74f48ecfec601650de93John McCall // expression must have been an lvalue-to-rvalue conversion which we 63214b9c2d235fb9449e249d74f48ecfec601650de93John McCall // should reapply. 63224b9c2d235fb9449e249d74f48ecfec601650de93John McCall if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject)) 63234b9c2d235fb9449e249d74f48ecfec601650de93John McCall result = SemaRef.checkPseudoObjectRValue(result.take()); 63244b9c2d235fb9449e249d74f48ecfec601650de93John McCall 63254b9c2d235fb9449e249d74f48ecfec601650de93John McCall return result; 63264b9c2d235fb9449e249d74f48ecfec601650de93John McCall} 63274b9c2d235fb9449e249d74f48ecfec601650de93John McCall 63284b9c2d235fb9449e249d74f48ecfec601650de93John McCalltemplate<typename Derived> 63294b9c2d235fb9449e249d74f48ecfec601650de93John McCallExprResult 6330f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter CollingbourneTreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr( 6331f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne UnaryExprOrTypeTraitExpr *E) { 6332b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->isArgumentType()) { 6333a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *OldT = E->getArgumentTypeInfo(); 63345557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor 6335a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *NewT = getDerived().TransformType(OldT); 63365ab75172051a6d2ea71a80a79e81c65519fd3462John McCall if (!NewT) 6337f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63395ab75172051a6d2ea71a80a79e81c65519fd3462John McCall if (!getDerived().AlwaysRebuild() && OldT == NewT) 63403fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 63411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6342f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(), 6343f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getKind(), 6344f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getSourceRange()); 6345b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 63461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 634772b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman // C++0x [expr.sizeof]p1: 634872b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman // The operand is either an expression, which is an unevaluated operand 634972b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman // [...] 635072b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 63511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 635272b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman ExprResult SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); 635372b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman if (SubExpr.isInvalid()) 635472b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman return ExprError(); 63551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 635672b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) 635772b8b1ef9f7fb4f66fefcbd8d82fce2301b851d4Eli Friedman return SemaRef.Owned(E); 63581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6359f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(), 6360f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getOperatorLoc(), 6361f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getKind(), 6362f4e3cfbe8abd124be6341ef5d714819b4fbd9082Peter Collingbourne E->getSourceRange()); 6363b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 63641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6365b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 636660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6367454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { 636860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6369b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6370f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 637260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6373b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6374f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6377b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6378b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6379b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 63803fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 63811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildArraySubscriptExpr(LHS.get(), 6383b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLHS()->getLocStart(), 63849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get(), 6385b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRBracketLoc()); 6386b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 63871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 638960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6390454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCallExpr(CallExpr *E) { 6391b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the callee. 639260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 6393b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Callee.isInvalid()) 6394f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6395b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6396b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform arguments. 6397b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgChanged = false; 6398ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 6399aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 6400aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgChanged)) 6401aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6402aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 6403b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6404b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Callee.get() == E->getCallee() && 6405b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgChanged) 640692be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E);; 64071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6408b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Wrong source location information for the '('. 64091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeLParenLoc 6410b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = ((Expr *)Callee.get())->getSourceRange().getBegin(); 64119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, 6412b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Args), 6413b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6414b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 64161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 641760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6418454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { 641960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 6420b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Base.isInvalid()) 6421f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 642340d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor NestedNameSpecifierLoc QualifierLoc; 642483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor if (E->hasQualifier()) { 642540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc 642640d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 642740d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor 642840d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor if (!QualifierLoc) 6429f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 643083f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 6431e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); 64321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6433f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *Member 64347c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), 64357c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getMemberDecl())); 6436b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Member) 6437f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 64396bb8017bb9e828d118e15e59d71c66bba323c364John McCall NamedDecl *FoundDecl = E->getFoundDecl(); 64406bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (FoundDecl == E->getMemberDecl()) { 64416bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl = Member; 64426bb8017bb9e828d118e15e59d71c66bba323c364John McCall } else { 64436bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl = cast_or_null<NamedDecl>( 64446bb8017bb9e828d118e15e59d71c66bba323c364John McCall getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); 64456bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!FoundDecl) 6446f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64476bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 64486bb8017bb9e828d118e15e59d71c66bba323c364John McCall 6449b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6450b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Base.get() == E->getBase() && 645140d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc == E->getQualifierLoc() && 64528a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor Member == E->getMemberDecl() && 64536bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl == E->getFoundDecl() && 6454096832c5ed5b9106fa177ebc148489760c3bc496John McCall !E->hasExplicitTemplateArgs()) { 6455c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 64561f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson // Mark it referenced in the new context regardless. 64571f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson // FIXME: this is a bit instantiation-specific. 64585f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkMemberReferenced(E); 64595f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman 64603fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 64611f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson } 6462b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6463d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs; 6464096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (E->hasExplicitTemplateArgs()) { 6465d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TransArgs.setLAngleLoc(E->getLAngleLoc()); 6466d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TransArgs.setRAngleLoc(E->getRAngleLoc()); 6467fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 6468fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 6469fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 6470fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 64718a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor } 6472c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6473b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Bogus source location for the operator 6474b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeOperatorLoc 6475b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); 6476b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6477c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // FIXME: to do this check properly, we will need to preserve the 6478c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // first-qualifier-in-scope here, just in case we had a dependent 6479c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // base (and therefore couldn't do the check) and a 6480c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // nested-name-qualifier (and therefore could do the lookup). 6481c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall NamedDecl *FirstQualifierInScope = 0; 6482c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 64839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, 6484b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrow(), 648540d96a69c0e1e8c10f92d450c305a7aae696ca9cDouglas Gregor QualifierLoc, 6486e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateKWLoc, 64872577743c5650c646fb705df01403707e94f2df04Abramo Bagnara E->getMemberNameInfo(), 64888a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor Member, 64896bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl, 6490096832c5ed5b9106fa177ebc148489760c3bc496John McCall (E->hasExplicitTemplateArgs() 6491d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall ? &TransArgs : 0), 6492c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall FirstQualifierInScope); 6493b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 64941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6495b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 649660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6497454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { 649860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6499b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6500f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 650260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6503b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6504f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6506b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6507b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6508b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 65093fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 65101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6511b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), 65129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), RHS.get()); 6513b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6514b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 65151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 651660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6517b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCompoundAssignOperator( 6518454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CompoundAssignOperator *E) { 6519454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformBinaryOperator(E); 6520b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 65211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6522b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 652356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallExprResult TreeTransform<Derived>:: 652456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCallTransformBinaryConditionalOperator(BinaryConditionalOperator *e) { 652556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // Just rebuild the common and RHS expressions and see whether we 652656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall // get any changes. 652756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 652856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprResult commonExpr = getDerived().TransformExpr(e->getCommon()); 652956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (commonExpr.isInvalid()) 653056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return ExprError(); 653156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 653256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr()); 653356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (rhs.isInvalid()) 653456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return ExprError(); 653556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 653656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall if (!getDerived().AlwaysRebuild() && 653756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall commonExpr.get() == e->getCommon() && 653856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs.get() == e->getFalseExpr()) 653956ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return SemaRef.Owned(e); 654056ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 654156ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall return getDerived().RebuildConditionalOperator(commonExpr.take(), 654256ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall e->getQuestionLoc(), 654356ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 0, 654456ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall e->getColonLoc(), 654556ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall rhs.get()); 654656ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall} 654756ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCall 654856ca35d396d8692c384c785f9aeebcf22563fe1eJohn McCalltemplate<typename Derived> 654960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6550454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { 655160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(E->getCond()); 6552b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Cond.isInvalid()) 6553f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 655560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6556b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6557f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 655960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6560b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6561f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6563b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6564b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Cond.get() == E->getCond() && 6565b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6566b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 65673fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 65681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 65699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildConditionalOperator(Cond.get(), 657047e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor E->getQuestionLoc(), 65719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), 657247e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor E->getColonLoc(), 65739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get()); 6574b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 65751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 65761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 657760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6578454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { 6579a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor // Implicit casts are eliminated during transformation, since they 6580a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor // will be recomputed by semantic analysis after transformation. 65816eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return getDerived().TransformExpr(E->getSubExprAsWritten()); 6582b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 65831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6584b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 658560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6586454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { 6587ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 6588ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 6589ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 6590ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor 659160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 65926eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 6593b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6594f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6596b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6597ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 6598b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 65993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 66001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 66019d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), 6602ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type, 6603b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc(), 66049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get()); 6605b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6607b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 660860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6609454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { 661042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *OldT = E->getTypeSourceInfo(); 661142f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *NewT = getDerived().TransformType(OldT); 661242f56b50062cd3b3c6b23fdb9053578ae9145664John McCall if (!NewT) 6613f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 661560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Init = getDerived().TransformExpr(E->getInitializer()); 6616b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Init.isInvalid()) 6617f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6619b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 662042f56b50062cd3b3c6b23fdb9053578ae9145664John McCall OldT == NewT && 6621b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Init.get() == E->getInitializer()) 662292be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 6623b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 66241d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // Note: the expression type doesn't necessarily match the 66251d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // type-as-written, but that's okay, because it should always be 66261d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // derivable from the initializer. 66271d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 662842f56b50062cd3b3c6b23fdb9053578ae9145664John McCall return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, 6629b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getInitializer()->getLocEnd(), 66309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init.get()); 6631b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6633b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 663460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6635454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { 663660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 6637b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Base.isInvalid()) 6638f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6640b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6641b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Base.get() == E->getBase()) 66423fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 66431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6644b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Bad source location 66451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeOperatorLoc 6646b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); 66479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, 6648b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getAccessorLoc(), 6649b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getAccessor()); 6650b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6652b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 665360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6654454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { 6655b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool InitChanged = false; 66561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6657ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*, 4> Inits(SemaRef); 6658aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, 6659aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Inits, &InitChanged)) 6660aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6661aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 6662b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && !InitChanged) 66633fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 66641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6665b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), 6666e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor E->getRBraceLoc(), E->getType()); 6667b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 66681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6669b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 667060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6671454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { 6672b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Designation Desig; 66731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 667443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transform the initializer value 667560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Init = getDerived().TransformExpr(E->getInit()); 6676b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Init.isInvalid()) 6677f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 667943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transform the designators. 6680ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef); 6681b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ExprChanged = false; 6682b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), 6683b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor DEnd = E->designators_end(); 6684b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D != DEnd; ++D) { 6685b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (D->isFieldDesignator()) { 6686b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Desig.AddDesignator(Designator::getField(D->getFieldName(), 6687b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getDotLoc(), 6688b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getFieldLoc())); 6689b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor continue; 6690b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 66911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6692b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (D->isArrayDesignator()) { 669360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); 6694b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Index.isInvalid()) 6695f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 66961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 66971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Desig.AddDesignator(Designator::getArray(Index.get(), 6698b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getLBracketLoc())); 66991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6700b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); 6701b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(Index.release()); 6702b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor continue; 6703b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 67041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6705b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor assert(D->isArrayRangeDesignator() && "New kind of designator?"); 670660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Start 6707b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = getDerived().TransformExpr(E->getArrayRangeStart(*D)); 6708b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Start.isInvalid()) 6709f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 67101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 671160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); 6712b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (End.isInvalid()) 6713f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 67141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 67151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Desig.AddDesignator(Designator::getArrayRange(Start.get(), 6716b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor End.get(), 6717b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getLBracketLoc(), 6718b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getEllipsisLoc())); 67191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6720b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || 6721b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor End.get() != E->getArrayRangeEnd(*D); 67221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6723b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(Start.release()); 6724b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(End.release()); 6725b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 67261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6727b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6728b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Init.get() == E->getInit() && 6729b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ExprChanged) 67303fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 67311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6732b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), 6733b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getEqualOrColonLoc(), 67349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall E->usesGNUSyntax(), Init.get()); 6735b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 67361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6737b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 673860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6739b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformImplicitValueInitExpr( 6740454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall ImplicitValueInitExpr *E) { 67415557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); 6742c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 67435557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor // FIXME: Will we ever have proper type location here? Will we actually 67445557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor // need to transform the type? 6745b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor QualType T = getDerived().TransformType(E->getType()); 6746b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (T.isNull()) 6747f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 67481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6749b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6750b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T == E->getType()) 67513fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 67521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6753b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildImplicitValueInitExpr(T); 6754b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 67551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6756b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 675760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6758454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { 67599bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); 67609bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor if (!TInfo) 6761f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 67621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 676360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 6764b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6765f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 67661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6767b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 67682cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TInfo == E->getWrittenTypeInfo() && 6769b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 67703fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 67711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 67729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), 67732cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TInfo, E->getRParenLoc()); 6774b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6775b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6776b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 677760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6778454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { 6779b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 6780ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*, 4> Inits(SemaRef); 6781aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, 6782aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 6783aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6784aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 6785b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildParenListExpr(E->getLParenLoc(), 6786b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Inits), 6787b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6788b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 67891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6790b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform an address-of-label expression. 6791b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 6792b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// By default, the transformation of an address-of-label expression always 6793b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// rebuilds the expression, so that the label identifier can be resolved to 6794b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// the corresponding label statement by semantic analysis. 6795b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 679660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6797454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { 679857ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(), 679957ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner E->getLabel()); 680057ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner if (!LD) 680157ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner return ExprError(); 680257ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner 6803b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), 680457ad37823e198f977cac605dbfbaefb4daf325e9Chris Lattner cast<LabelDecl>(LD)); 6805b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 68071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 680860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6809454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { 68107f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall SemaRef.ActOnStartStmtExpr(); 681160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt 6812b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = getDerived().TransformCompoundStmt(E->getSubStmt(), true); 68137f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall if (SubStmt.isInvalid()) { 68147f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall SemaRef.ActOnStmtExprError(); 6815f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68167f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall } 68171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6818b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 68197f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall SubStmt.get() == E->getSubStmt()) { 68207f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall // Calling this an 'error' is unintuitive, but it does the right thing. 68217f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall SemaRef.ActOnStmtExprError(); 682292be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 68237f39d51d9c8f551fd09c1feee3d8033f5702b2cbJohn McCall } 68241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 68251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildStmtExpr(E->getLParenLoc(), 68269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubStmt.get(), 6827b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6828b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6830b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 683160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6832454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { 683360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(E->getCond()); 6834b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Cond.isInvalid()) 6835f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 683760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 6838b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 6839f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 684160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 6842b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 6843f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 68441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6845b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6846b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Cond.get() == E->getCond() && 6847b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 6848b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 68493fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 68501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6851b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), 68529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond.get(), LHS.get(), RHS.get(), 6853b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6854b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 68551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6856b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 685760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6858454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { 68593fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6860b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6861b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6862b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 686360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6864454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { 6865668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor switch (E->getOperator()) { 6866668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_New: 6867668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Delete: 6868668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Array_New: 6869668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Array_Delete: 6870668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); 6871c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6872668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Call: { 6873668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // This is a call to an object's operator(). 6874668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); 6875668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6876668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Transform the object itself. 687760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Object = getDerived().TransformExpr(E->getArg(0)); 6878668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor if (Object.isInvalid()) 6879f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6880668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6881668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // FIXME: Poor location information 6882668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor SourceLocation FakeLParenLoc 6883668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor = SemaRef.PP.getLocForEndOfToken( 6884668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor static_cast<Expr *>(Object.get())->getLocEnd()); 6885668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6886668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Transform the call arguments. 6887ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 6888aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, 6889aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args)) 6890aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6891668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 68929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, 6893668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor move_arg(Args), 6894668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor E->getLocEnd()); 6895668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor } 6896668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6897668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ 6898668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_##Name: 6899668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) 6900668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#include "clang/Basic/OperatorKinds.def" 6901668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Subscript: 6902668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Handled below. 6903668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor break; 6904668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6905668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Conditional: 6906668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("conditional operator is not actually overloadable"); 6907668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 6908668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_None: 6909668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case NUM_OVERLOADED_OPERATORS: 6910668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("not an overloaded operator?"); 6911668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor } 6912668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 691360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 6914b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Callee.isInvalid()) 6915f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 69161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 691760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult First = getDerived().TransformExpr(E->getArg(0)); 6918b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (First.isInvalid()) 6919f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6920b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 692160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Second; 6922b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->getNumArgs() == 2) { 6923b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Second = getDerived().TransformExpr(E->getArg(1)); 6924b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Second.isInvalid()) 6925f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6926b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 69271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6928b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6929b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Callee.get() == E->getCallee() && 6930b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor First.get() == E->getArg(0) && 69311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) 693292be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 69331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6934b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), 6935b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOperatorLoc(), 69369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Callee.get(), 69379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall First.get(), 69389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Second.get()); 6939b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 69401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6941b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 694260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6943454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { 6944454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCallExpr(E); 6945b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 69461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6947b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 6948e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneExprResult 6949e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter CollingbourneTreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) { 6950e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // Transform the callee. 6951e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 6952e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (Callee.isInvalid()) 6953e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return ExprError(); 6954e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6955e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // Transform exec config. 6956e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ExprResult EC = getDerived().TransformCallExpr(E->getConfig()); 6957e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (EC.isInvalid()) 6958e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return ExprError(); 6959e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6960e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // Transform arguments. 6961e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne bool ArgChanged = false; 6962e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne ASTOwningVector<Expr*> Args(SemaRef); 6963e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 6964e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne &ArgChanged)) 6965e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return ExprError(); 6966e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6967e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne if (!getDerived().AlwaysRebuild() && 6968e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne Callee.get() == E->getCallee() && 6969e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne !ArgChanged) 697092be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 6971e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6972e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne // FIXME: Wrong source location information for the '('. 6973e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne SourceLocation FakeLParenLoc 6974e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne = ((Expr *)Callee.get())->getSourceRange().getBegin(); 6975e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, 6976e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne move_arg(Args), 6977e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne E->getRParenLoc(), EC.get()); 6978e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne} 6979e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbourne 6980e08ce650a2b02410eddd1f60a4aa6b3d4be71e73Peter Collingbournetemplate<typename Derived> 698160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6982454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { 6983ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 6984ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 6985ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 6986ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor 698760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 69886eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 6989b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 6990f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 69911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6992b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6993ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 6994b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 69953fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 69961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6997b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Poor source location information here. 69981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeLAngleLoc 6999b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); 7000b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); 7001b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeRParenLoc 7002b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken( 7003b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getSubExpr()->getSourceRange().getEnd()); 7004b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), 70051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump E->getStmtClass(), 7006b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeLAngleLoc, 7007ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type, 7008b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRAngleLoc, 7009b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRAngleLoc, 70109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 7011b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRParenLoc); 7012b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 70131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7014b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 701560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7016454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { 7017454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 7018b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 70191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7020b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 702160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7022454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { 7023454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 7024b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 70251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7026b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 702760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7028b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXReinterpretCastExpr( 7029454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXReinterpretCastExpr *E) { 7030454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 7031b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 70321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7033b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 703460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7035454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { 7036454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 7037b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 70381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7039b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 704060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7041b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXFunctionalCastExpr( 7042454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXFunctionalCastExpr *E) { 7043ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 7044ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 7045ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 70461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 704760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 70486eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 7049b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 7050f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7052b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7053ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 7054b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 70553fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 70561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7057ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return getDerived().RebuildCXXFunctionalCastExpr(Type, 7058b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getSubExpr()->getLocStart(), 70599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 7060b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 7061b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 70621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7063b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 706460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7065454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { 7066b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->isTypeOperand()) { 706757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TypeSourceInfo *TInfo 706857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor = getDerived().TransformType(E->getTypeOperandSourceInfo()); 706957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor if (!TInfo) 7070f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7072b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 707357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TInfo == E->getTypeOperandSourceInfo()) 70743fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 70751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 707657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return getDerived().RebuildCXXTypeidExpr(E->getType(), 707757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor E->getLocStart(), 707857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TInfo, 7079b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 7080b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 70811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7082ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman // We don't know whether the subexpression is potentially evaluated until 7083ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman // after we perform semantic analysis. We speculatively assume it is 7084ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman // unevaluated; it will get fixed later if the subexpression is in fact 7085b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // potentially evaluated. 7086ef331b783bb96a0f0e34afdb7ef46677dc4764cbEli Friedman EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 70871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 708860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); 7089b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 7090f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 70911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7092b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7093b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getExprOperand()) 70943fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 70951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 709657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return getDerived().RebuildCXXTypeidExpr(E->getType(), 709757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor E->getLocStart(), 70989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 7099b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 7100b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7101b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7102b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 710360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 710401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetTreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { 710501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (E->isTypeOperand()) { 710601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TypeSourceInfo *TInfo 710701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet = getDerived().TransformType(E->getTypeOperandSourceInfo()); 710801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!TInfo) 710901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return ExprError(); 711001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 711101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!getDerived().AlwaysRebuild() && 711201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TInfo == E->getTypeOperandSourceInfo()) 71133fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 711401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 71153c52a218f41f091a17582d037663594d2b8dc708Douglas Gregor return getDerived().RebuildCXXUuidofExpr(E->getType(), 711601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocStart(), 711701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TInfo, 711801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocEnd()); 711901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 712001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 712101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 712201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 712301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); 712401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (SubExpr.isInvalid()) 712501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return ExprError(); 712601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 712701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!getDerived().AlwaysRebuild() && 712801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SubExpr.get() == E->getExprOperand()) 71293fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 713001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 713101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getDerived().RebuildCXXUuidofExpr(E->getType(), 713201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocStart(), 713301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SubExpr.get(), 713401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocEnd()); 713501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet} 713601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 713701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichettemplate<typename Derived> 713801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetExprResult 7139454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { 71403fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7141b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 71421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7143b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 714460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7145b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( 7146454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXNullPtrLiteralExpr *E) { 71473fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7148b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 71491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7150b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 715160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7152454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { 7153ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor DeclContext *DC = getSema().getFunctionLevelDeclContext(); 71547a614d8380297fcd2bc23986241905d97222948cRichard Smith QualType T; 71557a614d8380297fcd2bc23986241905d97222948cRichard Smith if (CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC)) 71567a614d8380297fcd2bc23986241905d97222948cRichard Smith T = MD->getThisType(getSema().Context); 71577a614d8380297fcd2bc23986241905d97222948cRichard Smith else 71587a614d8380297fcd2bc23986241905d97222948cRichard Smith T = getSema().Context.getPointerType( 71597a614d8380297fcd2bc23986241905d97222948cRichard Smith getSema().Context.getRecordType(cast<CXXRecordDecl>(DC))); 71601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7161ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor if (!getDerived().AlwaysRebuild() && T == E->getType()) { 7162ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor // Make sure that we capture 'this'. 7163ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor getSema().CheckCXXThisCapture(E->getLocStart()); 71643fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7165ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor } 7166ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor 7167828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); 7168b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 71691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7170b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 717160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7172454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { 717360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 7174b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 7175f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 71761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7177b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7178b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 71793fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7180b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7181bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(), 7182bca01b46850f867b2f4137f25c882022b58f8471Douglas Gregor E->isThrownVariableInScope()); 7183b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 71841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7185b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 718660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7187454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { 71881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParmVarDecl *Param 71897c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), 71907c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getParam())); 7191b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Param) 7192f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 71931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 719453cb6f82c41397917b14fb8cdcb32e6c9bd07655Chandler Carruth if (!getDerived().AlwaysRebuild() && 7195b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Param == E->getParam()) 71963fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 71971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7198036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); 7199b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 72001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7201b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 720260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7203ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas GregorTreeTransform<Derived>::TransformCXXScalarValueInitExpr( 7204ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXScalarValueInitExpr *E) { 7205ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 7206ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 7207f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7208ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor 7209b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7210ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo()) 72113fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 72121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7213ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXScalarValueInitExpr(T, 7214ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /*FIXME:*/T->getTypeLoc().getEndLoc(), 7215ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor E->getRParenLoc()); 7216b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 72171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7218b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 721960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7220454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { 7221b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the type that we're allocating 72221bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *AllocTypeInfo 72231bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); 72241bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor if (!AllocTypeInfo) 7225f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 72261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7227b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the size of the array we're allocating (if any). 722860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); 7229b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (ArraySize.isInvalid()) 7230f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 72311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7232b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the placement arguments (if any). 7233b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 7234ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> PlacementArgs(SemaRef); 7235aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getPlacementArgs(), 7236aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor E->getNumPlacementArgs(), true, 7237aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor PlacementArgs, &ArgumentChanged)) 72382aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return ExprError(); 72392aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl 72402aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl // Transform the initializer (if any). 72412aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl Expr *OldInit = E->getInitializer(); 72422aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl ExprResult NewInit; 72432aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl if (OldInit) 72442aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl NewInit = getDerived().TransformExpr(OldInit); 72452aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl if (NewInit.isInvalid()) 72462aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl return ExprError(); 72471af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor 72482aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl // Transform new operator and delete operator. 72491af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorNew = 0; 72501af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorNew()) { 72511af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorNew = cast_or_null<FunctionDecl>( 72527c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 72537c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorNew())); 72541af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorNew) 7255f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 72561af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 72571af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor 72581af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorDelete = 0; 72591af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorDelete()) { 72601af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete = cast_or_null<FunctionDecl>( 72617c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 72627c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorDelete())); 72631af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorDelete) 7264f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 72651af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 7266c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7267b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 72681bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocTypeInfo == E->getAllocatedTypeSourceInfo() && 7269b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArraySize.get() == E->getArraySize() && 72702aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl NewInit.get() == OldInit && 72711af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorNew == E->getOperatorNew() && 72721af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete == E->getOperatorDelete() && 72731af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor !ArgumentChanged) { 72741af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark any declarations we need as referenced. 72751af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: instantiation-specific. 72761af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorNew) 72775f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew); 72781af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorDelete) 72795f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); 72802ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor 72812aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl if (E->isArray() && !E->getAllocatedType()->isDependentType()) { 72822ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor QualType ElementType 72832ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor = SemaRef.Context.getBaseElementType(E->getAllocatedType()); 72842ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor if (const RecordType *RecordT = ElementType->getAs<RecordType>()) { 72852ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl()); 72862ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) { 72875f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor); 72882ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor } 72892ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor } 72902ad63cf7146268a336b5a931f626adaa8a5150f0Douglas Gregor } 72912aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl 72923fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 72931af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 72941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 72951bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor QualType AllocType = AllocTypeInfo->getType(); 72965b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (!ArraySize.get()) { 72975b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // If no array size was specified, but the new expression was 72985b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // instantiated with an array type (e.g., "new T" where T is 72995b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // instantiated with "int[4]"), extract the outer bound from the 73005b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // array type as our array size. We do this with constant and 73015b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // dependently-sized array types. 73025b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); 73035b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (!ArrayT) { 73045b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // Do nothing 73055b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } else if (const ConstantArrayType *ConsArrayT 73065b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor = dyn_cast<ConstantArrayType>(ArrayT)) { 7307c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ArraySize 73089996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, 73099996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis ConsArrayT->getSize(), 73109996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis SemaRef.Context.getSizeType(), 73119996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /*FIXME:*/E->getLocStart())); 73125b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor AllocType = ConsArrayT->getElementType(); 73135b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } else if (const DependentSizedArrayType *DepArrayT 73145b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor = dyn_cast<DependentSizedArrayType>(ArrayT)) { 73155b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (DepArrayT->getSizeExpr()) { 73163fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); 73175b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor AllocType = DepArrayT->getElementType(); 73185b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 73195b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 73205b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 73212aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl 7322b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXNewExpr(E->getLocStart(), 7323b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isGlobalNew(), 7324b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLocStart(), 7325b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(PlacementArgs), 7326b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLocStart(), 73274bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor E->getTypeIdParens(), 7328b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor AllocType, 73291bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocTypeInfo, 73309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ArraySize.get(), 73312aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl E->getDirectInitRange(), 73322aed8b88613863f3c439cdfb205bdf8b608fb205Sebastian Redl NewInit.take()); 7333b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 73341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7335b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 733660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7337454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { 733860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Operand = getDerived().TransformExpr(E->getArgument()); 7339b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Operand.isInvalid()) 7340f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 73411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 73421af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Transform the delete operator, if known. 73431af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorDelete = 0; 73441af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorDelete()) { 73451af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete = cast_or_null<FunctionDecl>( 73467c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 73477c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorDelete())); 73481af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorDelete) 7349f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 73501af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 7351c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7352b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 73531af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor Operand.get() == E->getArgument() && 73541af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete == E->getOperatorDelete()) { 73551af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark any declarations we need as referenced. 73561af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: instantiation-specific. 73571af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorDelete) 73585f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete); 73595833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor 73605833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor if (!E->getArgument()->isTypeDependent()) { 73615833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor QualType Destroyed = SemaRef.Context.getBaseElementType( 73625833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor E->getDestroyedType()); 73635833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { 73645833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); 73655f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkFunctionReferenced(E->getLocStart(), 73665f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.LookupDestructor(Record)); 73675833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor } 73685833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor } 73695833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor 73703fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 73711af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 73721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7373b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), 7374b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isGlobalDelete(), 7375b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrayForm(), 73769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Operand.get()); 7377b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 73781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7379b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 738060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7381a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas GregorTreeTransform<Derived>::TransformCXXPseudoDestructorExpr( 7382454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXPseudoDestructorExpr *E) { 738360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 7384a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor if (Base.isInvalid()) 7385f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 73861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7387b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectTypePtr; 7388a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor bool MayBePseudoDestructor = false; 73899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), 7390a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getOperatorLoc(), 7391a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->isArrow()? tok::arrow : tok::period, 7392a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor ObjectTypePtr, 7393a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor MayBePseudoDestructor); 7394a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (Base.isInvalid()) 7395f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7396c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7397b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall QualType ObjectType = ObjectTypePtr.get(); 7398f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc(); 7399f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor if (QualifierLoc) { 7400f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor QualifierLoc 7401f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType); 7402f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor if (!QualifierLoc) 740343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return ExprError(); 740443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } 7405f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor CXXScopeSpec SS; 7406f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SS.Adopt(QualifierLoc); 74071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7408a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed; 7409a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (E->getDestroyedTypeInfo()) { 7410a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor TypeSourceInfo *DestroyedTypeInfo 741143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), 7412b71d821d64af88749fc9860fd43a5164d8d819c8Douglas Gregor ObjectType, 0, SS); 7413a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (!DestroyedTypeInfo) 7414f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7415a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed = DestroyedTypeInfo; 74166b18e740495b67b439fa366367242110365cc4d9Douglas Gregor } else if (!ObjectType.isNull() && ObjectType->isDependentType()) { 7417a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // We aren't likely to be able to resolve the identifier down to a type 7418a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // now anyway, so just retain the identifier. 7419a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), 7420a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc()); 7421a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } else { 7422a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // Look for a destructor known with the given name. 7423b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), 7424a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor *E->getDestroyedTypeIdentifier(), 7425a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc(), 7426a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /*Scope=*/0, 7427a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor SS, ObjectTypePtr, 7428a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor false); 7429a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (!T) 7430f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7431c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7432a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed 7433a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), 7434a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc()); 7435a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 743626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor 743726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor TypeSourceInfo *ScopeTypeInfo = 0; 743826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor if (E->getScopeTypeInfo()) { 743943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo()); 744026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor if (!ScopeTypeInfo) 7441f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7442a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor } 7443c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 74449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), 7445a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor E->getOperatorLoc(), 7446a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor E->isArrow(), 7447f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor SS, 744826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor ScopeTypeInfo, 744926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor E->getColonColonLoc(), 7450fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor E->getTildeLoc(), 7451a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed); 7452a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor} 74531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7454a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregortemplate<typename Derived> 745560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7456ba13543329afac4a0d01304ec2ec4924d99306a6John McCallTreeTransform<Derived>::TransformUnresolvedLookupExpr( 7457454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall UnresolvedLookupExpr *Old) { 7458f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), 7459f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall Sema::LookupOrdinaryName); 7460f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7461f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Transform all the decls. 7462f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), 7463f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall E = Old->decls_end(); I != E; ++I) { 74647c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor NamedDecl *InstD = static_cast<NamedDecl*>( 74657c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(Old->getNameLoc(), 74667c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor *I)); 74679f54ad4381370c6b771424b53d219e661d6d6706John McCall if (!InstD) { 74689f54ad4381370c6b771424b53d219e661d6d6706John McCall // Silently ignore these if a UsingShadowDecl instantiated to nothing. 74699f54ad4381370c6b771424b53d219e661d6d6706John McCall // This can happen because of dependent hiding. 74709f54ad4381370c6b771424b53d219e661d6d6706John McCall if (isa<UsingShadowDecl>(*I)) 74719f54ad4381370c6b771424b53d219e661d6d6706John McCall continue; 74729f54ad4381370c6b771424b53d219e661d6d6706John McCall else 7473f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 74749f54ad4381370c6b771424b53d219e661d6d6706John McCall } 7475f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7476f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Expand using declarations. 7477f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (isa<UsingDecl>(InstD)) { 7478f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall UsingDecl *UD = cast<UsingDecl>(InstD); 7479f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall for (UsingDecl::shadow_iterator I = UD->shadow_begin(), 7480f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall E = UD->shadow_end(); I != E; ++I) 7481f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.addDecl(*I); 7482f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall continue; 7483f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 7484f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7485f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.addDecl(InstD); 7486f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 7487f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7488f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Resolve a kind, but don't do any further analysis. If it's 7489f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // ambiguous, the callee needs to deal with it. 7490f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.resolveKind(); 7491f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7492f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Rebuild the nested-name qualifier, if present. 7493f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall CXXScopeSpec SS; 74944c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (Old->getQualifierLoc()) { 74954c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc 74964c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); 74974c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (!QualifierLoc) 7498f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7499c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 75004c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor SS.Adopt(QualifierLoc); 7501c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt } 7502c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7503c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor if (Old->getNamingClass()) { 750466c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor CXXRecordDecl *NamingClass 750566c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( 750666c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNameLoc(), 750766c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNamingClass())); 750866c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor if (!NamingClass) 7509f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7510c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 751166c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor R.setNamingClass(NamingClass); 7512f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 7513f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7514e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); 7515e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 75169d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara // If we have neither explicit template arguments, nor the template keyword, 75179d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara // it's a normal declaration name. 75189d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) 7519f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); 7520f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7521f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // If we have template arguments, rebuild them, then rebuild the 7522f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // templateid expression. 7523f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); 7524fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), 7525fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor Old->getNumTemplateArgs(), 7526fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7527fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 7528f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 7529e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R, 75309d9922af13edf3ddf8804a41a98d997324fdd58eAbramo Bagnara Old->requiresADL(), &TransArgs); 7531b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 75321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7533b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 753460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7535454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { 75363d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); 75373d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor if (!T) 7538f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 75391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7540b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 75413d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor T == E->getQueriedTypeSourceInfo()) 75423fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 75431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 75441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildUnaryTypeTrait(E->getTrait(), 7545b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocStart(), 7546b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T, 7547b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 7548b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 75491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7550b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 755160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 75526ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetTreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { 75536ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); 75546ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!LhsT) 75556ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return ExprError(); 75566ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 75576ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); 75586ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!RhsT) 75596ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return ExprError(); 75606ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 75616ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!getDerived().AlwaysRebuild() && 75626ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) 75636ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return SemaRef.Owned(E); 75646ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 75656ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return getDerived().RebuildBinaryTypeTrait(E->getTrait(), 75666ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet E->getLocStart(), 75676ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet LhsT, RhsT, 75686ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet E->getLocEnd()); 75696ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet} 75706ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 75716ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichettemplate<typename Derived> 75726ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetExprResult 75734ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas GregorTreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) { 75744ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor bool ArgChanged = false; 75754ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor llvm::SmallVector<TypeSourceInfo *, 4> Args; 75764ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) { 75774ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeSourceInfo *From = E->getArg(I); 75784ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeLoc FromTL = From->getTypeLoc(); 75794ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (!isa<PackExpansionTypeLoc>(FromTL)) { 75804ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeLocBuilder TLB; 75814ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TLB.reserve(FromTL.getFullDataSize()); 75824ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor QualType To = getDerived().TransformType(TLB, FromTL); 75834ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (To.isNull()) 75844ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return ExprError(); 75854ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 75864ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (To == From->getType()) 75874ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Args.push_back(From); 75884ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor else { 75894ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); 75904ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ArgChanged = true; 75914ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 75924ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor continue; 75934ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 75944ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 75954ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ArgChanged = true; 75964ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 75974ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // We have a pack expansion. Instantiate it. 75984ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(FromTL); 75994ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeLoc PatternTL = ExpansionTL.getPatternLoc(); 76004ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor SmallVector<UnexpandedParameterPack, 2> Unexpanded; 76014ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded); 76024ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76034ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // Determine whether the set of unexpanded parameter packs can and should 76044ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // be expanded. 76054ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor bool Expand = true; 76064ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor bool RetainExpansion = false; 76074ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor llvm::Optional<unsigned> OrigNumExpansions 76084ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor = ExpansionTL.getTypePtr()->getNumExpansions(); 76094ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; 76104ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(), 76114ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor PatternTL.getSourceRange(), 76124ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Unexpanded, 76134ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Expand, RetainExpansion, 76144ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor NumExpansions)) 76154ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return ExprError(); 76164ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76174ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (!Expand) { 76184ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // The transform has determined that we should perform a simple 76194ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // transformation on the pack expansion, producing another pack 76204ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // expansion. 76214ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 76224ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76234ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeLocBuilder TLB; 76244ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TLB.reserve(From->getTypeLoc().getFullDataSize()); 76254ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76264ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor QualType To = getDerived().TransformType(TLB, PatternTL); 76274ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (To.isNull()) 76284ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return ExprError(); 76294ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76304ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor To = getDerived().RebuildPackExpansionType(To, 76314ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor PatternTL.getSourceRange(), 76324ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ExpansionTL.getEllipsisLoc(), 76334ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor NumExpansions); 76344ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (To.isNull()) 76354ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return ExprError(); 76364ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76374ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor PackExpansionTypeLoc ToExpansionTL 76384ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor = TLB.push<PackExpansionTypeLoc>(To); 76394ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); 76404ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); 76414ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor continue; 76424ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 76434ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76444ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // Expand the pack expansion by substituting for each argument in the 76454ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // pack(s). 76464ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 76474ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I); 76484ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeLocBuilder TLB; 76494ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TLB.reserve(PatternTL.getFullDataSize()); 76504ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor QualType To = getDerived().TransformType(TLB, PatternTL); 76514ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (To.isNull()) 76524ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return ExprError(); 76534ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76544ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); 76554ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 76564ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76574ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (!RetainExpansion) 76584ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor continue; 76594ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76604ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // If we're supposed to retain a pack expansion, do so by temporarily 76614ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor // forgetting the partially-substituted parameter pack. 76624ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ForgetPartiallySubstitutedPackRAII Forget(getDerived()); 76634ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76644ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TypeLocBuilder TLB; 76654ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor TLB.reserve(From->getTypeLoc().getFullDataSize()); 76664ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76674ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor QualType To = getDerived().TransformType(TLB, PatternTL); 76684ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (To.isNull()) 76694ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return ExprError(); 76704ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76714ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor To = getDerived().RebuildPackExpansionType(To, 76724ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor PatternTL.getSourceRange(), 76734ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ExpansionTL.getEllipsisLoc(), 76744ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor NumExpansions); 76754ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (To.isNull()) 76764ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return ExprError(); 76774ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76784ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor PackExpansionTypeLoc ToExpansionTL 76794ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor = TLB.push<PackExpansionTypeLoc>(To); 76804ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc()); 76814ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To)); 76824ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor } 76834ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76844ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor if (!getDerived().AlwaysRebuild() && !ArgChanged) 76854ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return SemaRef.Owned(E); 76864ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76874ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor return getDerived().RebuildTypeTrait(E->getTrait(), 76884ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor E->getLocStart(), 76894ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor Args, 76904ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor E->getLocEnd()); 76914ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor} 76924ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregor 76934ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas Gregortemplate<typename Derived> 76944ca8ac2e61c37ddadf37024af86f3e1019af8532Douglas GregorExprResult 769521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John WiegleyTreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) { 769621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); 769721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (!T) 769821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return ExprError(); 769921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 770021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (!getDerived().AlwaysRebuild() && 770121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley T == E->getQueriedTypeSourceInfo()) 770221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return SemaRef.Owned(E); 770321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 770421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley ExprResult SubExpr; 770521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley { 770621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 770721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SubExpr = getDerived().TransformExpr(E->getDimensionExpression()); 770821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (SubExpr.isInvalid()) 770921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return ExprError(); 771021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 771121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression()) 771221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return SemaRef.Owned(E); 771321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley } 771421ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 771521ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley return getDerived().RebuildArrayTypeTrait(E->getTrait(), 771621ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley E->getLocStart(), 771721ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley T, 771821ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley SubExpr.get(), 771921ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley E->getLocEnd()); 772021ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley} 772121ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegley 772221ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John Wiegleytemplate<typename Derived> 772321ff2e516b0e0bc8c1dbf965cb3d44bac3c64330John WiegleyExprResult 7724552622067dc45013d240f73952fece703f5e63bdJohn WiegleyTreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) { 7725552622067dc45013d240f73952fece703f5e63bdJohn Wiegley ExprResult SubExpr; 7726552622067dc45013d240f73952fece703f5e63bdJohn Wiegley { 7727552622067dc45013d240f73952fece703f5e63bdJohn Wiegley EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 7728552622067dc45013d240f73952fece703f5e63bdJohn Wiegley SubExpr = getDerived().TransformExpr(E->getQueriedExpression()); 7729552622067dc45013d240f73952fece703f5e63bdJohn Wiegley if (SubExpr.isInvalid()) 7730552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return ExprError(); 7731552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 7732552622067dc45013d240f73952fece703f5e63bdJohn Wiegley if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression()) 7733552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return SemaRef.Owned(E); 7734552622067dc45013d240f73952fece703f5e63bdJohn Wiegley } 7735552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 7736552622067dc45013d240f73952fece703f5e63bdJohn Wiegley return getDerived().RebuildExpressionTrait( 7737552622067dc45013d240f73952fece703f5e63bdJohn Wiegley E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd()); 7738552622067dc45013d240f73952fece703f5e63bdJohn Wiegley} 7739552622067dc45013d240f73952fece703f5e63bdJohn Wiegley 7740552622067dc45013d240f73952fece703f5e63bdJohn Wiegleytemplate<typename Derived> 7741552622067dc45013d240f73952fece703f5e63bdJohn WiegleyExprResult 7742865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformDependentScopeDeclRefExpr( 77432577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DependentScopeDeclRefExpr *E) { 774400cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor NestedNameSpecifierLoc QualifierLoc 774500cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc()); 774600cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor if (!QualifierLoc) 7747f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7748e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); 77491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 775043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // TODO: If this is a conversion-function-id, verify that the 775143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // destination type name (if present) resolves the same way after 775243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // instantiation as it did in the local scope. 775343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 77542577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo 77552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); 77562577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!NameInfo.getName()) 7757f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 77581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7759f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!E->hasExplicitTemplateArgs()) { 7760f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!getDerived().AlwaysRebuild() && 776100cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor QualifierLoc == E->getQualifierLoc() && 77622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // Note: it is sufficient to compare the Name component of NameInfo: 77632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // if name has not changed, DNLoc has not changed either. 77642577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getDeclName()) 77653fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 77661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 776700cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, 7768e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateKWLoc, 77692577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7770f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /*TemplateArgs*/ 0); 7771f17bb74e74aca9bb0525d2249041ab65c7d1fd48Douglas Gregor } 7772d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 7773d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); 7774fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 7775fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 7776fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 7777fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 7778b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 777900cf3cc2718671aa48e8da264a523b0058a8591eDouglas Gregor return getDerived().RebuildDependentScopeDeclRefExpr(QualifierLoc, 7780e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateKWLoc, 77812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 7782f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall &TransArgs); 7783b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 7784b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7785b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 778660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7787454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { 7788321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor // CXXConstructExprs are always implicit, so when we have a 7789321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor // 1-argument construction we just transform that argument. 7790321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor if (E->getNumArgs() == 1 || 7791321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) 7792321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor return getDerived().TransformExpr(E->getArg(0)); 7793321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor 7794b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); 7795b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7796b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor QualType T = getDerived().TransformType(E->getType()); 7797b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (T.isNull()) 7798f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 7799b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 7800b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXConstructorDecl *Constructor 7801b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = cast_or_null<CXXConstructorDecl>( 78027c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 78037c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 7804b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Constructor) 7805f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 78061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7807b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 7808ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 7809aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 7810aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 7811aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 7812aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 7813b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7814b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T == E->getType() && 7815b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Constructor == E->getConstructor() && 7816c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor !ArgumentChanged) { 78171af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark the constructor as referenced. 78181af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: Instantiation-specific 78195f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); 78203fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 7821c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor } 78221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 78234411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), 78244411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor Constructor, E->isElidable(), 78258c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor move_arg(Args), 78267cc58b4c927fca539d43eaa58e00dca95946eb7cAbramo Bagnara E->hadMultipleCandidates(), 78278c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor E->requiresZeroInitialization(), 7828428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth E->getConstructionKind(), 7829428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth E->getParenRange()); 7830b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 78311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7832b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform a C++ temporary-binding expression. 7833b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 78345132655e4296b780672e9a96b46a740135073534Douglas Gregor/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just 78355132655e4296b780672e9a96b46a740135073534Douglas Gregor/// transform the subexpression and return that. 7836b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 783760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7838454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { 78395132655e4296b780672e9a96b46a740135073534Douglas Gregor return getDerived().TransformExpr(E->getSubExpr()); 7840b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 78411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 78424765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// \brief Transform a C++ expression that contains cleanups that should 78434765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// be run after the expression is evaluated. 7844b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 78454765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Since ExprWithCleanups nodes are implicitly generated, we 78465132655e4296b780672e9a96b46a740135073534Douglas Gregor/// just transform the subexpression and return that. 7847b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 784860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 78494765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallTreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { 78505132655e4296b780672e9a96b46a740135073534Douglas Gregor return getDerived().TransformExpr(E->getSubExpr()); 7851b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 78521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7853b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 785460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7855b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXTemporaryObjectExpr( 7856ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXTemporaryObjectExpr *E) { 7857ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 7858ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 7859f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 78601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7861b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXConstructorDecl *Constructor 7862b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = cast_or_null<CXXConstructorDecl>( 7863c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt getDerived().TransformDecl(E->getLocStart(), 78647c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 7865b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Constructor) 7866f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 78671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7868b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 7869ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 7870b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Args.reserve(E->getNumArgs()); 7871aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 7872aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 7873aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 78741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7875b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 7876ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo() && 7877b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Constructor == E->getConstructor() && 787891be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor !ArgumentChanged) { 787991be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor // FIXME: Instantiation-specific 78805f2987c11491edb186401d4e8eced275f0ea7c5eEli Friedman SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor); 78813fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.MaybeBindToTemporary(E); 788291be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor } 7883ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor 7884ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXTemporaryObjectExpr(T, 7885ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /*FIXME:*/T->getTypeLoc().getEndLoc(), 7886b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Args), 7887b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 7888b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 78891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7890b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 789160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 789201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas GregorTreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) { 7893dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // Create the local class that will describe the lambda. 7894dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor CXXRecordDecl *Class 7895f54486acc1cadf2791c3916ece66fded1e57ba0bDouglas Gregor = getSema().createLambdaClosureType(E->getIntroducerRange(), 7896f54486acc1cadf2791c3916ece66fded1e57ba0bDouglas Gregor /*KnownDependent=*/false); 7897dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor getDerived().transformedLocalDecl(E->getLambdaClass(), Class); 7898dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 7899dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // Transform the type of the lambda parameters and start the definition of 7900dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // the lambda itself. 7901dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor TypeSourceInfo *MethodTy 7902dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor = TransformType(E->getCallOperator()->getTypeSourceInfo()); 7903dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor if (!MethodTy) 7904dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor return ExprError(); 7905dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 7906c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor // Transform lambda parameters. 7907c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor bool Invalid = false; 7908c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor llvm::SmallVector<QualType, 4> ParamTypes; 7909c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor llvm::SmallVector<ParmVarDecl *, 4> Params; 7910c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor if (getDerived().TransformFunctionTypeParams(E->getLocStart(), 7911c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor E->getCallOperator()->param_begin(), 7912c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor E->getCallOperator()->param_size(), 7913c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor 0, ParamTypes, &Params)) 7914c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor Invalid = true; 7915c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor 7916dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // Build the call operator. 7917f54486acc1cadf2791c3916ece66fded1e57ba0bDouglas Gregor // Note: Once a lambda mangling number and context declaration have been 7918f54486acc1cadf2791c3916ece66fded1e57ba0bDouglas Gregor // assigned, they never change. 7919f54486acc1cadf2791c3916ece66fded1e57ba0bDouglas Gregor unsigned ManglingNumber = E->getLambdaClass()->getLambdaManglingNumber(); 7920f54486acc1cadf2791c3916ece66fded1e57ba0bDouglas Gregor Decl *ContextDecl = E->getLambdaClass()->getLambdaContextDecl(); 7921dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor CXXMethodDecl *CallOperator 7922dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor = getSema().startLambdaDefinition(Class, E->getIntroducerRange(), 7923dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor MethodTy, 7924c6889e7ed16604c51994e1f11becf213fdc64eb3Douglas Gregor E->getCallOperator()->getLocEnd(), 7925f54486acc1cadf2791c3916ece66fded1e57ba0bDouglas Gregor Params, ManglingNumber, ContextDecl); 7926dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor getDerived().transformAttrs(E->getCallOperator(), CallOperator); 7927dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 7928d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor // FIXME: Instantiation-specific. 7929d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor CallOperator->setInstantiationOfMemberFunction(E->getCallOperator(), 7930d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor TSK_ImplicitInstantiation); 7931d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor 7932d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor // Introduce the context of the call operator. 7933d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor Sema::ContextRAII SavedContext(getSema(), CallOperator); 7934d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor 7935dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // Enter the scope of the lambda. 7936dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor sema::LambdaScopeInfo *LSI 7937dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor = getSema().enterLambdaScope(CallOperator, E->getIntroducerRange(), 7938dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor E->getCaptureDefault(), 7939dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor E->hasExplicitParameters(), 7940dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor E->hasExplicitResultType(), 7941dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor E->isMutable()); 7942dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 7943dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // Transform captures. 7944dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor bool FinishedExplicitCaptures = false; 7945dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor for (LambdaExpr::capture_iterator C = E->capture_begin(), 7946dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor CEnd = E->capture_end(); 7947dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor C != CEnd; ++C) { 7948dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // When we hit the first implicit capture, tell Sema that we've finished 7949dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // the list of explicit captures. 7950dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor if (!FinishedExplicitCaptures && C->isImplicit()) { 7951dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor getSema().finishLambdaExplicitCaptures(LSI); 7952dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor FinishedExplicitCaptures = true; 7953dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor } 7954dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 7955dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // Capturing 'this' is trivial. 7956dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor if (C->capturesThis()) { 7957dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit()); 7958dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor continue; 7959dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor } 7960dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 7961a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor // Determine the capture kind for Sema. 7962a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor Sema::TryCaptureKind Kind 7963a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor = C->isImplicit()? Sema::TryCapture_Implicit 7964a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor : C->getCaptureKind() == LCK_ByCopy 7965a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor ? Sema::TryCapture_ExplicitByVal 7966a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor : Sema::TryCapture_ExplicitByRef; 7967a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor SourceLocation EllipsisLoc; 7968a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor if (C->isPackExpansion()) { 7969a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation()); 7970a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor bool ShouldExpand = false; 7971a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor bool RetainExpansion = false; 7972a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor llvm::Optional<unsigned> NumExpansions; 7973a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(), 7974a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor C->getLocation(), 7975a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor Unexpanded, 7976a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor ShouldExpand, RetainExpansion, 7977a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor NumExpansions)) 7978a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor return ExprError(); 7979a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor 7980a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor if (ShouldExpand) { 7981a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor // The transform has determined that we should perform an expansion; 7982a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor // transform and capture each of the arguments. 7983a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor // expansion of the pattern. Do so. 7984a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor VarDecl *Pack = C->getCapturedVar(); 7985a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor for (unsigned I = 0; I != *NumExpansions; ++I) { 7986a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 7987a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor VarDecl *CapturedVar 7988a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), 7989a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor Pack)); 7990a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor if (!CapturedVar) { 7991a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor Invalid = true; 7992a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor continue; 7993a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor } 7994a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor 7995a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor // Capture the transformed variable. 7996999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); 7997a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor } 7998a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor continue; 7999a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor } 8000a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor 8001a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor EllipsisLoc = C->getEllipsisLoc(); 8002a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor } 8003a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor 8004dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // Transform the captured variable. 8005dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor VarDecl *CapturedVar 8006dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(), 8007dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor C->getCapturedVar())); 8008dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor if (!CapturedVar) { 8009dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor Invalid = true; 8010dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor continue; 8011dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor } 8012a73652465bcc4c0f6cb7d933ad84e002b527a643Douglas Gregor 8013dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // Capture the transformed variable. 8014999713eea940f4e087cc3ac878689c5c5c7a7225Douglas Gregor getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind); 8015dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor } 8016dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor if (!FinishedExplicitCaptures) 8017dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor getSema().finishLambdaExplicitCaptures(LSI); 8018dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 8019dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 8020dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // Enter a new evaluation context to insulate the lambda from any 8021dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // cleanups from the enclosing full-expression. 8022dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated); 8023dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 8024dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor if (Invalid) { 8025dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0, 8026dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor /*IsInstantiation=*/true); 8027dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor return ExprError(); 8028dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor } 8029dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor 8030dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor // Instantiate the body of the lambda expression. 8031d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor StmtResult Body = getDerived().TransformStmt(E->getBody()); 8032d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor if (Body.isInvalid()) { 8033d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/0, 8034d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor /*IsInstantiation=*/true); 8035d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor return ExprError(); 8036d5387e86ce3dfe1ae09e050ee11d86ca0d066d04Douglas Gregor } 8037ccc1b5eebc6ca8a904c58c0468b9a71483b7c7cfDouglas Gregor 8038dfca6f53ab97d28d43e3fa2564209df08f3d282cDouglas Gregor return getSema().ActOnLambdaExpr(E->getLocStart(), Body.take(), 8039f54486acc1cadf2791c3916ece66fded1e57ba0bDouglas Gregor /*CurScope=*/0, /*IsInstantiation=*/true); 804001d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor} 804101d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregor 804201d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas Gregortemplate<typename Derived> 804301d08018b7cf5ce1601707cfd7a84d22015fc04eDouglas GregorExprResult 8044b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( 8045454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXUnresolvedConstructExpr *E) { 8046ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 8047ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 8048f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 80491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8050b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 8051ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 8052aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args.reserve(E->arg_size()); 8053aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, 8054aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 8055aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 8056aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 8057b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 8058ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo() && 8059b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgumentChanged) 80603fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 80611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8062b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: we're faking the locations of the commas 8063ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXUnresolvedConstructExpr(T, 8064b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLParenLoc(), 8065b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Args), 8066b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 8067b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 80681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8069b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 807060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8071865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( 80722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara CXXDependentScopeMemberExpr *E) { 8073b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the base of the expression. 807460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base((Expr*) 0); 8075aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *OldBase; 8076aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType; 8077aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType ObjectType; 8078aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!E->isImplicitAccess()) { 8079aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OldBase = E->getBase(); 8080aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base = getDerived().TransformExpr(OldBase); 8081aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 8082f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 80831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8084aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall // Start the member reference and compute the object's type. 8085b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectTy; 8086d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor bool MayBePseudoDestructor = false; 80879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), 8088aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall E->getOperatorLoc(), 8089a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor E->isArrow()? tok::arrow : tok::period, 8090d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor ObjectTy, 8091d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor MayBePseudoDestructor); 8092aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 8093f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8094aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 8095b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ObjectType = ObjectTy.get(); 8096aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = ((Expr*) Base.get())->getType(); 8097aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } else { 8098aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OldBase = 0; 8099aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = getDerived().TransformType(E->getBaseType()); 8100aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); 8101aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 81021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 81036cd219879ffce00920189ec1dcea927a42602961Douglas Gregor // Transform the first part of the nested-name-specifier that qualifies 81046cd219879ffce00920189ec1dcea927a42602961Douglas Gregor // the member name. 8105c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor NamedDecl *FirstQualifierInScope 81066cd219879ffce00920189ec1dcea927a42602961Douglas Gregor = getDerived().TransformFirstQualifierInScope( 81077c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor E->getFirstQualifierFoundInScope(), 81087c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor E->getQualifierLoc().getBeginLoc()); 81091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 81107c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 8111a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor if (E->getQualifier()) { 81127c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc 81137c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(), 81147c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor ObjectType, 81157c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor FirstQualifierInScope); 81167c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor if (!QualifierLoc) 8117f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8118a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor } 81191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8120e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc(); 8121e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 812243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // TODO: If this is a conversion-function-id, verify that the 812343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // destination type name (if present) resolves the same way after 812443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // instantiation as it did in the local scope. 812543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 81262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo 812743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); 81282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!NameInfo.getName()) 8129f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 81301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8131aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!E->hasExplicitTemplateArgs()) { 81323b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor // This is a reference to a member without an explicitly-specified 81333b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor // template argument list. Optimize for this common case. 81343b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor if (!getDerived().AlwaysRebuild() && 8135aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base.get() == OldBase && 8136aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType == E->getBaseType() && 81377c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc == E->getQualifierLoc() && 81382577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getMember() && 81393b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor FirstQualifierInScope == E->getFirstQualifierFoundInScope()) 81403fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 81411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 81429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), 8143aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 81443b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor E->isArrow(), 81453b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor E->getOperatorLoc(), 81467c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc, 8147e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateKWLoc, 8148129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall FirstQualifierInScope, 81492577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 8150129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /*TemplateArgs*/ 0); 81513b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 81523b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor 8153d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); 8154fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 8155fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 8156fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 8157fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 81581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 81599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), 8160aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 8161b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrow(), 8162b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOperatorLoc(), 81637c3179cf463c3b3b8c21dbb955f933ba50b74f28Douglas Gregor QualifierLoc, 8164e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateKWLoc, 81653b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor FirstQualifierInScope, 81662577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 8167129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall &TransArgs); 8168129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall} 8169129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 8170129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCalltemplate<typename Derived> 817160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8172454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { 8173129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Transform the base of the expression. 817460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base((Expr*) 0); 8175aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType; 8176aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!Old->isImplicitAccess()) { 8177aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base = getDerived().TransformExpr(Old->getBase()); 8178aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 8179f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 81809138b4e96429cbaae00c52c15c960f72b6645088Richard Smith Base = getSema().PerformMemberExprBaseConversion(Base.take(), 81819138b4e96429cbaae00c52c15c960f72b6645088Richard Smith Old->isArrow()); 81829138b4e96429cbaae00c52c15c960f72b6645088Richard Smith if (Base.isInvalid()) 81839138b4e96429cbaae00c52c15c960f72b6645088Richard Smith return ExprError(); 81849138b4e96429cbaae00c52c15c960f72b6645088Richard Smith BaseType = Base.get()->getType(); 8185aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } else { 8186aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = getDerived().TransformType(Old->getBaseType()); 8187aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 8188129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 81894c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor NestedNameSpecifierLoc QualifierLoc; 81904c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (Old->getQualifierLoc()) { 81914c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor QualifierLoc 81924c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc()); 81934c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor if (!QualifierLoc) 8194f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8195129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 8196129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 8197e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc(); 8198e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara 81992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LookupResult R(SemaRef, Old->getMemberNameInfo(), 8200129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Sema::LookupOrdinaryName); 8201129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 8202129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Transform all the decls. 8203129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), 8204129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall E = Old->decls_end(); I != E; ++I) { 82057c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor NamedDecl *InstD = static_cast<NamedDecl*>( 82067c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(Old->getMemberLoc(), 82077c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor *I)); 82089f54ad4381370c6b771424b53d219e661d6d6706John McCall if (!InstD) { 82099f54ad4381370c6b771424b53d219e661d6d6706John McCall // Silently ignore these if a UsingShadowDecl instantiated to nothing. 82109f54ad4381370c6b771424b53d219e661d6d6706John McCall // This can happen because of dependent hiding. 82119f54ad4381370c6b771424b53d219e661d6d6706John McCall if (isa<UsingShadowDecl>(*I)) 82129f54ad4381370c6b771424b53d219e661d6d6706John McCall continue; 821334f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis else { 821434f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis R.clear(); 8215f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 821634f52d14742914bbaa975ce7de45957cccf256bcArgyrios Kyrtzidis } 82179f54ad4381370c6b771424b53d219e661d6d6706John McCall } 8218129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 8219129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Expand using declarations. 8220129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (isa<UsingDecl>(InstD)) { 8221129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall UsingDecl *UD = cast<UsingDecl>(InstD); 8222129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall for (UsingDecl::shadow_iterator I = UD->shadow_begin(), 8223129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall E = UD->shadow_end(); I != E; ++I) 8224129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.addDecl(*I); 8225129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall continue; 8226129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 8227129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 8228129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.addDecl(InstD); 8229129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 8230129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 8231129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.resolveKind(); 8232129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 8233c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor // Determine the naming class. 8234042d6f98ea73d781e43cc17077e8fc84a4201eefChandler Carruth if (Old->getNamingClass()) { 8235c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt CXXRecordDecl *NamingClass 8236c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( 823766c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getMemberLoc(), 823866c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNamingClass())); 823966c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor if (!NamingClass) 8240f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8241c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 824266c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor R.setNamingClass(NamingClass); 8243c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor } 8244c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8245129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TemplateArgumentListInfo TransArgs; 8246129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (Old->hasExplicitTemplateArgs()) { 8247129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TransArgs.setLAngleLoc(Old->getLAngleLoc()); 8248129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TransArgs.setRAngleLoc(Old->getRAngleLoc()); 8249fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), 8250fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor Old->getNumTemplateArgs(), 8251fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 8252fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 8253129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 8254c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 8255c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // FIXME: to do this check properly, we will need to preserve the 8256c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // first-qualifier-in-scope here, just in case we had a dependent 8257c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // base (and therefore couldn't do the check) and a 8258c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // nested-name-qualifier (and therefore could do the lookup). 8259c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall NamedDecl *FirstQualifierInScope = 0; 8260c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 82619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildUnresolvedMemberExpr(Base.get(), 8262aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 8263129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Old->getOperatorLoc(), 8264129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Old->isArrow(), 82654c9be89bb615ec07eb3ed507c8fa9d0baa8a5ad7Douglas Gregor QualifierLoc, 8266e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara TemplateKWLoc, 8267c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall FirstQualifierInScope, 8268129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R, 8269129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall (Old->hasExplicitTemplateArgs() 8270129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall ? &TransArgs : 0)); 8271b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8272b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 8273b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 827460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 82752e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlTreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { 8276eea06c609b73afc7bcfdf3e101efb8d9e7b3560cSean Hunt EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 82772e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); 82782e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl if (SubExpr.isInvalid()) 82792e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return ExprError(); 82802e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 82812e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) 82823fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 82832e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 82842e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); 82852e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl} 82862e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 82872e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redltemplate<typename Derived> 82882e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlExprResult 8289be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorTreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { 82904f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor ExprResult Pattern = getDerived().TransformExpr(E->getPattern()); 82914f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor if (Pattern.isInvalid()) 82924f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor return ExprError(); 82934f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor 82944f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern()) 82954f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor return SemaRef.Owned(E); 82964f1d282d6f32a419e89ddb56342e2313b0c78bb7Douglas Gregor 829767fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(), 829867fd1251aad51bb80d050b7fa5e506fef0ec8e02Douglas Gregor E->getNumExpansions()); 8299be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor} 8300ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 8301ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregortemplate<typename Derived> 8302ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorExprResult 8303ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorTreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { 8304ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // If E is not value-dependent, then nothing will change when we transform it. 8305ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // Note: This is an instantiation-centric view. 8306ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor if (!E->isValueDependent()) 8307ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return SemaRef.Owned(E); 8308ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 8309ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // Note: None of the implementations of TryExpandParameterPacks can ever 8310ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // produce a diagnostic when given only a single unexpanded parameter pack, 8311ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // so 8312ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); 8313ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor bool ShouldExpand = false; 8314d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor bool RetainExpansion = false; 8315cded4f649cd4b7ba7d461c25c6482ef52b8d3a2aDouglas Gregor llvm::Optional<unsigned> NumExpansions; 8316ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), 8317a71f9d0a5e1f8cafdd23a17e292de22fdc8e99ffDavid Blaikie Unexpanded, 8318d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor ShouldExpand, RetainExpansion, 8319d3731198193eee92796ddeb493973b7a598b003eDouglas Gregor NumExpansions)) 8320ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return ExprError(); 8321ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 8322089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor if (RetainExpansion) 8323ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return SemaRef.Owned(E); 8324089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor 8325089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor NamedDecl *Pack = E->getPack(); 8326089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor if (!ShouldExpand) { 8327089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(), 8328089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor Pack)); 8329089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor if (!Pack) 8330089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor return ExprError(); 8331089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor } 8332089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor 8333be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 8334ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // We now know the length of the parameter pack, so build a new expression 8335ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // that stores that length. 8336089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack, 8337ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor E->getPackLoc(), E->getRParenLoc(), 8338089e8939b7b3e72c32477e39df82f18e6a8f436eDouglas Gregor NumExpansions); 8339ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor} 8340ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 8341be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregortemplate<typename Derived> 8342be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorExprResult 8343c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorTreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr( 8344c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor SubstNonTypeTemplateParmPackExpr *E) { 8345c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor // Default behavior is to do nothing with this transformation. 834691a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall return SemaRef.Owned(E); 834791a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall} 834891a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall 834991a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCalltemplate<typename Derived> 835091a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallExprResult 835191a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCallTreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr( 835291a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall SubstNonTypeTemplateParmExpr *E) { 835391a5755ad73c5dc1dfb167e448fdd74e75a6df56John McCall // Default behavior is to do nothing with this transformation. 8354c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor return SemaRef.Owned(E); 8355c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor} 8356c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregor 8357c7793c73ba8a343de3f2552d984851985a46f159Douglas Gregortemplate<typename Derived> 8358c7793c73ba8a343de3f2552d984851985a46f159Douglas GregorExprResult 835903e80030515c800d1ab44125b9052dfffd1bd04cDouglas GregorTreeTransform<Derived>::TransformMaterializeTemporaryExpr( 836003e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor MaterializeTemporaryExpr *E) { 836103e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor return getDerived().TransformExpr(E->GetTemporaryExpr()); 836203e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor} 836303e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregor 836403e80030515c800d1ab44125b9052dfffd1bd04cDouglas Gregortemplate<typename Derived> 836503e80030515c800d1ab44125b9052dfffd1bd04cDouglas GregorExprResult 8366454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { 8367ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return SemaRef.MaybeBindToTemporary(E); 8368ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 8369ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8370ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenektemplate<typename Derived> 8371ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult 8372ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekTreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) { 8373d8b5ca14277e142506daed181ecff9151dfae32cJordy Rose return SemaRef.Owned(E); 8374ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 8375ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8376ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenektemplate<typename Derived> 8377ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult 8378eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick BeardTreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) { 8379eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 8380eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard if (SubExpr.isInvalid()) 8381eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard return ExprError(); 8382eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard 8383eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard if (!getDerived().AlwaysRebuild() && 8384eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard SubExpr.get() == E->getSubExpr()) 8385eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard return SemaRef.Owned(E); 8386eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard 8387eb382ec1507cf2c8c12d7443d0b67c076223aec6Patrick Beard return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get()); 8388ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 8389ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8390ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenektemplate<typename Derived> 8391ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult 8392ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekTreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) { 8393ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Transform each of the elements. 8394ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek llvm::SmallVector<Expr *, 8> Elements; 8395ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool ArgChanged = false; 8396ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (getDerived().TransformExprs(E->getElements(), E->getNumElements(), 8397ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek /*IsCall=*/false, Elements, &ArgChanged)) 8398ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(); 8399ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8400ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (!getDerived().AlwaysRebuild() && !ArgChanged) 8401ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return SemaRef.MaybeBindToTemporary(E); 8402ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8403ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(), 8404ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Elements.data(), 8405ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Elements.size()); 8406ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 8407ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8408ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenektemplate<typename Derived> 8409ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult 8410ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekTreeTransform<Derived>::TransformObjCDictionaryLiteral( 8411ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCDictionaryLiteral *E) { 8412ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Transform each of the elements. 8413ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek llvm::SmallVector<ObjCDictionaryElement, 8> Elements; 8414ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool ArgChanged = false; 8415ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) { 8416ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCDictionaryElement OrigElement = E->getKeyValueElement(I); 8417ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8418ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (OrigElement.isPackExpansion()) { 8419ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // This key/value element is a pack expansion. 8420ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SmallVector<UnexpandedParameterPack, 2> Unexpanded; 8421ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded); 8422ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded); 8423ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 8424ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8425ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Determine whether the set of unexpanded parameter packs can 8426ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // and should be expanded. 8427ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool Expand = true; 8428ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek bool RetainExpansion = false; 8429ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek llvm::Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions; 8430ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek llvm::Optional<unsigned> NumExpansions = OrigNumExpansions; 8431ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek SourceRange PatternRange(OrigElement.Key->getLocStart(), 8432ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek OrigElement.Value->getLocEnd()); 8433ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc, 8434ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek PatternRange, 8435ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Unexpanded, 8436ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Expand, RetainExpansion, 8437ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek NumExpansions)) 8438ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(); 8439ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8440ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (!Expand) { 8441ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // The transform has determined that we should perform a simple 8442ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // transformation on the pack expansion, producing another pack 8443ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // expansion. 8444ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 8445ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult Key = getDerived().TransformExpr(OrigElement.Key); 8446ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Key.isInvalid()) 8447ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(); 8448ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8449ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Key.get() != OrigElement.Key) 8450ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ArgChanged = true; 8451ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8452ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult Value = getDerived().TransformExpr(OrigElement.Value); 8453ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Value.isInvalid()) 8454ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(); 8455ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8456ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Value.get() != OrigElement.Value) 8457ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ArgChanged = true; 8458ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8459ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCDictionaryElement Expansion = { 8460ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions 8461ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek }; 8462ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Elements.push_back(Expansion); 8463ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek continue; 8464ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 8465ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8466ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Record right away that the argument was changed. This needs 8467ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // to happen even if the array expands to nothing. 8468ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ArgChanged = true; 8469ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8470ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // The transform has determined that we should perform an elementwise 8471ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // expansion of the pattern. Do so. 8472ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek for (unsigned I = 0; I != *NumExpansions; ++I) { 8473ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 8474ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult Key = getDerived().TransformExpr(OrigElement.Key); 8475ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Key.isInvalid()) 8476ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(); 8477ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8478ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult Value = getDerived().TransformExpr(OrigElement.Value); 8479ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Value.isInvalid()) 8480ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(); 8481ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8482ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCDictionaryElement Element = { 8483ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Key.get(), Value.get(), SourceLocation(), NumExpansions 8484ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek }; 8485ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8486ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // If any unexpanded parameter packs remain, we still have a 8487ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // pack expansion. 8488ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Key.get()->containsUnexpandedParameterPack() || 8489ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Value.get()->containsUnexpandedParameterPack()) 8490ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Element.EllipsisLoc = OrigElement.EllipsisLoc; 8491ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8492ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Elements.push_back(Element); 8493ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 8494ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8495ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // We've finished with this pack expansion. 8496ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek continue; 8497ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 8498ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8499ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Transform and check key. 8500ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult Key = getDerived().TransformExpr(OrigElement.Key); 8501ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Key.isInvalid()) 8502ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(); 8503ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8504ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Key.get() != OrigElement.Key) 8505ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ArgChanged = true; 8506ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8507ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Transform and check value. 8508ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult Value 8509ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek = getDerived().TransformExpr(OrigElement.Value); 8510ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Value.isInvalid()) 8511ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(); 8512ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8513ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Value.get() != OrigElement.Value) 8514ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ArgChanged = true; 8515ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8516ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ObjCDictionaryElement Element = { 8517ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Key.get(), Value.get(), SourceLocation(), llvm::Optional<unsigned>() 8518ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek }; 8519ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Elements.push_back(Element); 8520ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek } 8521ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8522ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (!getDerived().AlwaysRebuild() && !ArgChanged) 8523ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return SemaRef.MaybeBindToTemporary(E); 8524ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8525ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(), 8526ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Elements.data(), 8527ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Elements.size()); 8528b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8529b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 85301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 853160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8532454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { 853381d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *EncodedTypeInfo 853481d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor = getDerived().TransformType(E->getEncodedTypeSourceInfo()); 853581d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor if (!EncodedTypeInfo) 8536f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 85371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8538b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 853981d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedTypeInfo == E->getEncodedTypeSourceInfo()) 85403fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8541b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 8542b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), 854381d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedTypeInfo, 8544b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 8545b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 85461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8547b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 8548f85e193739c953358c865005855253af4f68a497John McCallExprResult TreeTransform<Derived>:: 8549f85e193739c953358c865005855253af4f68a497John McCallTransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) { 8550f85e193739c953358c865005855253af4f68a497John McCall ExprResult result = getDerived().TransformExpr(E->getSubExpr()); 8551f85e193739c953358c865005855253af4f68a497John McCall if (result.isInvalid()) return ExprError(); 8552f85e193739c953358c865005855253af4f68a497John McCall Expr *subExpr = result.take(); 8553f85e193739c953358c865005855253af4f68a497John McCall 8554f85e193739c953358c865005855253af4f68a497John McCall if (!getDerived().AlwaysRebuild() && 8555f85e193739c953358c865005855253af4f68a497John McCall subExpr == E->getSubExpr()) 8556f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(E); 8557f85e193739c953358c865005855253af4f68a497John McCall 8558f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(new(SemaRef.Context) 8559f85e193739c953358c865005855253af4f68a497John McCall ObjCIndirectCopyRestoreExpr(subExpr, E->getType(), E->shouldCopy())); 8560f85e193739c953358c865005855253af4f68a497John McCall} 8561f85e193739c953358c865005855253af4f68a497John McCall 8562f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived> 8563f85e193739c953358c865005855253af4f68a497John McCallExprResult TreeTransform<Derived>:: 8564f85e193739c953358c865005855253af4f68a497John McCallTransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) { 8565f85e193739c953358c865005855253af4f68a497John McCall TypeSourceInfo *TSInfo 8566f85e193739c953358c865005855253af4f68a497John McCall = getDerived().TransformType(E->getTypeInfoAsWritten()); 8567f85e193739c953358c865005855253af4f68a497John McCall if (!TSInfo) 8568f85e193739c953358c865005855253af4f68a497John McCall return ExprError(); 8569f85e193739c953358c865005855253af4f68a497John McCall 8570f85e193739c953358c865005855253af4f68a497John McCall ExprResult Result = getDerived().TransformExpr(E->getSubExpr()); 8571f85e193739c953358c865005855253af4f68a497John McCall if (Result.isInvalid()) 8572f85e193739c953358c865005855253af4f68a497John McCall return ExprError(); 8573f85e193739c953358c865005855253af4f68a497John McCall 8574f85e193739c953358c865005855253af4f68a497John McCall if (!getDerived().AlwaysRebuild() && 8575f85e193739c953358c865005855253af4f68a497John McCall TSInfo == E->getTypeInfoAsWritten() && 8576f85e193739c953358c865005855253af4f68a497John McCall Result.get() == E->getSubExpr()) 8577f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.Owned(E); 8578f85e193739c953358c865005855253af4f68a497John McCall 8579f85e193739c953358c865005855253af4f68a497John McCall return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(), 8580f85e193739c953358c865005855253af4f68a497John McCall E->getBridgeKeywordLoc(), TSInfo, 8581f85e193739c953358c865005855253af4f68a497John McCall Result.get()); 8582f85e193739c953358c865005855253af4f68a497John McCall} 8583f85e193739c953358c865005855253af4f68a497John McCall 8584f85e193739c953358c865005855253af4f68a497John McCalltemplate<typename Derived> 858560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8586454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { 858792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Transform arguments. 858892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor bool ArgChanged = false; 8589ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 8590aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args.reserve(E->getNumArgs()); 8591aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, 8592aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgChanged)) 8593aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 8594aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 859592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (E->getReceiverKind() == ObjCMessageExpr::Class) { 859692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Class message: transform the receiver type. 859792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor TypeSourceInfo *ReceiverTypeInfo 859892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor = getDerived().TransformType(E->getClassReceiverTypeInfo()); 859992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!ReceiverTypeInfo) 8600f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8601c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 860292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // If nothing changed, just retain the existing message send. 860392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!getDerived().AlwaysRebuild() && 860492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) 860592be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 860692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 860792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Build a new class message send. 8608207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SmallVector<SourceLocation, 16> SelLocs; 8609207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis E->getSelectorLocs(SelLocs); 861092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, 861192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getSelector(), 8612207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocs, 861392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getMethodDecl(), 861492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getLeftLoc(), 861592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor move_arg(Args), 861692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getRightLoc()); 861792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 861892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 861992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Instance message: transform the receiver 862092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor assert(E->getReceiverKind() == ObjCMessageExpr::Instance && 862192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor "Only class and instance messages may be instantiated"); 862260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Receiver 862392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor = getDerived().TransformExpr(E->getInstanceReceiver()); 862492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (Receiver.isInvalid()) 8625f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 862692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 862792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // If nothing changed, just retain the existing message send. 862892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!getDerived().AlwaysRebuild() && 862992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Receiver.get() == E->getInstanceReceiver() && !ArgChanged) 863092be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return SemaRef.MaybeBindToTemporary(E); 8631c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 863292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Build a new instance message send. 8633207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SmallVector<SourceLocation, 16> SelLocs; 8634207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis E->getSelectorLocs(SelLocs); 86359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCMessageExpr(Receiver.get(), 863692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getSelector(), 8637207180802c836fda8acbedb47a92f9d2bdca59c3Argyrios Kyrtzidis SelLocs, 863892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getMethodDecl(), 863992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getLeftLoc(), 864092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor move_arg(Args), 864192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getRightLoc()); 8642b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8643b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 86441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 864560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8646454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { 86473fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8648b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8649b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 86501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 865160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8652454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { 86533fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8654b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8655b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 86561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 865760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8658454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { 8659f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // Transform the base expression. 866060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 8661f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Base.isInvalid()) 8662f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8663f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor 8664f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // We don't need to transform the ivar; it will never change. 8665c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8666f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // If nothing changed, just retain the existing expression. 8667f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (!getDerived().AlwaysRebuild() && 8668f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Base.get() == E->getBase()) 86693fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8670c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 86719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), 8672f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->getLocation(), 8673f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->isArrow(), E->isFreeIvar()); 8674b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8675b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 86761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 867760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8678454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { 867912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // 'super' and types never change. Property never changes. Just 868012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // retain the existing expression. 868112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (!E->isObjectReceiver()) 86823fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 86838ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian 8684e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // Transform the base expression. 868560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 8686e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (Base.isInvalid()) 8687f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8688c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8689e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // We don't need to transform the property; it will never change. 8690c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8691e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // If nothing changed, just retain the existing expression. 8692e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (!getDerived().AlwaysRebuild() && 8693e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor Base.get() == E->getBase()) 86943fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8695b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 869612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (E->isExplicitProperty()) 869712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getDerived().RebuildObjCPropertyRefExpr(Base.get(), 869812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getExplicitProperty(), 869912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getLocation()); 870012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 870112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getDerived().RebuildObjCPropertyRefExpr(Base.get(), 87023c3b7f90a863af43fa63043d396553ecf205351cJohn McCall SemaRef.Context.PseudoObjectTy, 870312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getImplicitPropertyGetter(), 870412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getImplicitPropertySetter(), 870512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getLocation()); 8706b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8707b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 87081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 870960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8710ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekTreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) { 8711ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Transform the base expression. 8712ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult Base = getDerived().TransformExpr(E->getBaseExpr()); 8713ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Base.isInvalid()) 8714ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(); 8715ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8716ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // Transform the key expression. 8717ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek ExprResult Key = getDerived().TransformExpr(E->getKeyExpr()); 8718ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (Key.isInvalid()) 8719ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return ExprError(); 8720ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8721ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek // If nothing changed, just retain the existing expression. 8722ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek if (!getDerived().AlwaysRebuild() && 8723ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr()) 8724ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return SemaRef.Owned(E); 8725ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8726ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(), 8727ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek Base.get(), Key.get(), 8728ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek E->getAtIndexMethodDecl(), 8729ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek E->setAtIndexMethodDecl()); 8730ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek} 8731ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenek 8732ebcb57a8d298862c65043e88b2429591ab3c58d3Ted Kremenektemplate<typename Derived> 8733ebcb57a8d298862c65043e88b2429591ab3c58d3Ted KremenekExprResult 8734454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { 8735f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // Transform the base expression. 873660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 8737f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Base.isInvalid()) 8738f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 8739c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 8740f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // If nothing changed, just retain the existing expression. 8741f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (!getDerived().AlwaysRebuild() && 8742f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Base.get() == E->getBase()) 87433fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 8744c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 87459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), 8746f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->isArrow()); 8747b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8748b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 87491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 875060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8751454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { 8752b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 8753ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> SubExprs(SemaRef); 8754aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor SubExprs.reserve(E->getNumSubExprs()); 8755aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, 8756aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor SubExprs, &ArgumentChanged)) 8757aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 87581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8759b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 8760b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgumentChanged) 87613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 87621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8763b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), 8764b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(SubExprs), 8765b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 8766b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8767b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 87681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 876960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 8770454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { 8771c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall BlockDecl *oldBlock = E->getBlockDecl(); 8772a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 8773c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/0); 8774c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall BlockScopeInfo *blockScope = SemaRef.getCurBlock(); 8775c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 8776c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic()); 87770586520acb2f368c874943353a222be7f00c3068Fariborz Jahanian blockScope->TheDecl->setBlockMissingReturnType( 87780586520acb2f368c874943353a222be7f00c3068Fariborz Jahanian oldBlock->blockMissingReturnType()); 8779ff365592d1878c0e454f288e30613664a72cff4cFariborz Jahanian 8780686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<ParmVarDecl*, 4> params; 8781686775deca8b8685eb90801495880e3abdd844c2Chris Lattner SmallVector<QualType, 4> paramTypes; 8782a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 8783a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian // Parameter substitution. 8784c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(), 8785c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldBlock->param_begin(), 8786c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldBlock->param_size(), 878700b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis 0, paramTypes, ¶ms)) { 878800b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); 878992be2a5f4e938fc512683cd4e7dfd4e6789eb787Douglas Gregor return ExprError(); 879000b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis } 8791c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 8792c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall const FunctionType *exprFunctionType = E->getFunctionType(); 879384b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman QualType exprResultType = 879484b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman getDerived().TransformType(exprFunctionType->getResultType()); 8795a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 8796a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor // Don't allow returning a objc interface by value. 879784b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman if (exprResultType->isObjCObjectType()) { 8798c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall getSema().Diag(E->getCaretLocation(), 8799a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor diag::err_object_cannot_be_passed_returned_by_value) 880084b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman << 0 << exprResultType; 880100b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); 8802a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor return ExprError(); 8803a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor } 8804711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 8805c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall QualType functionType = getDerived().RebuildFunctionProtoType( 880684b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman exprResultType, 8807c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall paramTypes.data(), 8808c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall paramTypes.size(), 8809c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall oldBlock->isVariadic(), 8810eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith false, 0, RQ_None, 8811c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall exprFunctionType->getExtInfo()); 8812c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall blockScope->FunctionType = functionType; 8813711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 8814711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Set the parameters on the block decl. 8815c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall if (!params.empty()) 88164278c654b645402554eb52a48e9c7097c9f1233aDavid Blaikie blockScope->TheDecl->setParams(params); 881784b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman 881884b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman if (!oldBlock->blockMissingReturnType()) { 881984b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman blockScope->HasImplicitReturnType = false; 882084b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman blockScope->ReturnType = exprResultType; 882184b007fae6c0cd30fa07074d34fbe2bf61fa44f9Eli Friedman } 8822a779d9ca2fdf1247f65de0e6acf2870d8be53ccdDouglas Gregor 8823711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Transform the body 8824c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall StmtResult body = getDerived().TransformStmt(E->getBody()); 882500b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis if (body.isInvalid()) { 882600b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/0); 8827711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return ExprError(); 882800b465747138ec5c00e1d7568d2eb88c6db6042dArgyrios Kyrtzidis } 8829711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 8830c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#ifndef NDEBUG 8831c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall // In builds with assertions, make sure that we captured everything we 8832c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall // captured before. 8833fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor if (!SemaRef.getDiagnostics().hasErrorOccurred()) { 8834fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor for (BlockDecl::capture_iterator i = oldBlock->capture_begin(), 8835fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor e = oldBlock->capture_end(); i != e; ++i) { 8836fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor VarDecl *oldCapture = i->getVariable(); 8837fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor 8838fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor // Ignore parameter packs. 8839fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor if (isa<ParmVarDecl>(oldCapture) && 8840fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor cast<ParmVarDecl>(oldCapture)->isParameterPack()) 8841fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor continue; 8842c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 8843fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor VarDecl *newCapture = 8844fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(), 8845fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor oldCapture)); 8846fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor assert(blockScope->CaptureMap.count(newCapture)); 8847fc92137eee708b632c00a9b0934ff87aeae234a5Douglas Gregor } 8848ec79d877c1998366480d97a7a6c94e15c053edd8Douglas Gregor assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured()); 8849c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall } 8850c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall#endif 8851c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall 8852c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(), 8853c6ac9c3d754f91d27b1734965e5f1a8e542e8f40John McCall /*Scope=*/0); 8854b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8855b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 88561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 885760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 885861eee0ca33b29e102f11bab77c8b74cc00e2392bTanya LattnerTreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) { 8859b219cfc4d75f0a03630b7c4509ef791b7e97b2c8David Blaikie llvm_unreachable("Cannot transform asType expressions yet"); 886061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner} 8861276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman 8862276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedmantemplate<typename Derived> 8863276b061970939293f1abaf694bd3ef05b2cbda79Eli FriedmanExprResult 8864276b061970939293f1abaf694bd3ef05b2cbda79Eli FriedmanTreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) { 8865dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman QualType RetTy = getDerived().TransformType(E->getType()); 8866dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman bool ArgumentChanged = false; 8867dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman ASTOwningVector<Expr*> SubExprs(SemaRef); 8868dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman SubExprs.reserve(E->getNumSubExprs()); 8869dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, 8870dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman SubExprs, &ArgumentChanged)) 8871dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman return ExprError(); 8872dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 8873dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman if (!getDerived().AlwaysRebuild() && 8874dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman !ArgumentChanged) 8875dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman return SemaRef.Owned(E); 8876dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman 8877dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), move_arg(SubExprs), 8878dfa64ba45922e1c28e36341bdf34785fea74659bEli Friedman RetTy, E->getOp(), E->getRParenLoc()); 8879276b061970939293f1abaf694bd3ef05b2cbda79Eli Friedman} 888061eee0ca33b29e102f11bab77c8b74cc00e2392bTanya Lattner 8881b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===// 8882b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Type reconstruction 8883b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===// 8884b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 88851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 888685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, 888785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Star) { 88882865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildPointerType(PointeeType, Star, 8889b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor getDerived().getBaseEntity()); 8890b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8891b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 88921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 889385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, 889485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Star) { 88952865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildBlockPointerType(PointeeType, Star, 8896b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor getDerived().getBaseEntity()); 8897b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8898b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 88991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 89001eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 890185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, 890285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall bool WrittenAsLValue, 890385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil) { 89042865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, 890585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Sigil, getDerived().getBaseEntity()); 8906b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 8907b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 89081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 89091eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 891085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, 891185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType ClassType, 891285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil) { 89132865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildMemberPointerType(PointeeType, ClassType, 891485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Sigil, getDerived().getBaseEntity()); 8915577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8916577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8917577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 89181eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 8919577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorTreeTransform<Derived>::RebuildArrayType(QualType ElementType, 8920577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 8921577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt *Size, 8922577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Expr *SizeExpr, 8923577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 8924577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 8925577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (SizeExpr || !Size) 8926577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, 8927577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange, 8928577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor getDerived().getBaseEntity()); 89291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 89301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Types[] = { 89311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, 89321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, 89331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty 8934577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor }; 8935577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const unsigned NumTypes = sizeof(Types) / sizeof(QualType); 8936577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType SizeType; 8937577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor for (unsigned I = 0; I != NumTypes; ++I) 8938577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { 8939577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SizeType = Types[I]; 8940577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor break; 8941577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 89421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 894301f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman // Note that we can return a VariableArrayType here in the case where 894401f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman // the element type was a dependent VariableArrayType. 894501f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman IntegerLiteral *ArraySize 894601f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType, 894701f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman /*FIXME*/BracketsRange.getBegin()); 894801f276dac946c0845f6eb3449ab253cfdba841a1Eli Friedman return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize, 8949577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange, 89501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getDerived().getBaseEntity()); 8951577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 89521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8953577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 89541eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 89551eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, 8956577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 8957577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt &Size, 895885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 895985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange) { 89601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, 896185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall IndexTypeQuals, BracketsRange); 8962577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8963577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8964577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 89651eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 89661eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, 8967577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 896885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 896985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange) { 89701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, 897185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall IndexTypeQuals, BracketsRange); 8972577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 89731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 8974577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 89751eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 89761eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, 8977577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 89789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 8979577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 8980577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 89811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 89829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SizeExpr, 8983577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange); 8984577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8985577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8986577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 89871eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 89881eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, 8989577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 89909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 8991577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 8992577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 89931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 89949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SizeExpr, 8995577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange); 8996577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 8997577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 8998577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 8999577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, 9000e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson unsigned NumElements, 9001e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::VectorKind VecKind) { 9002577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor // FIXME: semantic checking! 9003e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); 9004577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 90051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9006577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 9007577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, 9008577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumElements, 9009577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc) { 9010577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), 9011577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor NumElements, true); 9012577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IntegerLiteral *VectorSize 90139996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, 90149996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis AttributeLoc); 90159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); 9016577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 90171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9018577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 90191eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 90201eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, 90219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 9022577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc) { 90239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); 9024577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 90251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9026577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 9027577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, 90281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType *ParamTypes, 9029577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumParamTypes, 90301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool Variadic, 9031eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith bool HasTrailingReturn, 9032fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman unsigned Quals, 9033c938c1668b4fd12af154e965dd935a89e4801a70Douglas Gregor RefQualifierKind RefQualifier, 9034fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman const FunctionType::ExtInfo &Info) { 90351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, 9036eefb3d5b49c844347f212073a7e975b8118fe8e9Richard Smith HasTrailingReturn, Quals, RefQualifier, 9037577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor getDerived().getBaseLocation(), 9038fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman getDerived().getBaseEntity(), 9039fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman Info); 9040577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 90411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9042577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 9043a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { 9044a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return SemaRef.Context.getFunctionNoProtoType(T); 9045a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 9046a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 9047a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 9048ed97649e9574b9d854fa4d6109c9333ae0993554John McCallQualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { 9049ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(D && "no decl found"); 9050ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (D->isInvalidDecl()) return QualType(); 9051ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 905292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // FIXME: Doesn't account for ObjCInterfaceDecl! 9053ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TypeDecl *Ty; 9054ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (isa<UsingDecl>(D)) { 9055ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UsingDecl *Using = cast<UsingDecl>(D); 9056ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(Using->isTypeName() && 9057ed97649e9574b9d854fa4d6109c9333ae0993554John McCall "UnresolvedUsingTypenameDecl transformed to non-typename using"); 9058ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 9059ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // A valid resolved using typename decl points to exactly one type decl. 9060ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(++Using->shadow_begin() == Using->shadow_end()); 9061ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); 9062c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 9063ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } else { 9064ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(isa<UnresolvedUsingTypenameDecl>(D) && 9065ed97649e9574b9d854fa4d6109c9333ae0993554John McCall "UnresolvedUsingTypenameDecl transformed to non-using decl"); 9066ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Ty = cast<UnresolvedUsingTypenameDecl>(D); 9067ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 9068ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 9069ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return SemaRef.Context.getTypeDeclType(Ty); 9070ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 9071ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 9072ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> 90732a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, 90742a984cad5ac3fdceeff2bd99daa7b90979313475John McCall SourceLocation Loc) { 90752a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return SemaRef.BuildTypeofExprType(E, Loc); 9076577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 9077577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 9078577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 9079577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { 9080577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeOfType(Underlying); 9081577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 9082577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 9083577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 90842a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, 90852a984cad5ac3fdceeff2bd99daa7b90979313475John McCall SourceLocation Loc) { 90862a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return SemaRef.BuildDecltypeType(E, Loc); 9087577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 9088577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 9089577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 9090ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean HuntQualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType, 9091ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt UnaryTransformType::UTTKind UKind, 9092ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt SourceLocation Loc) { 9093ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc); 9094ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt} 9095ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunt 9096ca63c200346c0ca9e00194ec6e34a5a7b0ed9321Sean Hunttemplate<typename Derived> 9097577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTemplateSpecializationType( 9098833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateName Template, 9099833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation TemplateNameLoc, 910067714230a191bc3c01f33378f34f34ef377991a6Douglas Gregor TemplateArgumentListInfo &TemplateArgs) { 9101d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); 9102577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 91031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9104dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived> 9105b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli FriedmanQualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType, 9106b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman SourceLocation KWLoc) { 9107b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman return SemaRef.BuildAtomicType(ValueType, KWLoc); 9108b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman} 9109b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedman 9110b001de7458d17c17e6d8b8034c7cfcefd3b70c00Eli Friedmantemplate<typename Derived> 91111eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 9112fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 9113d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor bool TemplateKW, 9114d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TemplateDecl *Template) { 9115fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW, 9116d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor Template); 9117d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor} 9118d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor 9119d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived> 91201eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 9121fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 9122fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor const IdentifierInfo &Name, 9123fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 912443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 912543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope) { 9126fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor UnqualifiedId TemplateName; 9127fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor TemplateName.setIdentifier(&Name, NameLoc); 9128d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Sema::TemplateTy Template; 9129e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. 9130d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor getSema().ActOnDependentTemplateName(/*Scope=*/0, 9131e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, TemplateKWLoc, TemplateName, 9132b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType::make(ObjectType), 9133d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor /*EnteringContext=*/false, 9134d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Template); 913543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return Template.get(); 9136d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor} 91371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9138b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 9139ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTemplateName 9140fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas GregorTreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS, 9141ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor OverloadedOperatorKind Operator, 9142fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor SourceLocation NameLoc, 9143ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor QualType ObjectType) { 9144ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId Name; 9145fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor // FIXME: Bogus location information. 9146e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc }; 9147fd4ffebd8e8e77346e70dfbc2d72dd673ebd7c6dDouglas Gregor Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations); 9148e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. 9149d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Sema::TemplateTy Template; 9150d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor getSema().ActOnDependentTemplateName(/*Scope=*/0, 9151e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, TemplateKWLoc, Name, 9152b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType::make(ObjectType), 9153d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor /*EnteringContext=*/false, 9154d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Template); 9155d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor return Template.template getAsVal<TemplateName>(); 9156ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor} 9157c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 9158ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregortemplate<typename Derived> 915960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 9160b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, 9161b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 91629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *OrigCallee, 91639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *First, 91649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Second) { 91659ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Callee = OrigCallee->IgnoreParenCasts(); 91669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); 91671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9168b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Determine whether this should be a builtin operation. 9169f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl if (Op == OO_Subscript) { 91709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType() && 91719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall !Second->getType()->isOverloadableType()) 91729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().CreateBuiltinArraySubscriptExpr(First, 91739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Callee->getLocStart(), 91749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Second, OpLoc); 91751a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman } else if (Op == OO_Arrow) { 91761a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman // -> is never a builtin operation. 91779ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); 91789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall } else if (Second == 0 || isPostIncDec) { 91799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType()) { 9180b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // The argument is not of overloadable type, so try to create a 9181b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // built-in unary operation. 91822de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc 9183b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); 91841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 91859ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); 9186b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 9187b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } else { 91889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType() && 91899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall !Second->getType()->isOverloadableType()) { 9190b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Neither of the arguments is an overloadable type, so try to 9191b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // create a built-in binary operation. 91922de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 919360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 91949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); 9195b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 9196f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 91971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9198b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return move(Result); 9199b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 9200b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 92011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 92021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Compute the transformed set of functions (and function templates) to be 9203b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // used during overload resolution. 92046e26689f5d513e24ad7783a4493201930fdeccc0John McCall UnresolvedSet<16> Functions; 92051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 92069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { 9207ba13543329afac4a0d01304ec2ec4924d99306a6John McCall assert(ULE->requiresADL()); 9208ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 9209ba13543329afac4a0d01304ec2ec4924d99306a6John McCall // FIXME: Do we have to check 9210ba13543329afac4a0d01304ec2ec4924d99306a6John McCall // IsAcceptableNonMemberOperatorCandidate for each of these? 92116e26689f5d513e24ad7783a4493201930fdeccc0John McCall Functions.append(ULE->decls_begin(), ULE->decls_end()); 9212ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } else { 92139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl()); 9214ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } 92151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9216b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Add any functions found via argument-dependent lookup. 92179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Args[2] = { First, Second }; 92189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall unsigned NumArgs = 1 + (Second != 0); 92191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9220b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Create the overloaded operator invocation for unary operators. 9221b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (NumArgs == 1 || isPostIncDec) { 92222de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc 9223b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); 92249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); 9225b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 92261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 92275b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor if (Op == OO_Subscript) { 92285b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor SourceLocation LBrace; 92295b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor SourceLocation RBrace; 92305b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor 92315b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) { 92325b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor DeclarationNameLoc &NameLoc = DRE->getNameInfo().getInfo(); 92335b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor LBrace = SourceLocation::getFromRawEncoding( 92345b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor NameLoc.CXXOperatorName.BeginOpNameLoc); 92355b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor RBrace = SourceLocation::getFromRawEncoding( 92365b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor NameLoc.CXXOperatorName.EndOpNameLoc); 92375b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor } else { 92385b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor LBrace = Callee->getLocStart(); 92395b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor RBrace = OpLoc; 92405b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor } 92415b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor 92425b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace, 92435b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor First, Second); 92445b8968cc599eb6100bb73ae87be9d6cd2577ac9eDouglas Gregor } 9245f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl 9246b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Create the overloaded operator invocation for binary operators. 92472de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 924860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 9249b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); 9250b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 9251f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 92521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 92531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return move(Result); 9254b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 92551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 925626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregortemplate<typename Derived> 925760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 92589ae2f076ca5ab1feb3ba95629099ec2319833701John McCallTreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, 925926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SourceLocation OperatorLoc, 926026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor bool isArrow, 9261f3db29fff6a583ecda823cf909ab7737d8d30129Douglas Gregor CXXScopeSpec &SS, 926226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor TypeSourceInfo *ScopeType, 926326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SourceLocation CCLoc, 9264fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SourceLocation TildeLoc, 9265a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed) { 92669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall QualType BaseType = Base->getType(); 92679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (Base->isTypeDependent() || Destroyed.getIdentifier() || 926826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor (!isArrow && !BaseType->getAs<RecordType>()) || 9269c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt (isArrow && BaseType->getAs<PointerType>() && 9270bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif !BaseType->getAs<PointerType>()->getPointeeType() 9271bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif ->template getAs<RecordType>())){ 927226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor // This pseudo-destructor expression is still a pseudo-destructor. 92739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, 927426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor isArrow? tok::arrow : tok::period, 9275fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SS, ScopeType, CCLoc, TildeLoc, 9276a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed, 927726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /*FIXME?*/true); 927826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor } 92792577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 9280a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); 92812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( 92822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SemaRef.Context.getCanonicalType(DestroyedType->getType()))); 92832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); 92842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.setNamedTypeInfo(DestroyedType); 92852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 92866314db9d5918939ad8ec88cd9c3f42a33a67c2b6Richard Smith // The scope type is now known to be a valid nested name specifier 92876314db9d5918939ad8ec88cd9c3f42a33a67c2b6Richard Smith // component. Tack it on to the end of the nested name specifier. 92886314db9d5918939ad8ec88cd9c3f42a33a67c2b6Richard Smith if (ScopeType) 92896314db9d5918939ad8ec88cd9c3f42a33a67c2b6Richard Smith SS.Extend(SemaRef.Context, SourceLocation(), 92906314db9d5918939ad8ec88cd9c3f42a33a67c2b6Richard Smith ScopeType->getTypeLoc(), CCLoc); 92912577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 9292e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller. 92939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, BaseType, 929426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor OperatorLoc, isArrow, 9295e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara SS, TemplateKWLoc, 9296e4b92761b43ced611c417ae478568610f1ad7b1eAbramo Bagnara /*FIXME: FirstQualifier*/ 0, 92972577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 929826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /*TemplateArgs*/ 0); 929926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor} 930026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor 9301577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} // end namespace clang 9302577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 9303577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H 9304