TreeTransform.h revision 711c52bb20d0c69063b52a99826fb7d2835501f1
1a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall//===------- 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. 7577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===/ 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// 12577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===/ 13577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#ifndef LLVM_CLANG_SEMA_TREETRANSFORM_H 14577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#define LLVM_CLANG_SEMA_TREETRANSFORM_H 15577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 162d88708cbe4e4ec5e04e4acb6bd7f5be68557379John McCall#include "clang/Sema/SemaInternal.h" 17e737f5041a36d0befb39ffeed8d50ba15916d3daDouglas Gregor#include "clang/Sema/Lookup.h" 188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor#include "clang/Sema/ParsedTemplate.h" 19dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor#include "clang/Sema/SemaDiagnostic.h" 20781472fe99a120098c631b0cbe33c89f8cef5e70John McCall#include "clang/Sema/ScopeInfo.h" 21c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor#include "clang/AST/Decl.h" 227cd088e519d7e6caa4c4c12db52e0e4ae35d25c2John McCall#include "clang/AST/DeclObjC.h" 23657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor#include "clang/AST/Expr.h" 24b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/AST/ExprCXX.h" 25b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/AST/ExprObjC.h" 2643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/Stmt.h" 2743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/StmtCXX.h" 2843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#include "clang/AST/StmtObjC.h" 2919510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Ownership.h" 3019510856727e0e14a3696b2a72c35163bff2a71fJohn McCall#include "clang/Sema/Designator.h" 31b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#include "clang/Lex/Preprocessor.h" 32a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "llvm/Support/ErrorHandling.h" 337e44e3fcd75147f229f42e6912898ce62d6b4d08Douglas Gregor#include "TypeLocBuilder.h" 34577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#include <algorithm> 35577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 36577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregornamespace clang { 37781472fe99a120098c631b0cbe33c89f8cef5e70John McCallusing namespace sema; 381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 39577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \brief A semantic tree transformation that allows one to transform one 40577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// abstract syntax tree into another. 41577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// A new tree transformation is defined by creating a new subclass \c X of 431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// \c TreeTransform<X> and then overriding certain operations to provide 441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// behavior specific to that transformation. For example, template 45577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// instantiation is implemented as a tree transformation where the 46577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation of TemplateTypeParmType nodes involves substituting the 47577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template arguments for their corresponding template parameters; a similar 48577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// transformation is performed for non-type template parameters and 49577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// template template parameters. 50577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 51577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// This tree-transformation template uses static polymorphism to allow 521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// subclasses to customize any of its operations. Thus, a subclass can 53577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// override any of the transformation or rebuild operators by providing an 54577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operation with the same signature as the default implementation. The 55577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// overridding function should not be virtual. 56577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 57577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// Semantic tree transformations are split into two stages, either of which 58577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// can be replaced by a subclass. The "transform" step transforms an AST node 59577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// or the parts of an AST node using the various transformation functions, 60577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// then passes the pieces on to the "rebuild" step, which constructs a new AST 61577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// node of the appropriate kind from the pieces. The default transformation 62577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// routines recursively transform the operands to composite AST nodes (e.g., 63577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// the pointee type of a PointerType node) and, if any of those operand nodes 64577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// were changed by the transformation, invokes the rebuild operation to create 65577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// a new AST node. 66577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// Subclasses can customize the transformation at various levels. The 68670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor/// most coarse-grained transformations involve replacing TransformType(), 69577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifier(), 70577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// TransformTemplateName(), or TransformTemplateArgument() with entirely 71577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// new implementations. 72577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 73577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// For more fine-grained transformations, subclasses can replace any of the 74577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// \c TransformXXX functions (where XXX is the name of an AST node, e.g., 7543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor/// PointerType, StmtExpr) to alter the transformation. As mentioned previously, 76577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// replacing TransformTemplateTypeParmType() allows template instantiation 771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to substitute template arguments for their corresponding template 78577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// parameters. Additionally, subclasses can override the \c RebuildXXX 79577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// functions to control how AST nodes are rebuilt when their operands change. 80577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// By default, \c TreeTransform will invoke semantic analysis to rebuild 81577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// AST nodes. However, certain other tree transformations (e.g, cloning) may 82577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// be able to use more efficient rebuild steps. 83577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// 84577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// There are a handful of other functions that can be overridden, allowing one 851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump/// to avoid traversing nodes that don't need any transformation 86577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their 87577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// operands have not changed (\c AlwaysRebuild()), and customize the 88577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// default locations and entity names used for type-checking 89577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor/// (\c getBaseLocation(), \c getBaseEntity()). 90577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 91577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorclass TreeTransform { 92577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregorprotected: 93577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Sema &SemaRef; 948491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumppublic: 96577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Initializes a new tree transformer. 97b99268b3083c882103bd1bd08bdcc9a76a2b4795Douglas Gregor TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { } 981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 99577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Retrieves a reference to the derived class. 100577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Derived &getDerived() { return static_cast<Derived&>(*this); } 101577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 102577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Retrieves a reference to the derived class. 1031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const Derived &getDerived() const { 1041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return static_cast<const Derived&>(*this); 105577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 106577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 10760d7b3a319d84d688752be3870615ac0f111fb16John McCall static inline ExprResult Owned(Expr *E) { return E; } 10860d7b3a319d84d688752be3870615ac0f111fb16John McCall static inline StmtResult Owned(Stmt *S) { return S; } 1099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall 110577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Retrieves a reference to the semantic analysis object used for 111577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// this tree transform. 112577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Sema &getSema() const { return SemaRef; } 1131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 114577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Whether the transformation should always rebuild AST nodes, even 115577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// if none of the children have changed. 116577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 117577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this function to specify when the transformation 118577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// should rebuild all AST nodes. 119577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor bool AlwaysRebuild() { return false; } 1201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 121577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Returns the location of the entity being transformed, if that 122577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// information was not available elsewhere in the AST. 123577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 1241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, returns no source-location information. Subclasses can 125577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// provide an alternative implementation that provides better location 126577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// information. 127577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation getBaseLocation() { return SourceLocation(); } 1281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 129577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Returns the name of the entity being transformed, if that 130577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// information was not available elsewhere in the AST. 131577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 132577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, returns an empty name. Subclasses can provide an alternative 133577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// implementation with a more precise name. 134577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor DeclarationName getBaseEntity() { return DeclarationName(); } 135577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 136b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Sets the "base" location and entity when that 137b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// information is known based on another transformation. 138b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 139b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, the source location and entity are ignored. Subclasses can 140b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// override this function to provide a customized implementation. 141b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor void setBase(SourceLocation Loc, DeclarationName Entity) { } 1421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 143b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief RAII object that temporarily sets the base location and entity 144b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// used for reporting diagnostics in types. 145b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor class TemporaryBase { 146b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TreeTransform &Self; 147b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OldLocation; 148b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor DeclarationName OldEntity; 1491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 150b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor public: 151b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TemporaryBase(TreeTransform &Self, SourceLocation Location, 1521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump DeclarationName Entity) : Self(Self) { 153b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor OldLocation = Self.getDerived().getBaseLocation(); 154b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor OldEntity = Self.getDerived().getBaseEntity(); 155b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Self.getDerived().setBase(Location, Entity); 156b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 158b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ~TemporaryBase() { 159b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Self.getDerived().setBase(OldLocation, OldEntity); 160b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 161b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor }; 1621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Determine whether the given type \p T has already been 164577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// transformed. 165577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 166577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses can provide an alternative implementation of this routine 1671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// to short-circuit evaluation when it is known that a given type will 168577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// not change. For example, template instantiation need not traverse 169577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// non-dependent types. 170577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor bool AlreadyTransformed(QualType T) { 171577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return T.isNull(); 172577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 173577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 1746eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// \brief Determine whether the given call argument should be dropped, e.g., 1756eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// because it is a default argument. 1766eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// 1776eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// Subclasses can provide an alternative implementation of this routine to 1786eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// determine which kinds of call arguments get dropped. By default, 1796eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor /// CXXDefaultArgument nodes are dropped (prior to transformation). 1806eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor bool DropCallArgument(Expr *E) { 1816eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return E->isDefaultArgument(); 1826eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor } 183c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1848491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \brief Determine whether we should expand a pack expansion with the 1858491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// given set of parameter packs into separate arguments by repeatedly 1868491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// transforming the pattern. 1878491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 188b99268b3083c882103bd1bd08bdcc9a76a2b4795Douglas Gregor /// By default, the transformer never tries to expand pack expansions. 1898491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// Subclasses can override this routine to provide different behavior. 1908491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 1918491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param EllipsisLoc The location of the ellipsis that identifies the 1928491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// pack expansion. 1938491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 1948491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param PatternRange The source range that covers the entire pattern of 1958491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// the pack expansion. 1968491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 1978491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param Unexpanded The set of unexpanded parameter packs within the 1988491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// pattern. 1998491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2008491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param NumUnexpanded The number of unexpanded parameter packs in 2018491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \p Unexpanded. 2028491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2038491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param ShouldExpand Will be set to \c true if the transformer should 2048491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// expand the corresponding pack expansions into separate arguments. When 2058491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// set, \c NumExpansions must also be set. 2068491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2078491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \param NumExpansions The number of separate arguments that will be in 2088491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// the expanded form of the corresponding pack expansion. Must be set when 2098491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \c ShouldExpand is \c true. 2108491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 2118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \returns true if an error occurred (e.g., because the parameter packs 2128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// are to be instantiated with arguments of different lengths), false 2138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions) 2148491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// must be set. 2158491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor bool TryExpandParameterPacks(SourceLocation EllipsisLoc, 2168491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor SourceRange PatternRange, 2178491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor const UnexpandedParameterPack *Unexpanded, 2188491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor unsigned NumUnexpanded, 2198491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor bool &ShouldExpand, 2208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor unsigned &NumExpansions) { 2218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ShouldExpand = false; 2228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return false; 2238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 2248491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 225577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transforms the given type into another type. 226577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 227a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// By default, this routine transforms a type by creating a 228a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall /// TypeSourceInfo for it and delegating to the appropriate 229a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// function. This is expensive, but we don't mind, because 230a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// this method is deprecated anyway; all users should be 231a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall /// switched to storing TypeSourceInfos. 232577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 233577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \returns the transformed type. 23443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType TransformType(QualType T); 2351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 236a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// \brief Transforms the given type-with-location into a new 237a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// type-with-location. 238a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// 239a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// By default, this routine transforms a type by delegating to the 240a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// appropriate TransformXXXType to build a new type. Subclasses 241a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// may override this function (to take over all type 242a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// transformations) or some set of the TransformXXXType functions 243a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// to alter the transformation. 24443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeSourceInfo *TransformType(TypeSourceInfo *DI); 245a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 246a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// \brief Transform the given type-with-location into a new 247a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// type, collecting location information in the given builder 248a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// as necessary. 249577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 25043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL); 2511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 252657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor /// \brief Transform the given statement. 253577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 2541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, this routine transforms a statement by delegating to the 25543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// appropriate TransformXXXStmt function to transform a specific kind of 25643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// statement or the TransformExpr() function to transform an expression. 25743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this function to transform statements using some 25843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// other mechanism. 25943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 26043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \returns the transformed statement. 26160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TransformStmt(Stmt *S); 2621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 263657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor /// \brief Transform the given expression. 264657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor /// 265b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, this routine transforms an expression by delegating to the 266b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// appropriate TransformXXXExpr function to build a new expression. 267b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this function to transform expressions using some 268b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// other mechanism. 269b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 270b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \returns the transformed expression. 27160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult TransformExpr(Expr *E); 2721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 273aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \brief Transform the given list of expressions. 274aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 275aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// This routine transforms a list of expressions by invoking 276aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \c TransformExpr() for each subexpression. However, it also provides 277aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// support for variadic templates by expanding any pack expansions (if the 278aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// derived class permits such expansion) along the way. When pack expansions 279aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// are present, the number of outputs may not equal the number of inputs. 280aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 281aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param Inputs The set of expressions to be transformed. 282aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 283aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param NumInputs The number of expressions in \c Inputs. 284aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 285aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param IsCall If \c true, then this transform is being performed on 286aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// function-call arguments, and any arguments that should be dropped, will 287aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// be. 288aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 289aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param Outputs The transformed input expressions will be added to this 290aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// vector. 291aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 292aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \param ArgChanged If non-NULL, will be set \c true if any argument changed 293aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// due to transformation. 294aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// 295aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor /// \returns true if an error occurred, false otherwise. 296aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall, 297aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor llvm::SmallVectorImpl<Expr *> &Outputs, 298aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool *ArgChanged = 0); 299aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 300577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transform the given declaration, which is referenced from a type 301577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// or expression. 302577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 303dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// By default, acts as the identity function on declarations. Subclasses 304dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// may override this function to provide alternate behavior. 3057c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor Decl *TransformDecl(SourceLocation Loc, Decl *D) { return D; } 30643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 30743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Transform the definition of the given declaration. 30843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 3091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, invokes TransformDecl() to transform the declaration. 31043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this function to provide alternate behavior. 311c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Decl *TransformDefinition(SourceLocation Loc, Decl *D) { 312c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getDerived().TransformDecl(Loc, D); 3137c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor } 3141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3156cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// \brief Transform the given declaration, which was the first part of a 3166cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// nested-name-specifier in a member access expression. 3176cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// 318c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /// This specific declaration transformation only applies to the first 3196cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// identifier in a nested-name-specifier of a member access expression, e.g., 3206cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// the \c T in \c x->T::member 3216cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// 3226cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// By default, invokes TransformDecl() to transform the declaration. 3236cd219879ffce00920189ec1dcea927a42602961Douglas Gregor /// Subclasses may override this function to provide alternate behavior. 324c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) { 325c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D)); 3266cd219879ffce00920189ec1dcea927a42602961Douglas Gregor } 327c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 328577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transform the given nested-name-specifier. 329577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 3301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, transforms all of the types and declarations within the 331dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// nested-name-specifier. Subclasses may override this function to provide 332dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// alternate behavior. 333577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor NestedNameSpecifier *TransformNestedNameSpecifier(NestedNameSpecifier *NNS, 334a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor SourceRange Range, 335c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor QualType ObjectType = QualType(), 336c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor NamedDecl *FirstQualifierInScope = 0); 3371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// \brief Transform the given declaration name. 33981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// 34081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// By default, transforms the types of conversion function, constructor, 34181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// and destructor names and then (if needed) rebuilds the declaration name. 34281499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// Identifiers and selectors are returned unmodified. Sublcasses may 34381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor /// override this function to provide alternate behavior. 3442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo 34543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo); 3461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 347577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transform the given template name. 3481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 349d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// By default, transforms the template name by transforming the declarations 3501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// and nested-name-specifiers that occur within the template name. 351d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// Subclasses may override this function to provide alternate behavior. 3523b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor TemplateName TransformTemplateName(TemplateName Name, 35343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType = QualType(), 35443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope = 0); 3551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 356577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Transform the given template argument. 357577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 3581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, this operation transforms the type, expression, or 3591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// declaration stored within the template argument and constructs a 360670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor /// new template argument from the transformed result. Subclasses may 361670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor /// override this function to provide alternate behavior. 362833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// 363833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// Returns true if there was an error. 364833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall bool TransformTemplateArgument(const TemplateArgumentLoc &Input, 365833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &Output); 366833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 367fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// \brief Transform the given set of template arguments. 368fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 369fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// By default, this operation transforms all of the template arguments 370fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// in the input set using \c TransformTemplateArgument(), and appends 371fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// the transformed arguments to the output list. 372fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 3737ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// Note that this overload of \c TransformTemplateArguments() is merely 3747ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// a convenience function. Subclasses that wish to override this behavior 3757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// should override the iterator-based member template version. 3767ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// 377fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// \param Inputs The set of template arguments to be transformed. 378fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 379fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// \param NumInputs The number of template arguments in \p Inputs. 380fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 381fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// \param Outputs The set of transformed template arguments output by this 382fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// routine. 383fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// 384fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor /// Returns true if an error occurred. 385fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs, 386fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor unsigned NumInputs, 3877ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentListInfo &Outputs) { 3887ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs); 3897ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 3907f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 3917f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// \brief Transform the given set of template arguments. 3927f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// 3937f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// By default, this operation transforms all of the template arguments 3947f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// in the input set using \c TransformTemplateArgument(), and appends 3957f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// the transformed arguments to the output list. 3967f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// 3977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \param First An iterator to the first template argument. 3987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// 3997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \param Last An iterator one step past the last template argument. 4007f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// 4017f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// \param Outputs The set of transformed template arguments output by this 4027f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// routine. 4037f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// 4047f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor /// Returns true if an error occurred. 4057ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor template<typename InputIterator> 4067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor bool TransformTemplateArguments(InputIterator First, 4077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Last, 4087ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentListInfo &Outputs); 4097f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 410833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument. 411833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall void InventTemplateArgumentLoc(const TemplateArgument &Arg, 412833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &ArgLoc); 413833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 414a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall /// \brief Fakes up a TypeSourceInfo for a type. 415a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *InventTypeSourceInfo(QualType T) { 416a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall return SemaRef.Context.getTrivialTypeSourceInfo(T, 417833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall getDerived().getBaseLocation()); 418833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 4191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 420a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT) 421a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT) \ 42243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T); 423a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def" 424577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 42543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType 42643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TransformTemplateSpecializationType(TypeLocBuilder &TLB, 42743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateSpecializationTypeLoc TL, 42843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template); 42943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 43043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType 43143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 43243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentTemplateSpecializationTypeLoc TL, 43343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NestedNameSpecifier *Prefix); 43443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 43521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// \brief Transforms the parameters of a function type into the 43621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// given vectors. 43721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// 43821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// The result vectors should be kept in sync; null entries in the 43921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// variables vector are acceptable. 44021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// 44121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// Return true on error. 44221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall bool TransformFunctionTypeParams(FunctionProtoTypeLoc TL, 44321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall llvm::SmallVectorImpl<QualType> &PTypes, 44421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall llvm::SmallVectorImpl<ParmVarDecl*> &PVars); 44521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 44621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// \brief Transforms a single function-type parameter. Return null 44721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /// on error. 44821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm); 44921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 45043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL); 451833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 45260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr); 45360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E); 4541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 45543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) \ 45660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Transform##Node(Node *S); 457b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent) \ 45860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Transform##Node(Node *E); 4597381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 4604bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 4611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 462577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new pointer type given its pointee type. 463577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 464577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the pointer type. 465577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 46685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil); 467577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 468577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new block pointer type given its pointee type. 469577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 4701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, performs semantic analysis when building the block pointer 471577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// type. Subclasses may override this routine to provide different behavior. 47285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil); 473577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 47485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// \brief Build a new reference type given the type it references. 475577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 47685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// By default, performs semantic analysis when building the 47785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// reference type. Subclasses may override this routine to provide 47885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// different behavior. 479577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 48085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// \param LValue whether the type was written with an lvalue sigil 48185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall /// or an rvalue sigil. 48285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildReferenceType(QualType ReferentType, 48385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall bool LValue, 48485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil); 4851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 486577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new member pointer type given the pointee type and the 487577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// class type it refers into. 488577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 489577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the member pointer 490577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// type. Subclasses may override this routine to provide different behavior. 49185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType, 49285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil); 4931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 494577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new array type given the element type, size 495577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// modifier, size of the array (if known), size expression, and index type 496577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// qualifiers. 497577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 498577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 499577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 5001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// Also by default, all of the other Rebuild*Array 501577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildArrayType(QualType ElementType, 502577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 503577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt *Size, 504577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Expr *SizeExpr, 505577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 506577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange); 5071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 508577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new constant array type given the element type, size 509577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// modifier, (known) size of the array, and index type qualifiers. 510577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 511577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 512577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 5131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildConstantArrayType(QualType ElementType, 514577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 515577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt &Size, 51685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 51785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange); 518577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 519577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new incomplete array type given the element type, size 520577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// modifier, and index type qualifiers. 521577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 522577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 523577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 5241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildIncompleteArrayType(QualType ElementType, 525577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 52685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 52785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange); 528577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 5291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new variable-length array type given the element type, 530577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// size modifier, size expression, and index type qualifiers. 531577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 532577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 533577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 5341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildVariableArrayType(QualType ElementType, 535577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 5369ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 537577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 538577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange); 539577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 5401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new dependent-sized array type given the element type, 541577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// size modifier, size expression, and index type qualifiers. 542577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 543577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the array type. 544577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 5451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildDependentSizedArrayType(QualType ElementType, 546577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 5479ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 548577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 549577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange); 550577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 551577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new vector type given the element type and 552577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// number of elements. 553577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 554577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the vector type. 555577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 55682287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson QualType RebuildVectorType(QualType ElementType, unsigned NumElements, 557e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::VectorKind VecKind); 5581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 559577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new extended vector type given the element type and 560577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// number of elements. 561577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 562577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the vector type. 563577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 564577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements, 565577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc); 5661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new potentially dependently-sized extended vector type 568577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// given the element type and number of elements. 569577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 570577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the vector type. 571577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 5721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType RebuildDependentSizedExtVectorType(QualType ElementType, 5739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 574577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc); 5751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 576577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new function type. 577577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 578577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the function type. 579577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 580577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildFunctionProtoType(QualType T, 5811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType *ParamTypes, 582577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumParamTypes, 583fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman bool Variadic, unsigned Quals, 584fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman const FunctionType::ExtInfo &Info); 5851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 586a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /// \brief Build a new unprototyped function type. 587a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType RebuildFunctionNoProtoType(QualType ResultType); 588a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 589ed97649e9574b9d854fa4d6109c9333ae0993554John McCall /// \brief Rebuild an unresolved typename type, given the decl that 590ed97649e9574b9d854fa4d6109c9333ae0993554John McCall /// the UnresolvedUsingTypenameDecl was transformed to. 591ed97649e9574b9d854fa4d6109c9333ae0993554John McCall QualType RebuildUnresolvedUsingType(Decl *D); 592ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 593577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new typedef type. 594577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildTypedefType(TypedefDecl *Typedef) { 595577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeDeclType(Typedef); 596577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 597577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 598577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new class/struct/union type. 599577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildRecordType(RecordDecl *Record) { 600577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeDeclType(Record); 601577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 602577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 603577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new Enum type. 604577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildEnumType(EnumDecl *Enum) { 605577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeDeclType(Enum); 606577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 6077da2431c23ef1ee8acb114e39692246e1801afc2John McCall 6081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new typeof(expr) type. 609577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 610577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the typeof type. 611577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6122a984cad5ac3fdceeff2bd99daa7b90979313475John McCall QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc); 613577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 6141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new typeof(type) type. 615577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 616577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, builds a new TypeOfType with the given underlying type. 617577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildTypeOfType(QualType Underlying); 618577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 6191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new C++0x decltype type. 620577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 621577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the decltype type. 622577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// Subclasses may override this routine to provide different behavior. 6232a984cad5ac3fdceeff2bd99daa7b90979313475John McCall QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc); 6241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 625577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new template specialization type. 626577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 627577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the template 628577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// specialization type. Subclasses may override this routine to provide 629577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// different behavior. 630577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType RebuildTemplateSpecializationType(TemplateName Template, 631833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation TemplateLoc, 632d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo &Args); 6331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 634075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// \brief Build a new parenthesized type. 635075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// 636075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// By default, builds a new ParenType type from the inner type. 637075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara /// Subclasses may override this routine to provide different behavior. 638075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType RebuildParenType(QualType InnerType) { 639075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return SemaRef.Context.getParenType(InnerType); 640075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 641075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 642577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new qualified name type. 643577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 644465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// By default, builds a new ElaboratedType type from the keyword, 645465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// the nested-name-specifier and the named type. 646465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara /// Subclasses may override this routine to provide different behavior. 64721e413fe6305a198564d436ac515497716c47844John McCall QualType RebuildElaboratedType(SourceLocation KeywordLoc, 64821e413fe6305a198564d436ac515497716c47844John McCall ElaboratedTypeKeyword Keyword, 649465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara NestedNameSpecifier *NNS, QualType Named) { 650465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return SemaRef.Context.getElaboratedType(Keyword, NNS, Named); 6511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 652577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 653577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new typename type that refers to a template-id. 654577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 655e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// By default, builds a new DependentNameType type from the 656e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// nested-name-specifier and the given type. Subclasses may override 657e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// this routine to provide different behavior. 65833500955d731c73717af52088b7fc0e7a85681e7John McCall QualType RebuildDependentTemplateSpecializationType( 65933500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeKeyword Keyword, 6601efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor NestedNameSpecifier *Qualifier, 6611efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor SourceRange QualifierRange, 66233500955d731c73717af52088b7fc0e7a85681e7John McCall const IdentifierInfo *Name, 66333500955d731c73717af52088b7fc0e7a85681e7John McCall SourceLocation NameLoc, 66433500955d731c73717af52088b7fc0e7a85681e7John McCall const TemplateArgumentListInfo &Args) { 66533500955d731c73717af52088b7fc0e7a85681e7John McCall // Rebuild the template name. 66633500955d731c73717af52088b7fc0e7a85681e7John McCall // TODO: avoid TemplateName abstraction 66733500955d731c73717af52088b7fc0e7a85681e7John McCall TemplateName InstName = 6681efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor getDerived().RebuildTemplateName(Qualifier, QualifierRange, *Name, 66943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType(), 0); 67033500955d731c73717af52088b7fc0e7a85681e7John McCall 67196fb42ea29253cf2b34848dfdb3e40ef14ca8ebcDouglas Gregor if (InstName.isNull()) 67296fb42ea29253cf2b34848dfdb3e40ef14ca8ebcDouglas Gregor return QualType(); 67396fb42ea29253cf2b34848dfdb3e40ef14ca8ebcDouglas Gregor 67433500955d731c73717af52088b7fc0e7a85681e7John McCall // If it's still dependent, make a dependent specialization. 67533500955d731c73717af52088b7fc0e7a85681e7John McCall if (InstName.getAsDependentTemplateName()) 67633500955d731c73717af52088b7fc0e7a85681e7John McCall return SemaRef.Context.getDependentTemplateSpecializationType( 6771efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor Keyword, Qualifier, Name, Args); 67833500955d731c73717af52088b7fc0e7a85681e7John McCall 67933500955d731c73717af52088b7fc0e7a85681e7John McCall // Otherwise, make an elaborated type wrapping a non-dependent 68033500955d731c73717af52088b7fc0e7a85681e7John McCall // specialization. 68133500955d731c73717af52088b7fc0e7a85681e7John McCall QualType T = 68233500955d731c73717af52088b7fc0e7a85681e7John McCall getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args); 68333500955d731c73717af52088b7fc0e7a85681e7John McCall if (T.isNull()) return QualType(); 684465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 68522f638a58ed05579c51ee6a35a1d16a7c2157f90Abramo Bagnara // NOTE: NNS is already recorded in template specialization type T. 68622f638a58ed05579c51ee6a35a1d16a7c2157f90Abramo Bagnara return SemaRef.Context.getElaboratedType(Keyword, /*NNS=*/0, T); 6871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 688577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 689577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// \brief Build a new typename type that refers to an identifier. 690577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// 691577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// By default, performs semantic analysis when building the typename type 692e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara /// (or elaborated type). Subclasses may override this routine to provide 693577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor /// different behavior. 694e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword, 6954a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor NestedNameSpecifier *NNS, 6964a2023f5014e82389d5980d307b89c545dbbac81Douglas Gregor const IdentifierInfo *Id, 697e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SourceLocation KeywordLoc, 698e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SourceRange NNSRange, 699e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SourceLocation IdLoc) { 7004033642464e8ba0982f88f34cffad808d247b393Douglas Gregor CXXScopeSpec SS; 7014033642464e8ba0982f88f34cffad808d247b393Douglas Gregor SS.setScopeRep(NNS); 702e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SS.setRange(NNSRange); 703e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara 7044033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (NNS->isDependent()) { 7054033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // If the name is still dependent, just build a new dependent name type. 7064033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (!SemaRef.computeDeclContext(SS)) 7074033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return SemaRef.Context.getDependentNameType(Keyword, NNS, Id); 7084033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 7094033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 710465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara if (Keyword == ETK_None || Keyword == ETK_Typename) 711e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara return SemaRef.CheckTypenameType(Keyword, NNS, *Id, 712e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara KeywordLoc, NNSRange, IdLoc); 713465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 714465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword); 715465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 716e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara // We had a dependent elaborated-type-specifier that has been transformed 7174033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // into a non-dependent elaborated-type-specifier. Find the tag we're 7184033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // referring to. 719e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName); 7204033642464e8ba0982f88f34cffad808d247b393Douglas Gregor DeclContext *DC = SemaRef.computeDeclContext(SS, false); 7214033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (!DC) 7224033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 7234033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 7245613876991c80a684595fe8de1f039296a0657ffJohn McCall if (SemaRef.RequireCompleteDeclContext(SS, DC)) 7255613876991c80a684595fe8de1f039296a0657ffJohn McCall return QualType(); 7265613876991c80a684595fe8de1f039296a0657ffJohn McCall 7274033642464e8ba0982f88f34cffad808d247b393Douglas Gregor TagDecl *Tag = 0; 7284033642464e8ba0982f88f34cffad808d247b393Douglas Gregor SemaRef.LookupQualifiedName(Result, DC); 7294033642464e8ba0982f88f34cffad808d247b393Douglas Gregor switch (Result.getResultKind()) { 7304033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::NotFound: 7314033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::NotFoundInCurrentInstantiation: 7324033642464e8ba0982f88f34cffad808d247b393Douglas Gregor break; 733c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7344033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::Found: 7354033642464e8ba0982f88f34cffad808d247b393Douglas Gregor Tag = Result.getAsSingle<TagDecl>(); 7364033642464e8ba0982f88f34cffad808d247b393Douglas Gregor break; 737c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7384033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::FoundOverloaded: 7394033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::FoundUnresolvedValue: 7404033642464e8ba0982f88f34cffad808d247b393Douglas Gregor llvm_unreachable("Tag lookup cannot find non-tags"); 7414033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 742c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7434033642464e8ba0982f88f34cffad808d247b393Douglas Gregor case LookupResult::Ambiguous: 7444033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // Let the LookupResult structure handle ambiguities. 7454033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 7464033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 7474033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 7484033642464e8ba0982f88f34cffad808d247b393Douglas Gregor if (!Tag) { 7491eabb7d0c30f6a876b0fd03ad4656c096c26b8d0Douglas Gregor // FIXME: Would be nice to highlight just the source range. 750e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope) 7511eabb7d0c30f6a876b0fd03ad4656c096c26b8d0Douglas Gregor << Kind << Id << DC; 7524033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 7534033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 754465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 755e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, IdLoc, *Id)) { 756e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id; 7574033642464e8ba0982f88f34cffad808d247b393Douglas Gregor SemaRef.Diag(Tag->getLocation(), diag::note_previous_use); 7584033642464e8ba0982f88f34cffad808d247b393Douglas Gregor return QualType(); 7594033642464e8ba0982f88f34cffad808d247b393Douglas Gregor } 7604033642464e8ba0982f88f34cffad808d247b393Douglas Gregor 7614033642464e8ba0982f88f34cffad808d247b393Douglas Gregor // Build the elaborated-type-specifier type. 7624033642464e8ba0982f88f34cffad808d247b393Douglas Gregor QualType T = SemaRef.Context.getTypeDeclType(Tag); 763465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return SemaRef.Context.getElaboratedType(Keyword, NNS, T); 764dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor } 7651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 766dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// \brief Build a new nested-name-specifier given the prefix and an 767dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// identifier that names the next step in the nested-name-specifier. 768dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// 769dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// By default, performs semantic analysis when building the new 770dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// nested-name-specifier. Subclasses may override this routine to provide 771dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// different behavior. 772dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, 773dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor SourceRange Range, 774a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor IdentifierInfo &II, 775c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor QualType ObjectType, 776c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor NamedDecl *FirstQualifierInScope); 777dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor 778dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// \brief Build a new nested-name-specifier given the prefix and the 779dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// namespace named in the next step in the nested-name-specifier. 780dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// 781dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// By default, performs semantic analysis when building the new 782dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// nested-name-specifier. Subclasses may override this routine to provide 783dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// different behavior. 784dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, 785dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor SourceRange Range, 786dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor NamespaceDecl *NS); 787dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor 788dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// \brief Build a new nested-name-specifier given the prefix and the 789dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// type named in the next step in the nested-name-specifier. 790dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// 791dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// By default, performs semantic analysis when building the new 792dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// nested-name-specifier. Subclasses may override this routine to provide 793dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor /// different behavior. 794dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor NestedNameSpecifier *RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, 795dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor SourceRange Range, 796dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor bool TemplateKW, 797edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor QualType T); 798d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor 799d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// \brief Build a new template name given a nested name specifier, a flag 800d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// indicating whether the "template" keyword was provided, and the template 801d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// that the template name refers to. 802d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// 803d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// By default, builds the new template name directly. Subclasses may override 804d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// this routine to provide different behavior. 805d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, 806d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor bool TemplateKW, 807d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TemplateDecl *Template); 808d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor 809d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// \brief Build a new template name given a nested name specifier and the 810d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// name that is referred to as a template. 811d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// 812d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// By default, performs semantic analysis to determine whether the name can 813d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// be resolved to a specific template, then builds the appropriate kind of 814d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// template name. Subclasses may override this routine to provide different 815d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor /// behavior. 816d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, 8171efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor SourceRange QualifierRange, 8183b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor const IdentifierInfo &II, 81943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 82043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope); 8211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 822ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// \brief Build a new template name given a nested name specifier and the 823ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// overloaded operator name that is referred to as a template. 824ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// 825ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// By default, performs semantic analysis to determine whether the name can 826ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// be resolved to a specific template, then builds the appropriate kind of 827ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// template name. Subclasses may override this routine to provide different 828ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /// behavior. 829ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor TemplateName RebuildTemplateName(NestedNameSpecifier *Qualifier, 830ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor OverloadedOperatorKind Operator, 831ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor QualType ObjectType); 832c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 83343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new compound statement. 83443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 83543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 83643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 83760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc, 83843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor MultiStmtArg Statements, 83943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation RBraceLoc, 84043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool IsStmtExpr) { 8419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements, 84243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor IsStmtExpr); 84343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 84443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 84543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new case statement. 84643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 84743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 84843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 84960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCaseStmt(SourceLocation CaseLoc, 8509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *LHS, 85143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation EllipsisLoc, 8529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *RHS, 85343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation ColonLoc) { 8549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS, 85543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor ColonLoc); 85643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 8571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 85843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Attach the body to a new case statement. 85943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 86043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 86143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 86260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) { 8639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall getSema().ActOnCaseStmtBody(S, Body); 8649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return S; 86543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 8661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 86743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new default statement. 86843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 86943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 87043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 87160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc, 87243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation ColonLoc, 8739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *SubStmt) { 8749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt, 87543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /*CurScope=*/0); 87643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 8771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 87843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new label statement. 87943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 88043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 88143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 88260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildLabelStmt(SourceLocation IdentLoc, 88343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor IdentifierInfo *Id, 88443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation ColonLoc, 8851a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis Stmt *SubStmt, bool HasUnusedAttr) { 8861a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis return SemaRef.ActOnLabelStmt(IdentLoc, Id, ColonLoc, SubStmt, 8871a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis HasUnusedAttr); 88843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 8891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 89043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new "if" statement. 89143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 89243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 89343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 89460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond, 89544aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis VarDecl *CondVar, Stmt *Then, 8969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SourceLocation ElseLoc, Stmt *Else) { 89744aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else); 89843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 8991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 90043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Start building a new switch statement. 90143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 90243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 90343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 90460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc, 9059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Cond, VarDecl *CondVar) { 9069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond, 907d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall CondVar); 90843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 9091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 91043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Attach the body to the switch statement. 91143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 91243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 91343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 91460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc, 9159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Switch, Stmt *Body) { 9169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body); 91743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 91843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 91943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new while statement. 92043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 92143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 92243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 92360d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildWhileStmt(SourceLocation WhileLoc, 924eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor Sema::FullExprArg Cond, 92599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor VarDecl *CondVar, 9269ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Body) { 9279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body); 92843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 9291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 93043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new do-while statement. 93143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 93243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 93343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 93460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body, 93543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation WhileLoc, 93643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation LParenLoc, 9379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Cond, 93843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation RParenLoc) { 9399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc, 9409ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond, RParenLoc); 94143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 94243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 94343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new for statement. 94443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 94543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 94643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 94760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildForStmt(SourceLocation ForLoc, 94843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation LParenLoc, 9499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Init, Sema::FullExprArg Cond, 95099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor VarDecl *CondVar, Sema::FullExprArg Inc, 9519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SourceLocation RParenLoc, Stmt *Body) { 9529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond, 953d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall CondVar, 9549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Inc, RParenLoc, Body); 95543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 9561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 95743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new goto statement. 95843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 95943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 96043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 96160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildGotoStmt(SourceLocation GotoLoc, 96243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation LabelLoc, 96343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor LabelStmt *Label) { 96443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label->getID()); 96543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 96643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 96743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new indirect goto statement. 96843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 96943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 97043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 97160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc, 97243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation StarLoc, 9739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Target) { 9749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target); 97543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 9761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 97743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new return statement. 97843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 97943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 98043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 98160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, 9829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Result) { 9831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 9849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnReturnStmt(ReturnLoc, Result); 98543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 9861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 98743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new declaration statement. 98843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 98943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 99043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 99160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildDeclStmt(Decl **Decls, unsigned NumDecls, 9921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation StartLoc, 99343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation EndLoc) { 99443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getSema().Owned( 99543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor new (getSema().Context) DeclStmt( 99643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor DeclGroupRef::Create(getSema().Context, 99743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Decls, NumDecls), 99843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor StartLoc, EndLoc)); 99943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 10001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1001703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// \brief Build a new inline asm statement. 1002703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// 1003703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// By default, performs semantic analysis to build the new statement. 1004703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson /// Subclasses may override this routine to provide different behavior. 100560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildAsmStmt(SourceLocation AsmLoc, 1006703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool IsSimple, 1007703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool IsVolatile, 1008703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson unsigned NumOutputs, 1009703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson unsigned NumInputs, 1010ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson IdentifierInfo **Names, 1011703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson MultiExprArg Constraints, 1012703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson MultiExprArg Exprs, 10139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *AsmString, 1014703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson MultiExprArg Clobbers, 1015703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson SourceLocation RParenLoc, 1016703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool MSAsm) { 1017c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getSema().ActOnAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs, 1018703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson NumInputs, Names, move(Constraints), 10199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs, AsmString, Clobbers, 1020703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson RParenLoc, MSAsm); 1021703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 10224dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 10234dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// \brief Build a new Objective-C @try statement. 10244dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// 10254dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// By default, performs semantic analysis to build the new statement. 10264dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 102760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc, 10289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *TryBody, 10298f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor MultiStmtArg CatchStmts, 10309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Finally) { 10319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, move(CatchStmts), 10329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Finally); 10334dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 10344dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 1035be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// \brief Rebuild an Objective-C exception declaration. 1036be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// 1037be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// By default, performs semantic analysis to build the new declaration. 1038be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// Subclasses may override this routine to provide different behavior. 1039be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl, 1040be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TypeSourceInfo *TInfo, QualType T) { 1041c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getSema().BuildObjCExceptionDecl(TInfo, T, 1042c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ExceptionDecl->getIdentifier(), 1043be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor ExceptionDecl->getLocation()); 1044be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 1045c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1046be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// \brief Build a new Objective-C @catch statement. 1047be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// 1048be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// By default, performs semantic analysis to build the new statement. 1049be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor /// Subclasses may override this routine to provide different behavior. 105060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc, 1051be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor SourceLocation RParenLoc, 1052be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *Var, 10539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Body) { 1054be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc, 10559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Var, Body); 1056be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 1057c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 10584dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// \brief Build a new Objective-C @finally statement. 10594dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// 10604dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// By default, performs semantic analysis to build the new statement. 10614dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 106260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc, 10639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Body) { 10649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body); 10654dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 1066c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 10678fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// \brief Build a new Objective-C @throw statement. 1068d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor /// 1069d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor /// By default, performs semantic analysis to build the new statement. 1070d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor /// Subclasses may override this routine to provide different behavior. 107160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc, 10729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand) { 10739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildObjCAtThrowStmt(AtLoc, Operand); 1074d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor } 1075c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 10768fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// \brief Build a new Objective-C @synchronized statement. 10778fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// 10788fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// By default, performs semantic analysis to build the new statement. 10798fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor /// Subclasses may override this routine to provide different behavior. 108060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc, 10819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Object, 10829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *Body) { 10839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, 10849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body); 10858fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor } 1086c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor 1087c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// \brief Build a new Objective-C fast enumeration statement. 1088c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// 1089c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// By default, performs semantic analysis to build the new statement. 1090c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /// Subclasses may override this routine to provide different behavior. 109160d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc, 1092f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall SourceLocation LParenLoc, 1093f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *Element, 1094f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Expr *Collection, 1095f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall SourceLocation RParenLoc, 1096f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *Body) { 1097c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor return getSema().ActOnObjCForCollectionStmt(ForLoc, LParenLoc, 10989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Element, 10999ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Collection, 1100c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor RParenLoc, 11019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body); 1102c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor } 1103c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 110443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new C++ exception declaration. 110543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 110643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new decaration. 110743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 110883cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl, 1109a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *Declarator, 111043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor IdentifierInfo *Name, 111183cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor SourceLocation Loc) { 111283cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor return getSema().BuildExceptionDeclaration(0, Declarator, Name, Loc); 111343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 111443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 111543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new C++ catch statement. 111643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 111743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 111843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 111960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc, 1120f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall VarDecl *ExceptionDecl, 1121f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *Handler) { 11229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl, 11239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Handler)); 112443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 11251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 112643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// \brief Build a new C++ try statement. 112743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// 112843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// By default, performs semantic analysis to build the new statement. 112943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor /// Subclasses may override this routine to provide different behavior. 113060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, 1131f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Stmt *TryBlock, 1132f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiStmtArg Handlers) { 11339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, move(Handlers)); 113443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 11351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1136b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression that references a declaration. 1137b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1138b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1139b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 114060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS, 1141f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall LookupResult &R, 1142f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall bool RequiresADL) { 1143f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL); 1144f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 1145f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 1146f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 1147f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// \brief Build a new expression that references a declaration. 1148f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// 1149f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// By default, performs semantic analysis to build the new expression. 1150f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /// Subclasses may override this routine to provide different behavior. 115160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildDeclRefExpr(NestedNameSpecifier *Qualifier, 1152f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall SourceRange QualifierRange, 1153f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall ValueDecl *VD, 1154f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall const DeclarationNameInfo &NameInfo, 1155f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall TemplateArgumentListInfo *TemplateArgs) { 1156a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor CXXScopeSpec SS; 1157a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SS.setScopeRep(Qualifier); 1158a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor SS.setRange(QualifierRange); 1159dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 1160dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // FIXME: loses template args. 11612577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 11622577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD); 1163b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 11641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1165b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression in parentheses. 11661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1167b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1168b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 116960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen, 1170b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParen) { 11719ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnParenExpr(LParen, RParen, SubExpr); 1172b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1173b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1174a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// \brief Build a new pseudo-destructor expression. 11751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1176a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1177a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor /// Subclasses may override this routine to provide different behavior. 117860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base, 1179a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor SourceLocation OperatorLoc, 1180a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor bool isArrow, 1181a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor NestedNameSpecifier *Qualifier, 118226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SourceRange QualifierRange, 118326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor TypeSourceInfo *ScopeType, 118426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SourceLocation CCLoc, 1185fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SourceLocation TildeLoc, 1186a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed); 11871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1188b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new unary operator expression. 11891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1190b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1191b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 119260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildUnaryOperator(SourceLocation OpLoc, 11932de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc, 11949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr) { 11959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildUnaryOp(/*Scope=*/0, OpLoc, Opc, SubExpr); 1196b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 11971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 11988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// \brief Build a new builtin offsetof expression. 11998ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// 12008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// By default, performs semantic analysis to build the new expression. 12018ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor /// Subclasses may override this routine to provide different behavior. 120260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc, 12038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *Type, 1204f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::OffsetOfComponent *Components, 12058ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor unsigned NumComponents, 12068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor SourceLocation RParenLoc) { 12078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components, 12088ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor NumComponents, RParenLoc); 12098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 1210c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1211b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new sizeof or alignof expression with a type argument. 12121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1213b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1214b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 121560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildSizeOfAlignOf(TypeSourceInfo *TInfo, 12165ab75172051a6d2ea71a80a79e81c65519fd3462John McCall SourceLocation OpLoc, 1217b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool isSizeOf, SourceRange R) { 1218a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall return getSema().CreateSizeOfAlignOfExpr(TInfo, OpLoc, isSizeOf, R); 1219b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1220b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 12211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new sizeof or alignof expression with an expression 1222b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// argument. 12231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1224b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1225b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 122660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildSizeOfAlignOf(Expr *SubExpr, SourceLocation OpLoc, 1227b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool isSizeOf, SourceRange R) { 122860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 12299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall = getSema().CreateSizeOfAlignOfExpr(SubExpr, OpLoc, isSizeOf, R); 1230b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 1231f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 12321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1233b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return move(Result); 1234b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 12351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1236b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new array subscript expression. 12371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1238b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1239b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 124060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildArraySubscriptExpr(Expr *LHS, 1241b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LBracketLoc, 12429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *RHS, 1243b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RBracketLoc) { 12449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnArraySubscriptExpr(/*Scope=*/0, LHS, 12459ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LBracketLoc, RHS, 1246b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RBracketLoc); 1247b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1248b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1249b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new call expression. 12501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1251b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1252b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 125360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc, 1254b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg Args, 1255b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 12569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCallExpr(/*Scope=*/0, Callee, LParenLoc, 1257a1a04786cea2445759026edacd096abd1fbf4a05Douglas Gregor move(Args), RParenLoc); 1258b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1259b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1260b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new member access expression. 12611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1262b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1263b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 126460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc, 1265f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall bool isArrow, 1266f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall NestedNameSpecifier *Qualifier, 1267f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceRange QualifierRange, 1268f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall const DeclarationNameInfo &MemberNameInfo, 1269f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ValueDecl *Member, 1270f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall NamedDecl *FoundDecl, 1271d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo *ExplicitTemplateArgs, 1272f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall NamedDecl *FirstQualifierInScope) { 1273d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson if (!Member->getDeclName()) { 1274f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // We have a reference to an unnamed field. This is always the 1275f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // base of an anonymous struct/union member access, i.e. the 1276f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall // field is always of record type. 1277d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson assert(!Qualifier && "Can't have an unnamed field with a qualifier!"); 1278f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall assert(Member->getType()->isRecordType() && 1279f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall "unnamed member not of record type?"); 12801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 12819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (getSema().PerformObjectMemberConversion(Base, Qualifier, 12826bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl, Member)) 1283f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 12848aa5f407d9e4787ff08bd66e1a2fe39be174fddcDouglas Gregor 1285f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind(); 12861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump MemberExpr *ME = 12879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall new (getSema().Context) MemberExpr(Base, isArrow, 12882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara Member, MemberNameInfo, 1289f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall cast<FieldDecl>(Member)->getType(), 1290f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall VK, OK_Ordinary); 1291d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson return getSema().Owned(ME); 1292d8b285fee4471f393da8ee30f552ceacdc362afaAnders Carlsson } 12931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 129483f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor CXXScopeSpec SS; 129583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor if (Qualifier) { 129683f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor SS.setRange(QualifierRange); 129783f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor SS.setScopeRep(Qualifier); 129883f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 129983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor 13009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall getSema().DefaultFunctionArrayConversion(Base); 13019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall QualType BaseType = Base->getType(); 1302aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 13036bb8017bb9e828d118e15e59d71c66bba323c364John McCall // FIXME: this involves duplicating earlier analysis in a lot of 13046bb8017bb9e828d118e15e59d71c66bba323c364John McCall // cases; we should avoid this when possible. 13052577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName); 13066bb8017bb9e828d118e15e59d71c66bba323c364John McCall R.addDecl(FoundDecl); 1307c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R.resolveKind(); 1308c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 13099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow, 1310129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SS, FirstQualifierInScope, 1311c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R, ExplicitTemplateArgs); 1312b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 13131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1314b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new binary operator expression. 13151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1316b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1317b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 131860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildBinaryOperator(SourceLocation OpLoc, 13192de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc, 13209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *LHS, Expr *RHS) { 13219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildBinOp(/*Scope=*/0, OpLoc, Opc, LHS, RHS); 1322b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1323b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1324b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new conditional operator expression. 13251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1326b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1327b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 132860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildConditionalOperator(Expr *Cond, 1329b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation QuestionLoc, 13309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *LHS, 1331b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation ColonLoc, 13329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *RHS) { 13339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond, 13349ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS, RHS); 1335b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1336b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1337b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C-style cast expression. 13381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1339b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1340b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 134160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc, 13429d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1343b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc, 13449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr) { 1345b042fdfc9460e0018276412257e3c3226f9ea96eJohn McCall return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, 13469ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr); 1347b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 13481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1349b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new compound literal expression. 13501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1351b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1352b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 135360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc, 135442f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *TInfo, 1355b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc, 13569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Init) { 135742f56b50062cd3b3c6b23fdb9053578ae9145664John McCall return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, 13589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init); 1359b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 13601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1361b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new extended vector element access expression. 13621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1363b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1364b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 136560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildExtVectorElementExpr(Expr *Base, 1366b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 1367b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation AccessorLoc, 1368b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor IdentifierInfo &Accessor) { 1369aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 1370129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall CXXScopeSpec SS; 13712577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(&Accessor, AccessorLoc); 13729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, Base->getType(), 1373129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall OpLoc, /*IsArrow*/ false, 1374129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SS, /*FirstQualifierInScope*/ 0, 13752577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 1376129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /* TemplateArgs */ 0); 1377b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 13781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1379b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new initializer list expression. 13801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1381b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1382b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 138360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildInitList(SourceLocation LBraceLoc, 1384b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg Inits, 1385e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor SourceLocation RBraceLoc, 1386e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor QualType ResultTy) { 138760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 1388e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor = SemaRef.ActOnInitList(LBraceLoc, move(Inits), RBraceLoc); 1389e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor if (Result.isInvalid() || ResultTy->isDependentType()) 1390e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor return move(Result); 1391c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1392e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor // Patch in the result type we were given, which may have been computed 1393e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor // when the initial InitListExpr was built. 1394e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get()); 1395e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor ILE->setType(ResultTy); 1396e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor return move(Result); 1397b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 13981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1399b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new designated initializer expression. 14001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1401b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1402b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 140360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildDesignatedInitExpr(Designation &Desig, 1404b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg ArrayExprs, 1405b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation EqualOrColonLoc, 1406b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool GNUSyntax, 14079ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Init) { 140860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 1409b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax, 14109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init); 1411b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 1412f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 14131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1414b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.release(); 1415b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return move(Result); 1416b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 14171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1418b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new value-initialized expression. 14191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1420b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds the implicit value initialization without performing 1421b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// any semantic analysis. Subclasses may override this routine to provide 1422b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// different behavior. 142360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildImplicitValueInitExpr(QualType T) { 1424b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.Owned(new (SemaRef.Context) ImplicitValueInitExpr(T)); 1425b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 14261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1427b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new \c va_arg expression. 14281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1429b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1430b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 143160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc, 14329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, TypeSourceInfo *TInfo, 14332cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara SourceLocation RParenLoc) { 14342cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara return getSema().BuildVAArgExpr(BuiltinLoc, 14359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, TInfo, 14362cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara RParenLoc); 1437b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1438b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1439b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new expression list in parentheses. 14401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1441b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1442b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 144360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildParenListExpr(SourceLocation LParenLoc, 1444b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor MultiExprArg SubExprs, 1445b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1446c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getSema().ActOnParenOrParenListExpr(LParenLoc, RParenLoc, 1447f88f7ab5adaa11d050270ffee6aa871e855f83b8Fariborz Jahanian move(SubExprs)); 1448b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 14491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1450b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new address-of-label expression. 14511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 14521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// By default, performs semantic analysis, using the name of the label 1453b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// rather than attempting to map the label statement itself. 1454b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 145560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc, 1456b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LabelLoc, 1457b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LabelStmt *Label) { 1458b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label->getID()); 1459b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 14601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1461b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new GNU statement expression. 14621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// 1463b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1464b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 146560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildStmtExpr(SourceLocation LParenLoc, 14669ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Stmt *SubStmt, 1467b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 14689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc); 1469b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 14701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1471b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new __builtin_choose_expr expression. 1472b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1473b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1474b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 147560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc, 14769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Cond, Expr *LHS, Expr *RHS, 1477b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1478b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.ActOnChooseExpr(BuiltinLoc, 14799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond, LHS, RHS, 1480b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 1481b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 14821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1483b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new overloaded operator call expression. 1484b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1485b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1486b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// The semantic analysis provides the behavior of template instantiation, 1487b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// copying with transformations that turn what looks like an overloaded 14881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// operator call into a use of a builtin operator, performing 1489b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// argument-dependent lookup, etc. Subclasses may override this routine to 1490b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// provide different behavior. 149160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, 1492b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 14939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Callee, 14949ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *First, 14959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Second); 14961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 14971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new C++ "named" cast expression, such as static_cast or 1498b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// reinterpret_cast. 1499b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1500b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, this routine dispatches to one of the more-specific routines 15011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// for a particular named case, e.g., RebuildCXXStaticCastExpr(). 1502b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 150360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc, 1504b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Stmt::StmtClass Class, 1505b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 15069d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1507b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1508b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 15099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1510b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1511b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor switch (Class) { 1512b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXStaticCastExprClass: 15139d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo, 15141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 15159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 1516b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1517b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXDynamicCastExprClass: 15189d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo, 15191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 15209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 15211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1522b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXReinterpretCastExprClass: 15239d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo, 15241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 15259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, 1526b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 15271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1528b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::CXXConstCastExprClass: 15299d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo, 15301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump RAngleLoc, LParenLoc, 15319ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr, RParenLoc); 15321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1533b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor default: 1534b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor assert(false && "Invalid C++ named cast"); 1535b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor break; 1536b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1538f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 1539b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 15401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1541b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ static_cast expression. 1542b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1543b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1544b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 154560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc, 1546b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 15479d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1548b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1549b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 15509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1551b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1552c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast, 15539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1554c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1555c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1556b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1557b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1558b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ dynamic_cast expression. 1559b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1560b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1561b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 156260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc, 1563b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 15649d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1565b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1566b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 15679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1568b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1569c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast, 15709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1571c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1572c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1573b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1574b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1575b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ reinterpret_cast expression. 1576b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1577b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1578b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 157960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc, 1580b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 15819d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1582b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1583b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 15849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1585b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1586c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast, 15879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1588c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1589c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1590b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1591b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1592b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ const_cast expression. 1593b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 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 RebuildCXXConstCastExpr(SourceLocation OpLoc, 1597b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LAngleLoc, 15989d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall TypeSourceInfo *TInfo, 1599b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RAngleLoc, 1600b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation LParenLoc, 16019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SubExpr, 1602b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1603c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast, 16049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall TInfo, SubExpr, 1605c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LAngleLoc, RAngleLoc), 1606c89724cc6dcb178ec79c76d7e629d9a7b5d83418John McCall SourceRange(LParenLoc, RParenLoc)); 1607b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1609b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ functional-style cast expression. 1610b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1611b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1612b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1613ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo, 1614ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 1615ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor Expr *Sub, 1616ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 1617ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc, 1618f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall MultiExprArg(&Sub, 1), 1619b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 1620b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1622b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ typeid(type) expression. 1623b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1624b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1625b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 162660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType, 162757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor SourceLocation TypeidLoc, 162857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TypeSourceInfo *Operand, 1629b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 1630c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, 163157fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor RParenLoc); 1632b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 16331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 163401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 1635b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ typeid(expr) expression. 1636b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 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 RebuildCXXTypeidExpr(QualType TypeInfoType, 164057fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor SourceLocation TypeidLoc, 16419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand, 1642b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 16439ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand, 164457fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor RParenLoc); 16451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 16461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 164701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Build a new C++ __uuidof(type) expression. 164801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// 164901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// By default, performs semantic analysis to build the new expression. 165001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// Subclasses may override this routine to provide different behavior. 165101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, 165201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation TypeidLoc, 165301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TypeSourceInfo *Operand, 165401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation RParenLoc) { 165501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, 165601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet RParenLoc); 165701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 165801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 165901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// \brief Build a new C++ __uuidof(expr) expression. 166001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// 166101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// By default, performs semantic analysis to build the new expression. 166201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet /// Subclasses may override this routine to provide different behavior. 166301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType, 166401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation TypeidLoc, 166501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet Expr *Operand, 166601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SourceLocation RParenLoc) { 166701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand, 166801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet RParenLoc); 166901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 167001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 1671b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "this" expression. 1672b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1673b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds a new "this" expression without performing any 16741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// semantic analysis. Subclasses may override this routine to provide 1675b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// different behavior. 167660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc, 1677ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor QualType ThisType, 1678ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor bool isImplicit) { 1679b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getSema().Owned( 1680828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, 1681828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor isImplicit)); 1682b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1683b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1684b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ throw expression. 1685b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1686b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1687b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 168860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub) { 16899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnCXXThrow(ThrowLoc, Sub); 1690b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1691b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1692b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ default-argument expression. 1693b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1694b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, builds a new default-argument expression, which does not 1695b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// require any semantic analysis. Subclasses may override this routine to 1696b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// provide different behavior. 169760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc, 1698036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor ParmVarDecl *Param) { 1699036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor return getSema().Owned(CXXDefaultArgExpr::Create(getSema().Context, Loc, 1700036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor Param)); 1701b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1702b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1703b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ zero-initialization expression. 1704b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1705b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1706b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1707ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo, 1708ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 1709ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 1710ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc, 17111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump MultiExprArg(getSema(), 0, 0), 1712ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor RParenLoc); 1713b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1715b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "new" expression. 1716b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 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 RebuildCXXNewExpr(SourceLocation StartLoc, 17201bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor bool UseGlobal, 17211bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation PlacementLParen, 17221bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor MultiExprArg PlacementArgs, 17231bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation PlacementRParen, 17241bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceRange TypeIdParens, 17251bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor QualType AllocatedType, 17261bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *AllocatedTypeInfo, 17271bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor Expr *ArraySize, 17281bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation ConstructorLParen, 17291bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor MultiExprArg ConstructorArgs, 17301bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor SourceLocation ConstructorRParen) { 17311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getSema().BuildCXXNew(StartLoc, UseGlobal, 1732b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor PlacementLParen, 1733b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(PlacementArgs), 1734b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor PlacementRParen, 17354bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor TypeIdParens, 17361bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocatedType, 17371bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocatedTypeInfo, 17389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ArraySize, 1739b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ConstructorLParen, 1740b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(ConstructorArgs), 1741b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ConstructorRParen); 1742b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1744b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new C++ "delete" expression. 1745b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1746b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1747b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 174860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc, 1749b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool IsGlobalDelete, 1750b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool IsArrayForm, 17519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Operand) { 1752b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm, 17539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Operand); 1754b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 17551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1756b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new unary type trait expression. 1757b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1758b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1759b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 176060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildUnaryTypeTrait(UnaryTypeTrait Trait, 17613d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor SourceLocation StartLoc, 17623d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *T, 17633d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor SourceLocation RParenLoc) { 17643d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor return getSema().BuildUnaryTypeTrait(Trait, StartLoc, T, RParenLoc); 1765b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1766b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 17676ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// \brief Build a new binary type trait expression. 17686ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// 17696ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// By default, performs semantic analysis to build the new expression. 17706ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet /// Subclasses may override this routine to provide different behavior. 17716ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet ExprResult RebuildBinaryTypeTrait(BinaryTypeTrait Trait, 17726ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation StartLoc, 17736ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *LhsT, 17746ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *RhsT, 17756ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet SourceLocation RParenLoc) { 17766ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return getSema().BuildBinaryTypeTrait(Trait, StartLoc, LhsT, RhsT, RParenLoc); 17776ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet } 17786ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 17791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump /// \brief Build a new (previously unresolved) declaration reference 1780b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// expression. 1781b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1782b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1783b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 178460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildDependentScopeDeclRefExpr(NestedNameSpecifier *NNS, 1785b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceRange QualifierRange, 17862577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &NameInfo, 1787f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall const TemplateArgumentListInfo *TemplateArgs) { 1788b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXScopeSpec SS; 1789b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SS.setRange(QualifierRange); 1790b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SS.setScopeRep(NNS); 1791f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 1792f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (TemplateArgs) 17932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return getSema().BuildQualifiedTemplateIdExpr(SS, NameInfo, 1794f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall *TemplateArgs); 1795f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 17962577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return getSema().BuildQualifiedDeclarationNameExpr(SS, NameInfo); 1797b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1798b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1799b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new template-id expression. 1800b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1801b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1802b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 180360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS, 1804f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall LookupResult &R, 1805f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall bool RequiresADL, 1806d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo &TemplateArgs) { 1807f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getSema().BuildTemplateIdExpr(SS, R, RequiresADL, TemplateArgs); 1808b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1809b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1810b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 1811b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1812b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1813b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 181460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXConstructExpr(QualType T, 18154411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor SourceLocation Loc, 1816b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXConstructorDecl *Constructor, 1817b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool IsElidable, 18188c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor MultiExprArg Args, 18198c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor bool RequiresZeroInit, 1820428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth CXXConstructExpr::ConstructionKind ConstructKind, 1821428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth SourceRange ParenRange) { 1822ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> ConvertedArgs(SemaRef); 1823c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (getSema().CompleteConstructorCall(Constructor, move(Args), Loc, 18244411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor ConvertedArgs)) 1825f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 1826c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 18274411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable, 18288c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor move_arg(ConvertedArgs), 1829428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth RequiresZeroInit, ConstructKind, 1830428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth ParenRange); 1831b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1832b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1833b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 1834b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1835b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1836b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1837ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo, 1838ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 1839ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor MultiExprArg Args, 1840ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 1841ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, 1842b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LParenLoc, 1843b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(Args), 1844b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 1845b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1846b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1847b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new object-construction expression. 1848b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1849b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1850b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 1851ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo, 1852ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation LParenLoc, 1853ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor MultiExprArg Args, 1854ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SourceLocation RParenLoc) { 1855ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getSema().BuildCXXTypeConstructExpr(TSInfo, 1856b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LParenLoc, 1857b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move(Args), 1858b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 1859b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 18601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 1861b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new member reference expression. 1862b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1863b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1864b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 186560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE, 1866aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType, 1867b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool IsArrow, 1868b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OperatorLoc, 1869a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor NestedNameSpecifier *Qualifier, 1870a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor SourceRange QualifierRange, 1871129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall NamedDecl *FirstQualifierInScope, 18722577743c5650c646fb705df01403707e94f2df04Abramo Bagnara const DeclarationNameInfo &MemberNameInfo, 1873129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall const TemplateArgumentListInfo *TemplateArgs) { 1874b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXScopeSpec SS; 1875a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor SS.setRange(QualifierRange); 1876a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor SS.setScopeRep(Qualifier); 18771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 18789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, 1879aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OperatorLoc, IsArrow, 1880129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SS, FirstQualifierInScope, 18812577743c5650c646fb705df01403707e94f2df04Abramo Bagnara MemberNameInfo, 18822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TemplateArgs); 1883b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 1884b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 1885129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /// \brief Build a new member reference expression. 18863b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// 18873b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// By default, performs semantic analysis to build the new expression. 18883b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor /// Subclasses may override this routine to provide different behavior. 188960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, 1890aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType, 1891129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SourceLocation OperatorLoc, 1892129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall bool IsArrow, 1893129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall NestedNameSpecifier *Qualifier, 1894129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall SourceRange QualifierRange, 1895c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall NamedDecl *FirstQualifierInScope, 1896129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall LookupResult &R, 1897129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall const TemplateArgumentListInfo *TemplateArgs) { 18983b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor CXXScopeSpec SS; 18993b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor SS.setRange(QualifierRange); 19003b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor SS.setScopeRep(Qualifier); 19011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19029ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType, 1903aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OperatorLoc, IsArrow, 1904c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall SS, FirstQualifierInScope, 1905c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall R, TemplateArgs); 19063b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 19071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 19082e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// \brief Build a new noexcept expression. 19092e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// 19102e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// By default, performs semantic analysis to build the new expression. 19112e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl /// Subclasses may override this routine to provide different behavior. 19122e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) { 19132e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd()); 19142e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl } 19152e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 1916ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor /// \brief Build a new expression to compute the length of a parameter pack. 1917ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack, 1918ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation PackLoc, 1919ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor SourceLocation RParenLoc, 1920ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor unsigned Length) { 1921ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(), 1922ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor OperatorLoc, Pack, PackLoc, 1923ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor RParenLoc, Length); 1924ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor } 1925ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 1926b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new Objective-C @encode expression. 1927b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 1928b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1929b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 193060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc, 193181d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *EncodeTypeInfo, 1932b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation RParenLoc) { 193381d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor return SemaRef.Owned(SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, 1934b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc)); 19351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 1936b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 193792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /// \brief Build a new Objective-C class message. 193860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo, 193992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Selector Sel, 1940f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis SourceLocation SelectorLoc, 194192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ObjCMethodDecl *Method, 1942c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation LBracLoc, 194392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor MultiExprArg Args, 194492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor SourceLocation RBracLoc) { 194592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return SemaRef.BuildClassMessage(ReceiverTypeInfo, 194692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ReceiverTypeInfo->getType(), 194792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /*SuperLoc=*/SourceLocation(), 1948f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis Sel, Method, LBracLoc, SelectorLoc, 1949f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis RBracLoc, move(Args)); 195092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 195192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 195292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /// \brief Build a new Objective-C instance message. 195360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCMessageExpr(Expr *Receiver, 195492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Selector Sel, 1955f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis SourceLocation SelectorLoc, 195692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ObjCMethodDecl *Method, 1957c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SourceLocation LBracLoc, 195892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor MultiExprArg Args, 195992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor SourceLocation RBracLoc) { 19609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildInstanceMessage(Receiver, 19619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Receiver->getType(), 196292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor /*SuperLoc=*/SourceLocation(), 1963f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis Sel, Method, LBracLoc, SelectorLoc, 1964f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis RBracLoc, move(Args)); 196592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 196692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 1967f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// \brief Build a new Objective-C ivar reference expression. 1968f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// 1969f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// By default, performs semantic analysis to build the new expression. 1970f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// Subclasses may override this routine to provide different behavior. 197160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar, 1972f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor SourceLocation IvarLoc, 1973f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor bool IsArrow, bool IsFreeIvar) { 1974f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // FIXME: We lose track of the IsFreeIvar bit. 1975f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor CXXScopeSpec SS; 19769ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Base = BaseArg; 1977f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor LookupResult R(getSema(), Ivar->getDeclName(), IvarLoc, 1978f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Sema::LookupMemberName); 197960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 1980f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FIME:*/IvarLoc, 1981d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, 1982ad00b7705f9bbee81beeac428e7c6587734ab5a6John McCall false); 1983f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Result.isInvalid()) 1984f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 1985c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 1986f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Result.get()) 1987f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor return move(Result); 1988c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 19899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, Base->getType(), 1990c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /*FIXME:*/IvarLoc, IsArrow, SS, 1991f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FirstQualifierInScope=*/0, 1992c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt R, 1993f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*TemplateArgs=*/0); 1994f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor } 1995e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor 1996e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// \brief Build a new Objective-C property reference expression. 1997e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// 1998e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// By default, performs semantic analysis to build the new expression. 1999e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /// Subclasses may override this routine to provide different behavior. 200060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg, 2001e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor ObjCPropertyDecl *Property, 2002e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor SourceLocation PropertyLoc) { 2003e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor CXXScopeSpec SS; 20049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Base = BaseArg; 2005e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor LookupResult R(getSema(), Property->getDeclName(), PropertyLoc, 2006e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor Sema::LookupMemberName); 2007e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor bool IsArrow = false; 200860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2009e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*FIME:*/PropertyLoc, 2010d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, false); 2011e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (Result.isInvalid()) 2012f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2013c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2014e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (Result.get()) 2015e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor return move(Result); 2016c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 20179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, Base->getType(), 2018c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /*FIXME:*/PropertyLoc, IsArrow, 2019c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt SS, 2020e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*FirstQualifierInScope=*/0, 2021c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt R, 2022e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor /*TemplateArgs=*/0); 2023e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor } 2024c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 202512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// \brief Build a new Objective-C property reference expression. 20269cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor /// 20279cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor /// By default, performs semantic analysis to build the new expression. 202812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall /// Subclasses may override this routine to provide different behavior. 202912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T, 203012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *Getter, 203112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall ObjCMethodDecl *Setter, 203212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall SourceLocation PropertyLoc) { 203312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // Since these expressions can only be value-dependent, we do not 203412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // need to perform semantic analysis again. 203512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return Owned( 203612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T, 203712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall VK_LValue, OK_ObjCProperty, 203812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall PropertyLoc, Base)); 20399cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor } 20409cbfdd212ee0167f2487363d6fac7faaf7c65b64Douglas Gregor 2041f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// \brief Build a new Objective-C "isa" expression. 2042f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// 2043f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// By default, performs semantic analysis to build the new expression. 2044f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /// Subclasses may override this routine to provide different behavior. 204560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc, 2046f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor bool IsArrow) { 2047f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor CXXScopeSpec SS; 20489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Base = BaseArg; 2049f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor LookupResult R(getSema(), &getSema().Context.Idents.get("isa"), IsaLoc, 2050f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Sema::LookupMemberName); 205160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getSema().LookupMemberExpr(R, Base, IsArrow, 2052f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FIME:*/IsaLoc, 2053d226f65006733ed7f709c3174f22ce33391cb58fJohn McCall SS, 0, false); 2054f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Result.isInvalid()) 2055f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 2056c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2057f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Result.get()) 2058f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor return move(Result); 2059c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 20609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, Base->getType(), 2061c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt /*FIXME:*/IsaLoc, IsArrow, SS, 2062f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*FirstQualifierInScope=*/0, 2063c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt R, 2064f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor /*TemplateArgs=*/0); 2065f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor } 2066c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2067b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// \brief Build a new shuffle vector expression. 2068b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// 2069b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// By default, performs semantic analysis to build the new expression. 2070b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /// Subclasses may override this routine to provide different behavior. 207160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc, 2072f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall MultiExprArg SubExprs, 2073f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall SourceLocation RParenLoc) { 2074b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Find the declaration for __builtin_shufflevector 20751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump const IdentifierInfo &Name 2076b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.Context.Idents.get("__builtin_shufflevector"); 2077b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl(); 2078b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name)); 2079b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor assert(Lookup.first != Lookup.second && "No __builtin_shufflevector?"); 20801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2081b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Build a reference to the __builtin_shufflevector builtin 2082b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FunctionDecl *Builtin = cast<FunctionDecl>(*Lookup.first); 20831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Expr *Callee 2084b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = new (SemaRef.Context) DeclRefExpr(Builtin, Builtin->getType(), 2085f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall VK_LValue, BuiltinLoc); 2086b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SemaRef.UsualUnaryConversions(Callee); 20871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 20881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Build the CallExpr 2089b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor unsigned NumSubExprs = SubExprs.size(); 2090b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Expr **Subs = (Expr **)SubExprs.release(); 2091b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CallExpr *TheCall = new (SemaRef.Context) CallExpr(SemaRef.Context, Callee, 2092b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Subs, NumSubExprs, 20935291c3cec0dbe8ad1d8e7e67e93af2b1586d5400Douglas Gregor Builtin->getCallResultType(), 2094f89e55ab1bfb3ea997f8b02997c611a02254eb2dJohn McCall Expr::getValueKindForType(Builtin->getResultType()), 2095b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RParenLoc); 209660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult OwnedCall(SemaRef.Owned(TheCall)); 20971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2098b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Type-check the __builtin_shufflevector expression. 209960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = SemaRef.SemaBuiltinShuffleVector(TheCall); 2100b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 2101f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 21021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2103b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor OwnedCall.release(); 21041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return move(Result); 2105b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 210643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 21078491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// \brief Build a new template argument pack expansion. 21088491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// 21098491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// By default, performs semantic analysis to build a new pack expansion 21108491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// for a template argument. Subclasses may override this routine to provide 21118491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor /// different behavior. 21128491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern, 21138491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor SourceLocation EllipsisLoc) { 21148491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor switch (Pattern.getArgument().getKind()) { 21157a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor case TemplateArgument::Expression: { 21167a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor ExprResult Result 21177a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor = getSema().ActOnPackExpansion(Pattern.getSourceExpression(), 21187a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor EllipsisLoc); 21197a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor if (Result.isInvalid()) 21207a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor return TemplateArgumentLoc(); 21217a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor 21227a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor return TemplateArgumentLoc(Result.get(), Result.get()); 21237a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor } 2124dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 21258491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Template: 21267a21fd45d4f04643cbfb5df96a01f84bc6d3dd14Douglas Gregor llvm_unreachable("Unsupported pack expansion of templates"); 21278491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 21288491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Null: 21298491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Integral: 21308491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Declaration: 21318491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Pack: 21328491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor llvm_unreachable("Pack expansion pattern has no parameter packs"); 21338491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 21348491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor case TemplateArgument::Type: 21358491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (TypeSourceInfo *Expansion 21368491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(), 21378491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor EllipsisLoc)) 21388491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return TemplateArgumentLoc(TemplateArgument(Expansion->getType()), 21398491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Expansion); 21408491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor break; 21418491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 21428491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 21438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return TemplateArgumentLoc(); 21448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 21458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 2146dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// \brief Build a new expression pack expansion. 2147dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// 2148dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// By default, performs semantic analysis to build a new pack expansion 2149dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// for an expression. Subclasses may override this routine to provide 2150dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor /// different behavior. 2151dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc) { 2152dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return getSema().ActOnPackExpansion(Pattern, EllipsisLoc); 2153dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2154dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 215543fed0de4f5bc189e45562491f83d5193eb8dac0John McCallprivate: 215643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType TransformTypeInObjectScope(QualType T, 215743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 215843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope, 215943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NestedNameSpecifier *Prefix); 216043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 216143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *T, 216243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 216343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope, 216443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NestedNameSpecifier *Prefix); 2165577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor}; 2166b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 216743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 216860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) { 216943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!S) 217043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return SemaRef.Owned(S); 21711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 217243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor switch (S->getStmtClass()) { 217343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor case Stmt::NoStmtClass: break; 21741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 217543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform individual statement nodes 217643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) \ 217743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S)); 217843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) 21794bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 21801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 218143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform expressions by calling TransformExpr. 218243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define STMT(Node, Parent) 21837381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 218443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor#define EXPR(Node, Parent) case Stmt::Node##Class: 21854bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 218643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor { 218760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(cast<Expr>(S)); 218843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (E.isInvalid()) 2189f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 21901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().ActOnExprStmt(getSema().MakeFullExpr(E.take())); 219243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 21931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 21941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21953fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 219643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 21971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 21981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2199670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregortemplate<typename Derived> 220060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult TreeTransform<Derived>::TransformExpr(Expr *E) { 2201b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!E) 2202b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return SemaRef.Owned(E); 2203b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 2204b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor switch (E->getStmtClass()) { 2205b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor case Stmt::NoStmtClass: break; 2206b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define STMT(Node, Parent) case Stmt::Node##Class: break; 22077381d5cfbd599fa2b9e215011ad7cbd449de231aSean Hunt#define ABSTRACT_STMT(Stmt) 2208b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor#define EXPR(Node, Parent) \ 2209454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E)); 22104bfe1968410ea8ffe3b4f629addd7c4bcf484765Sean Hunt#include "clang/AST/StmtNodes.inc" 22111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 22121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 22133fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 2214657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor} 2215657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregor 2216657c1acfc47d5c315ce864f2089b692262532a17Douglas Gregortemplate<typename Derived> 2217aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregorbool TreeTransform<Derived>::TransformExprs(Expr **Inputs, 2218aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor unsigned NumInputs, 2219aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool IsCall, 2220aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor llvm::SmallVectorImpl<Expr *> &Outputs, 2221aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor bool *ArgChanged) { 2222aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor for (unsigned I = 0; I != NumInputs; ++I) { 2223aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor // If requested, drop call arguments that need to be dropped. 2224aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (IsCall && getDerived().DropCallArgument(Inputs[I])) { 2225aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (ArgChanged) 2226aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor *ArgChanged = true; 2227aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2228aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor break; 2229aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 2230aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2231dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) { 2232dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Expr *Pattern = Expansion->getPattern(); 2233dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2234dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; 2235dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 2236dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 2237dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2238dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // Determine whether the set of unexpanded parameter packs can and should 2239dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // be expanded. 2240dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor bool Expand = true; 2241dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor unsigned NumExpansions = 0; 2242dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(), 2243dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Pattern->getSourceRange(), 2244dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Unexpanded.data(), 2245dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Unexpanded.size(), 2246dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Expand, NumExpansions)) 2247dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2248dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2249dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (!Expand) { 2250dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // The transform has determined that we should perform a simple 2251dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // transformation on the pack expansion, producing another pack 2252dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // expansion. 2253dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 2254dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult OutPattern = getDerived().TransformExpr(Pattern); 2255dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (OutPattern.isInvalid()) 2256dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2257dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2258dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(), 2259dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Expansion->getEllipsisLoc()); 2260dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (Out.isInvalid()) 2261dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2262dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2263dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (ArgChanged) 2264dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor *ArgChanged = true; 2265dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Outputs.push_back(Out.get()); 2266dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor continue; 2267dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2268dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2269dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // The transform has determined that we should perform an elementwise 2270dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor // expansion of the pattern. Do so. 2271dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor for (unsigned I = 0; I != NumExpansions; ++I) { 2272dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 2273dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor ExprResult Out = getDerived().TransformExpr(Pattern); 2274dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (Out.isInvalid()) 2275dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor return true; 2276dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2277dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor if (ArgChanged) 2278dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor *ArgChanged = true; 2279dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor Outputs.push_back(Out.get()); 2280dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2281dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2282dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor continue; 2283dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor } 2284dcaa1ca0b475dfa887e1d061678a1e3501288510Douglas Gregor 2285aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor ExprResult Result = getDerived().TransformExpr(Inputs[I]); 2286aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (Result.isInvalid()) 2287aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return true; 2288aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2289aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (Result.get() != Inputs[I] && ArgChanged) 2290aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor *ArgChanged = true; 2291aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2292aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Outputs.push_back(Result.get()); 2293aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor } 2294aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2295aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return false; 2296aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor} 2297aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 2298aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregortemplate<typename Derived> 2299dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier * 2300dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::TransformNestedNameSpecifier(NestedNameSpecifier *NNS, 2301a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor SourceRange Range, 2302c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor QualType ObjectType, 2303c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor NamedDecl *FirstQualifierInScope) { 230443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NestedNameSpecifier *Prefix = NNS->getPrefix(); 23051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 230643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the prefix of this nested name specifier. 2307dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor if (Prefix) { 23081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Prefix = getDerived().TransformNestedNameSpecifier(Prefix, Range, 2309c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor ObjectType, 2310c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor FirstQualifierInScope); 2311dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor if (!Prefix) 2312dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor return 0; 2313dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor } 23141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2315dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor switch (NNS->getKind()) { 2316dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor case NestedNameSpecifier::Identifier: 231743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (Prefix) { 231843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // The object type and qualifier-in-scope really apply to the 231943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // leftmost entity. 232043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType = QualType(); 232143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FirstQualifierInScope = 0; 232243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } 232343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 23241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump assert((Prefix || !ObjectType.isNull()) && 2325a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor "Identifier nested-name-specifier with no prefix or object type"); 2326a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor if (!getDerived().AlwaysRebuild() && Prefix == NNS->getPrefix() && 2327a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor ObjectType.isNull()) 2328dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor return NNS; 23291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildNestedNameSpecifier(Prefix, Range, 2331a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor *NNS->getAsIdentifier(), 2332c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor ObjectType, 2333c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor FirstQualifierInScope); 23341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2335dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor case NestedNameSpecifier::Namespace: { 23361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NamespaceDecl *NS 2337dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor = cast_or_null<NamespaceDecl>( 23387c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(Range.getBegin(), 23397c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor NNS->getAsNamespace())); 23401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump if (!getDerived().AlwaysRebuild() && 2341dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor Prefix == NNS->getPrefix() && 2342dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor NS == NNS->getAsNamespace()) 2343dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor return NNS; 23441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2345dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor return getDerived().RebuildNestedNameSpecifier(Prefix, Range, NS); 2346dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor } 23471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2348dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor case NestedNameSpecifier::Global: 2349dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor // There is no meaningful transformation that one could perform on the 2350dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor // global scope. 2351dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor return NNS; 23521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2353dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor case NestedNameSpecifier::TypeSpecWithTemplate: 2354dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor case NestedNameSpecifier::TypeSpec: { 2355fbf2c945f8f8bbfe0459d45c03f9ff34bb445c81Douglas Gregor TemporaryBase Rebase(*this, Range.getBegin(), DeclarationName()); 235643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType T = TransformTypeInObjectScope(QualType(NNS->getAsType(), 0), 235743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType, 235843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FirstQualifierInScope, 235943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall Prefix); 2360d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (T.isNull()) 2361d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor return 0; 23621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2363dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor if (!getDerived().AlwaysRebuild() && 2364dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor Prefix == NNS->getPrefix() && 2365dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor T == QualType(NNS->getAsType(), 0)) 2366dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor return NNS; 23671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 23681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildNestedNameSpecifier(Prefix, Range, 23691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NNS->getKind() == NestedNameSpecifier::TypeSpecWithTemplate, 2370edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor T); 2371dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor } 2372dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor } 23731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2374dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor // Required to silence a GCC warning 23751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return 0; 2376dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor} 2377dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor 2378dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived> 23792577743c5650c646fb705df01403707e94f2df04Abramo BagnaraDeclarationNameInfo 23802577743c5650c646fb705df01403707e94f2df04Abramo BagnaraTreeTransform<Derived> 238143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) { 23822577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName Name = NameInfo.getName(); 238381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor if (!Name) 23842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(); 238581499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor 238681499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor switch (Name.getNameKind()) { 238781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::Identifier: 238881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCZeroArgSelector: 238981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCOneArgSelector: 239081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::ObjCMultiArgSelector: 239181499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXOperatorName: 23923e518bda00d710754ca077cf9be8dd821e16a854Sean Hunt case DeclarationName::CXXLiteralOperatorName: 239381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXUsingDirective: 23942577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return NameInfo; 23951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 239681499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXConstructorName: 239781499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXDestructorName: 239881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor case DeclarationName::CXXConversionFunctionName: { 23992577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TypeSourceInfo *NewTInfo; 24002577743c5650c646fb705df01403707e94f2df04Abramo Bagnara CanQualType NewCanTy; 24012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) { 240243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NewTInfo = getDerived().TransformType(OldTInfo); 240343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (!NewTInfo) 240443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return DeclarationNameInfo(); 240543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType()); 24062577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 24072577743c5650c646fb705df01403707e94f2df04Abramo Bagnara else { 24082577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewTInfo = 0; 24092577743c5650c646fb705df01403707e94f2df04Abramo Bagnara TemporaryBase Rebase(*this, NameInfo.getLoc(), Name); 241043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType NewT = getDerived().TransformType(Name.getCXXNameType()); 24112577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (NewT.isNull()) 24122577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(); 24132577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewCanTy = SemaRef.Context.getCanonicalType(NewT); 24142577743c5650c646fb705df01403707e94f2df04Abramo Bagnara } 24151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24162577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName NewName 24172577743c5650c646fb705df01403707e94f2df04Abramo Bagnara = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(), 24182577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewCanTy); 24192577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NewNameInfo(NameInfo); 24202577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewNameInfo.setName(NewName); 24212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NewNameInfo.setNamedTypeInfo(NewTInfo); 24222577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return NewNameInfo; 242381499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor } 24241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump } 24251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara assert(0 && "Unknown name kind."); 24272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara return DeclarationNameInfo(); 242881499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor} 242981499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregor 243081499bbeb2bd157a77b60364676ac434aca7a4dfDouglas Gregortemplate<typename Derived> 24311eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 24323b6afbb99a1c44b4076f8e15fb7311405941b306Douglas GregorTreeTransform<Derived>::TransformTemplateName(TemplateName Name, 243343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 243443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope) { 24357c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor SourceLocation Loc = getDerived().getBaseLocation(); 24367c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor 2437d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) { 24381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump NestedNameSpecifier *NNS 2439d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor = getDerived().TransformNestedNameSpecifier(QTN->getQualifier(), 244043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall /*FIXME*/ SourceRange(Loc), 244143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType, 244243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FirstQualifierInScope); 2443d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (!NNS) 2444d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor return TemplateName(); 24451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2446d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (TemplateDecl *Template = QTN->getTemplateDecl()) { 24471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateDecl *TransTemplate 24487c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); 2449d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (!TransTemplate) 2450d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor return TemplateName(); 24511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2452d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (!getDerived().AlwaysRebuild() && 2453d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor NNS == QTN->getQualifier() && 2454d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TransTemplate == Template) 2455d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor return Name; 24561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2457d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor return getDerived().RebuildTemplateName(NNS, QTN->hasTemplateKeyword(), 2458d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TransTemplate); 2459d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor } 24601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2461f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // These should be getting filtered out before they make it into the AST. 246243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall llvm_unreachable("overloaded template name survived to here"); 2463d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor } 24641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2465d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) { 246643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NestedNameSpecifier *NNS = DTN->getQualifier(); 246743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (NNS) { 246843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NNS = getDerived().TransformNestedNameSpecifier(NNS, 246943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall /*FIXME:*/SourceRange(Loc), 247043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType, 247143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FirstQualifierInScope); 247243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (!NNS) return TemplateName(); 247343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 247443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // These apply to the scope specifier, not the template. 247543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType = QualType(); 247643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FirstQualifierInScope = 0; 247743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } 24781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2479d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (!getDerived().AlwaysRebuild() && 2480dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor NNS == DTN->getQualifier() && 2481dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor ObjectType.isNull()) 2482d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor return Name; 24831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 24841efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor if (DTN->isIdentifier()) { 24851efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor // FIXME: Bad range 24861efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor SourceRange QualifierRange(getDerived().getBaseLocation()); 24871efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor return getDerived().RebuildTemplateName(NNS, QualifierRange, 24881efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor *DTN->getIdentifier(), 248943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType, 249043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FirstQualifierInScope); 24911efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor } 2492c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2493c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getDerived().RebuildTemplateName(NNS, DTN->getOperator(), 2494ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor ObjectType); 2495d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor } 24961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2497d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (TemplateDecl *Template = Name.getAsTemplateDecl()) { 24981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump TemplateDecl *TransTemplate 24997c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<TemplateDecl>(getDerived().TransformDecl(Loc, Template)); 2500d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (!TransTemplate) 2501d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor return TemplateName(); 25021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2503d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor if (!getDerived().AlwaysRebuild() && 2504d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TransTemplate == Template) 2505d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor return Name; 25061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2507d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor return TemplateName(TransTemplate); 2508d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor } 25091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2510f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // These should be getting filtered out before they reach the AST. 251143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall llvm_unreachable("overloaded function decl survived to here"); 2512f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return TemplateName(); 2513d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor} 2514d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor 2515d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived> 2516833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallvoid TreeTransform<Derived>::InventTemplateArgumentLoc( 2517833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgument &Arg, 2518833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &Output) { 2519833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation Loc = getDerived().getBaseLocation(); 2520670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor switch (Arg.getKind()) { 2521670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Null: 25229f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin llvm_unreachable("null template argument in TreeTransform"); 2523833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2524833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2525833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Type: 2526833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(Arg, 2527a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc)); 2528c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2529833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2530833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2531788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: 2532788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor Output = TemplateArgumentLoc(Arg, SourceRange(), Loc); 2533788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor break; 2534c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2535833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Expression: 2536833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(Arg, Arg.getAsExpr()); 2537833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2538833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2539833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Declaration: 2540670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Integral: 2541833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Pack: 2542828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo()); 2543833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall break; 2544833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 2545833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall} 2546833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2547833ca991c1bfc967f0995974ca86f66ba1f666b5John McCalltemplate<typename Derived> 2548833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallbool TreeTransform<Derived>::TransformTemplateArgument( 2549833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgumentLoc &Input, 2550833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateArgumentLoc &Output) { 2551833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall const TemplateArgument &Arg = Input.getArgument(); 2552833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall switch (Arg.getKind()) { 2553833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Null: 2554833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall case TemplateArgument::Integral: 2555833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = Input; 2556833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 25571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2558670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Type: { 2559a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *DI = Input.getTypeSourceInfo(); 2560833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (DI == NULL) 2561a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall DI = InventTypeSourceInfo(Input.getArgument().getAsType()); 2562833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2563833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall DI = getDerived().TransformType(DI); 2564833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!DI) return true; 2565833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2566833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI); 2567833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2568670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 25691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2570670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Declaration: { 2571833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: we should never have to transform one of these. 2572972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor DeclarationName Name; 2573972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor if (NamedDecl *ND = dyn_cast<NamedDecl>(Arg.getAsDecl())) 2574972e6ce33c7e307f4b0da12bd6079bbd6ef76948Douglas Gregor Name = ND->getDeclName(); 2575788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor TemporaryBase Rebase(*this, Input.getLocation(), Name); 25767c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor Decl *D = getDerived().TransformDecl(Input.getLocation(), Arg.getAsDecl()); 2577833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!D) return true; 2578833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2579828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Expr *SourceExpr = Input.getSourceDeclExpression(); 2580828bff2079b6a91ecd7ed5b842c59527d7682789John McCall if (SourceExpr) { 2581828bff2079b6a91ecd7ed5b842c59527d7682789John McCall EnterExpressionEvaluationContext Unevaluated(getSema(), 2582f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::Unevaluated); 258360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(SourceExpr); 25849ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SourceExpr = (E.isInvalid() ? 0 : E.take()); 2585828bff2079b6a91ecd7ed5b842c59527d7682789John McCall } 2586828bff2079b6a91ecd7ed5b842c59527d7682789John McCall 2587828bff2079b6a91ecd7ed5b842c59527d7682789John McCall Output = TemplateArgumentLoc(TemplateArgument(D), SourceExpr); 2588833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2589670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 25901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2591788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor case TemplateArgument::Template: { 2592c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt TemporaryBase Rebase(*this, Input.getLocation(), DeclarationName()); 2593788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor TemplateName Template 2594788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor = getDerived().TransformTemplateName(Arg.getAsTemplate()); 2595788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor if (Template.isNull()) 2596788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return true; 2597c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2598788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor Output = TemplateArgumentLoc(TemplateArgument(Template), 2599788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor Input.getTemplateQualifierRange(), 2600788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor Input.getTemplateNameLoc()); 2601788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor return false; 2602788cd06cf8e868a67158aafec5de3a1f408d14f3Douglas Gregor } 2603c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2604670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Expression: { 2605670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Template argument expressions are not potentially evaluated. 26061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EnterExpressionEvaluationContext Unevaluated(getSema(), 2607f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::Unevaluated); 26081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2609833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall Expr *InputExpr = Input.getSourceExpression(); 2610833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!InputExpr) InputExpr = Input.getArgument().getAsExpr(); 2611833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 261260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E 2613833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall = getDerived().TransformExpr(InputExpr); 2614833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (E.isInvalid()) return true; 26159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Output = TemplateArgumentLoc(TemplateArgument(E.take()), E.take()); 2616833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2617670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 26181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2619670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor case TemplateArgument::Pack: { 2620670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor llvm::SmallVector<TemplateArgument, 4> TransformedArgs; 2621670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor TransformedArgs.reserve(Arg.pack_size()); 26221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump for (TemplateArgument::pack_iterator A = Arg.pack_begin(), 2623670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor AEnd = Arg.pack_end(); 2624670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor A != AEnd; ++A) { 26251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2626833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: preserve source information here when we start 2627833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // caring about parameter packs. 2628833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2629828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TemplateArgumentLoc InputArg; 2630828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TemplateArgumentLoc OutputArg; 2631828bff2079b6a91ecd7ed5b842c59527d7682789John McCall getDerived().InventTemplateArgumentLoc(*A, InputArg); 2632828bff2079b6a91ecd7ed5b842c59527d7682789John McCall if (getDerived().TransformTemplateArgument(InputArg, OutputArg)) 2633833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 2634833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 2635828bff2079b6a91ecd7ed5b842c59527d7682789John McCall TransformedArgs.push_back(OutputArg.getArgument()); 2636670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 2637910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor 2638910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TemplateArgument *TransformedArgsPtr 2639910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor = new (getSema().Context) TemplateArgument[TransformedArgs.size()]; 2640910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor std::copy(TransformedArgs.begin(), TransformedArgs.end(), 2641910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TransformedArgsPtr); 2642910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor Output = TemplateArgumentLoc(TemplateArgument(TransformedArgsPtr, 2643910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor TransformedArgs.size()), 2644910f8008fea79120489a53593fe971b0b8a4a740Douglas Gregor Input.getLocInfo()); 2645833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return false; 2646670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 2647670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor } 26481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2649670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Work around bogus GCC warning 2650833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return true; 2651670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor} 2652670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor 26537ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// \brief Iterator adaptor that invents template argument location information 26547ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor/// for each of the template arguments in its underlying iterator. 26557ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename Derived, typename InputIterator> 26567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorclass TemplateArgumentLocInventIterator { 26577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TreeTransform<Derived> &Self; 26587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Iter; 26597ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 26607ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorpublic: 26617ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc value_type; 26627ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc reference; 26637ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef typename std::iterator_traits<InputIterator>::difference_type 26647ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor difference_type; 26657ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef std::input_iterator_tag iterator_category; 26667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 26677ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class pointer { 26687ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Arg; 2669fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 26707ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 26717ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } 26727ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 26737ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLoc *operator->() const { return &Arg; } 26747ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 26757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 26767ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator() { } 26777ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 26787ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self, 26797ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Iter) 26807ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor : Self(Self), Iter(Iter) { } 26817ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 26827ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator &operator++() { 26837ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++Iter; 26847ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return *this; 2685fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor } 2686fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 26877ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator operator++(int) { 26887ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocInventIterator Old(*this); 26897ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++(*this); 26907ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Old; 26917ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 26927ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 26937ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor reference operator*() const { 26947ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Result; 26957ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor Self.InventTemplateArgumentLoc(*Iter, Result); 26967ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Result; 26977ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 26987ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 26997ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor pointer operator->() const { return pointer(**this); } 27007ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 27017ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator==(const TemplateArgumentLocInventIterator &X, 27027ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLocInventIterator &Y) { 27037ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Iter == Y.Iter; 27047ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 2705fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor 27067ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator!=(const TemplateArgumentLocInventIterator &X, 27077ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLocInventIterator &Y) { 27087ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Iter != Y.Iter; 27097ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 27107ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor}; 27117ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 27127f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregortemplate<typename Derived> 27137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregortemplate<typename InputIterator> 27147ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregorbool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First, 27157ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor InputIterator Last, 27167f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor TemplateArgumentListInfo &Outputs) { 27177ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor for (; First != Last; ++First) { 27187f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor TemplateArgumentLoc Out; 27197ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc In = *First; 27208491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 27218491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (In.getArgument().getKind() == TemplateArgument::Pack) { 27228491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // Unpack argument packs, which we translate them into separate 27238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // arguments. 27247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // FIXME: We could do much better if we could guarantee that the 27257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // TemplateArgumentLocInfo for the pack expansion would be usable for 27267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor // all of the template arguments in the argument pack. 27277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLocInventIterator<Derived, 27287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgument::pack_iterator> 27297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor PackLocIterator; 27307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor if (TransformTemplateArguments(PackLocIterator(*this, 27317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor In.getArgument().pack_begin()), 27327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor PackLocIterator(*this, 27337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor In.getArgument().pack_end()), 27347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor Outputs)) 27357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return true; 27368491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 27378491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 27388491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 27398491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 27408491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (In.getArgument().isPackExpansion()) { 27418491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // We have a pack expansion, for which we will be substituting into 27428491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // the pattern. 27438491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor SourceLocation Ellipsis; 27448491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc Pattern 27458491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor = In.getPackExpansionPattern(Ellipsis, getSema().Context); 27468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 27478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor llvm::SmallVector<UnexpandedParameterPack, 2> Unexpanded; 27488491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded); 27498491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor assert(!Unexpanded.empty() && "Pack expansion without parameter packs?"); 27508491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 27518491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // Determine whether the set of unexpanded parameter packs can and should 27528491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // be expanded. 27538491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor bool Expand = true; 27548491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor unsigned NumExpansions = 0; 27558491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TryExpandParameterPacks(Ellipsis, 27568491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Pattern.getSourceRange(), 27578491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Unexpanded.data(), 27588491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Unexpanded.size(), 27598491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Expand, NumExpansions)) 27608491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 27618491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 27628491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (!Expand) { 27638491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The transform has determined that we should perform a simple 27648491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // transformation on the pack expansion, producing another pack 27658491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // expansion. 27668491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor TemplateArgumentLoc OutPattern; 27678491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1); 27688491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, OutPattern)) 27698491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 27708491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 27718491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis); 27728491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (Out.getArgument().isNull()) 27738491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 27748491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 27758491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Outputs.addArgument(Out); 27768491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 27778491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 27788491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 27798491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The transform has determined that we should perform an elementwise 27808491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // expansion of the pattern. Do so. 27818491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor for (unsigned I = 0; I != NumExpansions; ++I) { 27828491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I); 27838491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 27848491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(Pattern, Out)) 27858491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor return true; 27868491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 27878491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Outputs.addArgument(Out); 27888491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 27898491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 27908491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor continue; 27918491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor } 27928491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor 27938491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor // The simple case: 27948491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor if (getDerived().TransformTemplateArgument(In, Out)) 27957f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return true; 27967f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 27977f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor Outputs.addArgument(Out); 27987f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor } 27997f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 28007f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return false; 28017f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 28027f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor} 28037f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor 2804577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 2805577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor// Type transformation 2806577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 2807577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 2808577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 280943fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>::TransformType(QualType T) { 2810577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (getDerived().AlreadyTransformed(T)) 2811577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return T; 28121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2813a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Temporary workaround. All of these transformations should 2814a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // eventually turn into transformations on TypeLocs. 2815a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *DI = getSema().Context.CreateTypeSourceInfo(T); 28164802a311f402836f1f226a3d7a87e6a3088f9704John McCall DI->getTypeLoc().initialize(getDerived().getBaseLocation()); 2817c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 281843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeSourceInfo *NewDI = getDerived().TransformType(DI); 28191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2820a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (!NewDI) 2821a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 28221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2823a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return NewDI->getType(); 2824577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 28251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2826577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 282743fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) { 2828a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlreadyTransformed(DI->getType())) 2829a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return DI; 28301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2831a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder TLB; 28321bb8a45f7386a23871598d05141a07af03067925Argyrios Kyrtzidis 2833a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLoc TL = DI->getTypeLoc(); 2834a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TLB.reserve(TL.getFullDataSize()); 28351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 283643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result = getDerived().TransformType(TLB, TL); 2837a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 2838a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return 0; 28391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2840a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall return TLB.getTypeSourceInfo(SemaRef.Context, Result); 2841577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 28421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 2844a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 284543fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) { 2846a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall switch (T.getTypeLocClass()) { 2847a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define ABSTRACT_TYPELOC(CLASS, PARENT) 2848a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#define TYPELOC(CLASS, PARENT) \ 2849a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall case TypeLoc::CLASS: \ 285043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived().Transform##CLASS##Type(TLB, cast<CLASS##TypeLoc>(T)); 2851a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall#include "clang/AST/TypeLocNodes.def" 2852a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 2853577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 28549f61aa9e280adea9fbf3365f0e4f6ed568c9885aJeffrey Yasskin llvm_unreachable("unhandled type loc!"); 2855a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 2856577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 28571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2858a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// FIXME: By default, this routine adds type qualifiers only to types 2859a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that can have qualifiers, and silently suppresses those qualifiers 2860a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// that are not permitted (e.g., qualifiers on reference or function 2861a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// types). This is the right thing for template instantiation, but 2862a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall/// probably not for other clients. 28631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 28641eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 2865a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB, 286643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualifiedTypeLoc T) { 2867a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor Qualifiers Quals = T.getType().getLocalQualifiers(); 2868a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 286943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc()); 2870a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 2871577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 28721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2873a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Silently suppress qualifiers if the result type can't be qualified. 2874a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: this is the right thing for template instantiation, but 2875a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // probably not for other clients. 2876a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result->isFunctionType() || Result->isReferenceType()) 2877a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 28781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 28792865474261a608c7873b87ba4af110d17907896dJohn McCall if (!Quals.empty()) { 28802865474261a608c7873b87ba4af110d17907896dJohn McCall Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals); 28812865474261a608c7873b87ba4af110d17907896dJohn McCall TLB.push<QualifiedTypeLoc>(Result); 28822865474261a608c7873b87ba4af110d17907896dJohn McCall // No location information to preserve. 28832865474261a608c7873b87ba4af110d17907896dJohn McCall } 2884a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 2885a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 2886a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 2887a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 288843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// \brief Transforms a type that was written in a scope specifier, 288943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// given an object type, the results of unqualified lookup, and 289043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// an already-instantiated prefix. 289143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// 289243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// The object type is provided iff the scope specifier qualifies the 289343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// member of a dependent member-access expression. The prefix is 289443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// provided iff the the scope specifier in which this appears has a 289543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// prefix. 289643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// 289743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall/// This is private to TreeTransform. 289843fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived> 289943fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType 290043fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformTypeInObjectScope(QualType T, 290143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 290243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *UnqualLookup, 290343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NestedNameSpecifier *Prefix) { 290443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (getDerived().AlreadyTransformed(T)) 290543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return T; 290643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 290743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeSourceInfo *TSI = 290843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall SemaRef.Context.getTrivialTypeSourceInfo(T, getBaseLocation()); 290943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 291043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TSI = getDerived().TransformTypeInObjectScope(TSI, ObjectType, 291143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall UnqualLookup, Prefix); 291243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (!TSI) return QualType(); 291343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TSI->getType(); 291443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall} 291543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 291643fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived> 291743fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTypeSourceInfo * 291843fed0de4f5bc189e45562491f83d5193eb8dac0John McCallTreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSI, 291943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 292043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *UnqualLookup, 292143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NestedNameSpecifier *Prefix) { 292243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // TODO: in some cases, we might be some verification to do here. 292343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (ObjectType.isNull()) 292443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived().TransformType(TSI); 292543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 292643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType T = TSI->getType(); 292743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (getDerived().AlreadyTransformed(T)) 292843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TSI; 292943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 293043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeLocBuilder TLB; 293143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType Result; 293243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 293343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (isa<TemplateSpecializationType>(T)) { 293443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateSpecializationTypeLoc TL 293543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = cast<TemplateSpecializationTypeLoc>(TSI->getTypeLoc()); 293643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 293743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template = 293843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall getDerived().TransformTemplateName(TL.getTypePtr()->getTemplateName(), 293943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType, UnqualLookup); 294043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (Template.isNull()) return 0; 294143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 294243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall Result = getDerived() 294343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall .TransformTemplateSpecializationType(TLB, TL, Template); 294443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } else if (isa<DependentTemplateSpecializationType>(T)) { 294543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentTemplateSpecializationTypeLoc TL 294643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = cast<DependentTemplateSpecializationTypeLoc>(TSI->getTypeLoc()); 294743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 294843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall Result = getDerived() 294943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall .TransformDependentTemplateSpecializationType(TLB, TL, Prefix); 295043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } else { 295143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // Nothing special needs to be done for these. 295243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall Result = getDerived().TransformType(TLB, TSI->getTypeLoc()); 295343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } 295443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 295543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (Result.isNull()) return 0; 295643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TLB.getTypeSourceInfo(SemaRef.Context, Result); 295743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall} 295843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 2959a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate <class TyLoc> static inline 2960a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) { 2961a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TyLoc NewT = TLB.push<TyLoc>(T.getType()); 2962a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewT.setNameLoc(T.getNameLoc()); 2963a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return T.getType(); 2964a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 2965a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 2966a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 2967a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB, 296843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall BuiltinTypeLoc T) { 2969ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType()); 2970ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor NewT.setBuiltinLoc(T.getBuiltinLoc()); 2971ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor if (T.needsExtraLocalData()) 2972ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs(); 2973ddf889a2ad2888f1dea573987bbe952d9912c1a0Douglas Gregor return T.getType(); 2974577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 2975577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 29761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 2977a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB, 297843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ComplexTypeLoc T) { 2979a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: recurse? 2980a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return TransformTypeSpecType(TLB, T); 2981a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 29821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 2983a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 2984a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB, 298543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall PointerTypeLoc TL) { 2986c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt QualType PointeeType 2987c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt = getDerived().TransformType(TLB, TL.getPointeeLoc()); 298892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (PointeeType.isNull()) 298992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return QualType(); 299092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 299192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor QualType Result = TL.getType(); 2992c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall if (PointeeType->getAs<ObjCObjectType>()) { 299392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // A dependent pointer type 'T *' has is being transformed such 299492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // that an Objective-C class type is being replaced for 'T'. The 299592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // resulting pointer type is an ObjCObjectPointerType, not a 299692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // PointerType. 2997c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall Result = SemaRef.Context.getObjCObjectPointerType(PointeeType); 2998c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 2999c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result); 3000c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall NewT.setStarLoc(TL.getStarLoc()); 300192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return Result; 300292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 300343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 300492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (getDerived().AlwaysRebuild() || 300592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor PointeeType != TL.getPointeeLoc().getType()) { 300692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc()); 300792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (Result.isNull()) 300892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return QualType(); 300992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 3010c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 301192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result); 301292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor NewT.setSigilLoc(TL.getSigilLoc()); 3013c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return Result; 3014577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3015577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 30161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 30171eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3018a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB, 301943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall BlockPointerTypeLoc TL) { 3020db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor QualType PointeeType 3021c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt = getDerived().TransformType(TLB, TL.getPointeeLoc()); 3022c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (PointeeType.isNull()) 3023c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return QualType(); 3024c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3025c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt QualType Result = TL.getType(); 3026c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt if (getDerived().AlwaysRebuild() || 3027c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt PointeeType != TL.getPointeeLoc().getType()) { 3028c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt Result = getDerived().RebuildBlockPointerType(PointeeType, 3029db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor TL.getSigilLoc()); 3030db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor if (Result.isNull()) 3031db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor return QualType(); 3032db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor } 3033db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor 303439968adc66ab02275d2f561e372a20ae454bd4e7Douglas Gregor BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result); 3035db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor NewT.setSigilLoc(TL.getSigilLoc()); 3036db93c4a8f839b2f46bfea66531aa014242f4da2cDouglas Gregor return Result; 3037a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 30381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 303985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// Transforms a reference type. Note that somewhat paradoxically we 304085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// don't care whether the type itself is an l-value type or an r-value 304185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// type; we only care if the type was *written* as an l-value type 304285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall/// or an r-value type. 304385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCalltemplate<typename Derived> 304485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType 304585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB, 304643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ReferenceTypeLoc TL) { 304785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall const ReferenceType *T = TL.getTypePtr(); 304885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 304985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall // Note that this works with the pointee-as-written. 305085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 305185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (PointeeType.isNull()) 305285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return QualType(); 305385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 305485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType Result = TL.getType(); 305585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (getDerived().AlwaysRebuild() || 305685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall PointeeType != T->getPointeeTypeAsWritten()) { 305785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Result = getDerived().RebuildReferenceType(PointeeType, 305885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->isSpelledAsLValue(), 305985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getSigilLoc()); 306085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (Result.isNull()) 306185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return QualType(); 306285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall } 306385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 306485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall // r-value references can be rebuilt as l-value references. 306585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall ReferenceTypeLoc NewTL; 306685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall if (isa<LValueReferenceType>(Result)) 306785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL = TLB.push<LValueReferenceTypeLoc>(Result); 306885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall else 306985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL = TLB.push<RValueReferenceTypeLoc>(Result); 307085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall NewTL.setSigilLoc(TL.getSigilLoc()); 307185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 307285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall return Result; 307385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall} 307485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall 3075a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3076a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3077a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB, 307843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall LValueReferenceTypeLoc TL) { 307943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TransformReferenceType(TLB, TL); 3080a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 30811eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3082a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 3083a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3084a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB, 308543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall RValueReferenceTypeLoc TL) { 308643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return TransformReferenceType(TLB, TL); 3087577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 30881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3089577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 30901eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3091a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB, 309243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall MemberPointerTypeLoc TL) { 3093a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall MemberPointerType *T = TL.getTypePtr(); 3094a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3095a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc()); 3096577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (PointeeType.isNull()) 3097577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 30981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3099a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // TODO: preserve source information for this. 3100a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ClassType 3101a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall = getDerived().TransformType(QualType(T->getClass(), 0)); 3102577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ClassType.isNull()) 3103577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 31041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3105a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3106a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3107a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall PointeeType != T->getPointeeType() || 3108a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ClassType != QualType(T->getClass(), 0)) { 310985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Result = getDerived().RebuildMemberPointerType(PointeeType, ClassType, 311085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getStarLoc()); 3111a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3112a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3113a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3114577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3115a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result); 3116a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSigilLoc(TL.getSigilLoc()); 3117a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3118a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3119577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3120577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 31211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 31221eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 3123a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB, 312443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ConstantArrayTypeLoc TL) { 3125a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ConstantArrayType *T = TL.getTypePtr(); 3126a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3127577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3128577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 31291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3130a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3131a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3132a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3133a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildConstantArrayType(ElementType, 3134a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 3135a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSize(), 313685737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->getIndexTypeCVRQualifiers(), 313785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3138a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3139a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3140a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3141c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3142a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ConstantArrayTypeLoc NewTL = TLB.push<ConstantArrayTypeLoc>(Result); 3143a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3144a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 31451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3146a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Expr *Size = TL.getSizeExpr(); 3147a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Size) { 3148f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 3149a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Size = getDerived().TransformExpr(Size).template takeAs<Expr>(); 3150a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3151a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(Size); 3152a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3153a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3154577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 31551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3156577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 3157577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformIncompleteArrayType( 3158a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 315943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall IncompleteArrayTypeLoc TL) { 3160a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall IncompleteArrayType *T = TL.getTypePtr(); 3161a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3162577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3163577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 31641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3165a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3166a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3167a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3168a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildIncompleteArrayType(ElementType, 3169a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 317085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall T->getIndexTypeCVRQualifiers(), 317185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3172a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3173a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3174a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3175c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3176a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result); 3177a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3178a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 3179a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(0); 3180577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3181a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3182577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 31831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3184577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 3185a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3186a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB, 318743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall VariableArrayTypeLoc TL) { 3188a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall VariableArrayType *T = TL.getTypePtr(); 3189a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3190577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3191577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 31921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3193670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Array bounds are not potentially evaluated contexts 3194f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 3195670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor 319660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SizeResult 3197a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall = getDerived().TransformExpr(T->getSizeExpr()); 3198a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (SizeResult.isInvalid()) 3199577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 32001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Size = SizeResult.take(); 3202a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3203a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3204a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3205a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType() || 3206a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Size != T->getSizeExpr()) { 3207a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildVariableArrayType(ElementType, 3208a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 32099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Size, 3210a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getIndexTypeCVRQualifiers(), 321185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3212a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3213a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3214577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 3215c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3216a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall VariableArrayTypeLoc NewTL = TLB.push<VariableArrayTypeLoc>(Result); 3217a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3218a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 3219a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(Size); 32201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3221a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3222577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 32231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3225a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3226a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB, 322743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentSizedArrayTypeLoc TL) { 3228a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall DependentSizedArrayType *T = TL.getTypePtr(); 3229a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc()); 3230577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3231577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 32321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3233670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Array bounds are not potentially evaluated contexts 3234f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 32351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 323660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SizeResult 3237a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall = getDerived().TransformExpr(T->getSizeExpr()); 3238a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (SizeResult.isInvalid()) 3239577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 32401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3241a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Expr *Size = static_cast<Expr*>(SizeResult.get()); 3242a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3243a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3244a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3245a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType() || 3246a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Size != T->getSizeExpr()) { 3247a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildDependentSizedArrayType(ElementType, 3248a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getSizeModifier(), 32499ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Size, 3250a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getIndexTypeCVRQualifiers(), 325185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall TL.getBracketsRange()); 3252a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3253a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3254577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 3255a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall else SizeResult.take(); 32561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3257a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // We might have any sort of array type now, but fortunately they 3258a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // all have the same location layout. 3259a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result); 3260a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLBracketLoc(TL.getLBracketLoc()); 3261a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRBracketLoc(TL.getRBracketLoc()); 3262a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setSizeExpr(Size); 3263a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3264a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3265577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 32661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 32671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3268577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformDependentSizedExtVectorType( 3269a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 327043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentSizedExtVectorTypeLoc TL) { 3271a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall DependentSizedExtVectorType *T = TL.getTypePtr(); 3272a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3273a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // FIXME: ext vector locs should be nested 3274577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3275577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3276577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 32771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3278670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // Vector sizes are not potentially evaluated contexts 3279f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 3280670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor 328160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Size = getDerived().TransformExpr(T->getSizeExpr()); 3282577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (Size.isInvalid()) 3283577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 32841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3285a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3286a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3287eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall ElementType != T->getElementType() || 3288eee91c3efbfc6a1509b42f39beb5533a9636fd70John McCall Size.get() != T->getSizeExpr()) { 3289a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildDependentSizedExtVectorType(ElementType, 32909ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Size.take(), 3291577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor T->getAttributeLoc()); 3292a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3293a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3294a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3295a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3296a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Result might be dependent or not. 3297a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (isa<DependentSizedExtVectorType>(Result)) { 3298a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall DependentSizedExtVectorTypeLoc NewTL 3299a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall = TLB.push<DependentSizedExtVectorTypeLoc>(Result); 3300a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 3301a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } else { 3302a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); 3303a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 3304a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3305a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3306a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3307577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 33081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3310a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB, 331143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall VectorTypeLoc TL) { 3312a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall VectorType *T = TL.getTypePtr(); 3313577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3314577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3315577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 3316577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3317a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3318a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3319a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 332082287d19ded35248c4ce6a425ce74116a13ce44eJohn Thompson Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(), 3321e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson T->getVectorKind()); 3322a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3323a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3324a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3325c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3326a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result); 3327a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 33281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3329a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3330577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 33311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 33321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3333a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB, 333443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ExtVectorTypeLoc TL) { 3335a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall VectorType *T = TL.getTypePtr(); 3336577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType ElementType = getDerived().TransformType(T->getElementType()); 3337577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (ElementType.isNull()) 3338577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 33391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3340a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3341a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3342a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ElementType != T->getElementType()) { 3343a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildExtVectorType(ElementType, 3344a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->getNumElements(), 3345a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall /*FIXME*/ SourceLocation()); 3346a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3347a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3348a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3349c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 3350a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result); 3351a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 33521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3353a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3354577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3355577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 33561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 335721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallParmVarDecl * 335821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallTreeTransform<Derived>::TransformFunctionTypeParam(ParmVarDecl *OldParm) { 335921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo(); 336021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall TypeSourceInfo *NewDI = getDerived().TransformType(OldDI); 336121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall if (!NewDI) 336221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return 0; 336321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 336421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall if (NewDI == OldDI) 336521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return OldParm; 336621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall else 336721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return ParmVarDecl::Create(SemaRef.Context, 336821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall OldParm->getDeclContext(), 336921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall OldParm->getLocation(), 337021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall OldParm->getIdentifier(), 337121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall NewDI->getType(), 337221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall NewDI, 337321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall OldParm->getStorageClass(), 337416573fa9705b546b7597c273b25b85d6321e2b33Douglas Gregor OldParm->getStorageClassAsWritten(), 337521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall /* DefArg */ NULL); 337621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall} 337721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 337821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived> 337921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallbool TreeTransform<Derived>:: 338021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall TransformFunctionTypeParams(FunctionProtoTypeLoc TL, 338121ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall llvm::SmallVectorImpl<QualType> &PTypes, 338221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall llvm::SmallVectorImpl<ParmVarDecl*> &PVars) { 3383a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall FunctionProtoType *T = TL.getTypePtr(); 33841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3385a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall for (unsigned i = 0, e = TL.getNumArgs(); i != e; ++i) { 3386a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ParmVarDecl *OldParm = TL.getArg(i); 3387a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3388a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType NewType; 3389a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ParmVarDecl *NewParm; 3390a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3391a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (OldParm) { 339221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall NewParm = getDerived().TransformFunctionTypeParam(OldParm); 339321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall if (!NewParm) 339421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return true; 3395a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewType = NewParm->getType(); 3396a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3397a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // Deal with the possibility that we don't have a parameter 3398a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall // declaration for this parameter. 3399a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } else { 3400a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewParm = 0; 3401a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3402a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType OldType = T->getArgType(i); 3403a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewType = getDerived().TransformType(OldType); 3404a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (NewType.isNull()) 340521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return true; 3406a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 34071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 340821ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall PTypes.push_back(NewType); 340921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall PVars.push_back(NewParm); 3410577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 34111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 341221ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall return false; 341321ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall} 341421ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall 341521ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCalltemplate<typename Derived> 341621ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallQualType 341721ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCallTreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB, 341843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FunctionProtoTypeLoc TL) { 34197e010a04fef171049291d8cb3047f118566da090Douglas Gregor // Transform the parameters and return type. 34207e010a04fef171049291d8cb3047f118566da090Douglas Gregor // 34217e010a04fef171049291d8cb3047f118566da090Douglas Gregor // We instantiate in source order, with the return type first followed by 34227e010a04fef171049291d8cb3047f118566da090Douglas Gregor // the parameters, because users tend to expect this (even if they shouldn't 34237e010a04fef171049291d8cb3047f118566da090Douglas Gregor // rely on it!). 34247e010a04fef171049291d8cb3047f118566da090Douglas Gregor // 3425dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // When the function has a trailing return type, we instantiate the 3426dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // parameters before the return type, since the return type can then refer 3427dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // to the parameters themselves (via decltype, sizeof, etc.). 3428dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor // 342921ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall llvm::SmallVector<QualType, 4> ParamTypes; 343021ef0fa27b0783ec0bc6aa5b524feb2ec840f952John McCall llvm::SmallVector<ParmVarDecl*, 4> ParamDecls; 3431895162da2d52f4243f61081d7436de66af4503fcDouglas Gregor FunctionProtoType *T = TL.getTypePtr(); 34327e010a04fef171049291d8cb3047f118566da090Douglas Gregor 3433dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor QualType ResultType; 3434dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 3435dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (TL.getTrailingReturn()) { 3436dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls)) 3437dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 3438dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 3439dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 3440dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (ResultType.isNull()) 3441dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 3442dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor } 3443dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor else { 3444dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 3445dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (ResultType.isNull()) 3446dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 3447dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 3448dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor if (getDerived().TransformFunctionTypeParams(TL, ParamTypes, ParamDecls)) 3449dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor return QualType(); 3450dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor } 3451dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor 3452a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3453a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3454a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ResultType != T->getResultType() || 3455a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall !std::equal(T->arg_type_begin(), T->arg_type_end(), ParamTypes.begin())) { 3456a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildFunctionProtoType(ResultType, 3457a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ParamTypes.data(), 3458a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ParamTypes.size(), 3459a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall T->isVariadic(), 3460fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman T->getTypeQuals(), 3461fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman T->getExtInfo()); 3462a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3463a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3464a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 34651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3466a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result); 3467a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLParenLoc(TL.getLParenLoc()); 3468a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRParenLoc(TL.getRParenLoc()); 3469dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor NewTL.setTrailingReturn(TL.getTrailingReturn()); 3470a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall for (unsigned i = 0, e = NewTL.getNumArgs(); i != e; ++i) 3471a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setArg(i, ParamDecls[i]); 3472a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3473a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3474577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 34751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3476577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 3477577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformFunctionNoProtoType( 3478a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 347943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall FunctionNoProtoTypeLoc TL) { 3480a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall FunctionNoProtoType *T = TL.getTypePtr(); 3481a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType ResultType = getDerived().TransformType(TLB, TL.getResultLoc()); 3482a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (ResultType.isNull()) 3483a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3484a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3485a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3486a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3487a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall ResultType != T->getResultType()) 3488a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildFunctionNoProtoType(ResultType); 3489a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3490a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result); 3491a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setLParenLoc(TL.getLParenLoc()); 3492a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setRParenLoc(TL.getRParenLoc()); 3493dab60ad68a3a98d687305941a3852e793705f945Douglas Gregor NewTL.setTrailingReturn(false); 3494a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3495a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3496577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 34971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3498ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> QualType 3499ed97649e9574b9d854fa4d6109c9333ae0993554John McCallTreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB, 350043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall UnresolvedUsingTypeLoc TL) { 3501ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UnresolvedUsingType *T = TL.getTypePtr(); 35027c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl()); 3503ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (!D) 3504ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return QualType(); 3505ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 3506ed97649e9574b9d854fa4d6109c9333ae0993554John McCall QualType Result = TL.getType(); 3507ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (getDerived().AlwaysRebuild() || D != T->getDecl()) { 3508ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Result = getDerived().RebuildUnresolvedUsingType(D); 3509ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (Result.isNull()) 3510ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return QualType(); 3511ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 3512ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 3513ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // We might get an arbitrary type spec type back. We should at 3514ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // least always get a type spec type, though. 3515ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result); 3516ed97649e9574b9d854fa4d6109c9333ae0993554John McCall NewTL.setNameLoc(TL.getNameLoc()); 3517ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 3518ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return Result; 3519ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 3520ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 3521577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 3522a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB, 352343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypedefTypeLoc TL) { 3524a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypedefType *T = TL.getTypePtr(); 3525577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor TypedefDecl *Typedef 35267c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<TypedefDecl>(getDerived().TransformDecl(TL.getNameLoc(), 35277c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor T->getDecl())); 3528577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Typedef) 3529577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 35301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3531a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3532a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3533a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Typedef != T->getDecl()) { 3534a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildTypedefType(Typedef); 3535a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3536a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3537a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3538a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3539a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result); 3540a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 35411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3542a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3543577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 35441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3545577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 3546a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB, 354743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeOfExprTypeLoc TL) { 3548670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // typeof expressions are not potentially evaluated contexts 3549f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 35501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 355160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr()); 3552577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (E.isInvalid()) 3553577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 3554577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3555a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3556a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3557cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall E.get() != TL.getUnderlyingExpr()) { 35582a984cad5ac3fdceeff2bd99daa7b90979313475John McCall Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc()); 3559a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3560a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3561577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 3562a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall else E.take(); 35631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3564a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result); 3565cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setTypeofLoc(TL.getTypeofLoc()); 3566cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setLParenLoc(TL.getLParenLoc()); 3567cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setRParenLoc(TL.getRParenLoc()); 3568a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3569a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3570577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 35711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3573a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB, 357443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeOfTypeLoc TL) { 3575cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo(); 3576cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI); 3577cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall if (!New_Under_TI) 3578577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 35791eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3580a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3581cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) { 3582cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall Result = getDerived().RebuildTypeOfType(New_Under_TI->getType()); 3583a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3584a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3585a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 35861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3587a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result); 3588cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setTypeofLoc(TL.getTypeofLoc()); 3589cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setLParenLoc(TL.getLParenLoc()); 3590cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setRParenLoc(TL.getRParenLoc()); 3591cfb708c354e2f30ccc5cba9d644650f408a1ec3eJohn McCall NewTL.setUnderlyingTInfo(New_Under_TI); 3592a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3593a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3594577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 35951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 35961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3597a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB, 359843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DecltypeTypeLoc TL) { 3599a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall DecltypeType *T = TL.getTypePtr(); 3600a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3601670444ed30cc8ff66eb4847d921d9af0291a7111Douglas Gregor // decltype expressions are not potentially evaluated contexts 3602f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 36031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 360460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr()); 3605577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (E.isInvalid()) 3606577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3608a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3609a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3610a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall E.get() != T->getUnderlyingExpr()) { 36112a984cad5ac3fdceeff2bd99daa7b90979313475John McCall Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc()); 3612a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3613a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3614577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 3615a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall else E.take(); 3616a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3617a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result); 3618a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 36191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3620a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3621577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3622577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3623577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 3624a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB, 362543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall RecordTypeLoc TL) { 3626a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall RecordType *T = TL.getTypePtr(); 3627577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor RecordDecl *Record 36287c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(), 36297c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor T->getDecl())); 3630577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Record) 3631577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3633a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3634a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3635a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Record != T->getDecl()) { 3636a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildRecordType(Record); 3637a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3638a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3639a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 36401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3641a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result); 3642a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 3643a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3644a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3645577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 36461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 36471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3648a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB, 364943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall EnumTypeLoc TL) { 3650a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall EnumType *T = TL.getTypePtr(); 3651577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor EnumDecl *Enum 36527c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(), 36537c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor T->getDecl())); 3654577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!Enum) 3655577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 36561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3657a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3658a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3659a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Enum != T->getDecl()) { 3660a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall Result = getDerived().RebuildEnumType(Enum); 3661a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3662a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3663a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3664a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3665a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result); 3666a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NewTL.setNameLoc(TL.getNameLoc()); 36671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3668a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3669577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 36707da2431c23ef1ee8acb114e39692246e1801afc2John McCall 36713cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCalltemplate<typename Derived> 36723cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCallQualType TreeTransform<Derived>::TransformInjectedClassNameType( 36733cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TypeLocBuilder &TLB, 367443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall InjectedClassNameTypeLoc TL) { 36753cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall Decl *D = getDerived().TransformDecl(TL.getNameLoc(), 36763cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TL.getTypePtr()->getDecl()); 36773cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall if (!D) return QualType(); 36783cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 36793cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D)); 36803cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc()); 36813cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall return T; 36823cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall} 36833cb0ebd5f76abcb776f7cb4062bd79e3268c0dc4John McCall 36841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3685577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 3686577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateTypeParmType( 3687a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 368843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateTypeParmTypeLoc TL) { 3689a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return TransformTypeSpecType(TLB, TL); 3690577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 3691577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 36921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 369349a832bd499d6f61c23655f1fac99f0dd229756eJohn McCallQualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType( 3694a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall TypeLocBuilder &TLB, 369543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall SubstTemplateTypeParmTypeLoc TL) { 3696a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return TransformTypeSpecType(TLB, TL); 369749a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall} 369849a832bd499d6f61c23655f1fac99f0dd229756eJohn McCall 369949a832bd499d6f61c23655f1fac99f0dd229756eJohn McCalltemplate<typename Derived> 3700833ca991c1bfc967f0995974ca86f66ba1f666b5John McCallQualType TreeTransform<Derived>::TransformTemplateSpecializationType( 370143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TypeLocBuilder &TLB, 370243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateSpecializationTypeLoc TL) { 370343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall const TemplateSpecializationType *T = TL.getTypePtr(); 3704828bff2079b6a91ecd7ed5b842c59527d7682789John McCall 370543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template 370643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = getDerived().TransformTemplateName(T->getTemplateName()); 370743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (Template.isNull()) 370843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return QualType(); 3709833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 371043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived().TransformTemplateSpecializationType(TLB, TL, Template); 3711dd62b15665a4144c45c1f7c53665414ad5f7f4f2Douglas Gregor} 371243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 37137ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregornamespace { 37147ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \brief Simple iterator that traverses the template arguments in a 37157ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// container that provides a \c getArgLoc() member function. 37167ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// 37177ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// This iterator is intended to be used with the iterator form of 37187ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor /// \c TreeTransform<Derived>::TransformTemplateArguments(). 37197ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor template<typename ArgLocContainer> 37207ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class TemplateArgumentLocContainerIterator { 37217ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgLocContainer *Container; 37227ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor unsigned Index; 37237ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 37247ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 37257ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc value_type; 37267ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLoc reference; 37277ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef int difference_type; 37287ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef std::input_iterator_tag iterator_category; 37297ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 37307ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor class pointer { 37317ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc Arg; 37327ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 37337ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor public: 37347ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { } 37357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 37367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor const TemplateArgumentLoc *operator->() const { 37377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return &Arg; 37387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 37397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 37407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 37417ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 37427ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator() {} 37437ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 37447ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator(ArgLocContainer &Container, 37457ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor unsigned Index) 37467ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor : Container(&Container), Index(Index) { } 37477ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 37487ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator &operator++() { 37497ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++Index; 37507ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return *this; 37517ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 37527ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 37537ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator operator++(int) { 37547ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLocContainerIterator Old(*this); 37557ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ++(*this); 37567ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Old; 37577ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 37587ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 37597ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor TemplateArgumentLoc operator*() const { 37607ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return Container->getArgLoc(Index); 37617ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 37627ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 37637ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor pointer operator->() const { 37647ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return pointer(Container->getArgLoc(Index)); 37657ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 37667ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 37677ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator==(const TemplateArgumentLocContainerIterator &X, 3768f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor const TemplateArgumentLocContainerIterator &Y) { 37697ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return X.Container == Y.Container && X.Index == Y.Index; 37707ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 37717ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 37727ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor friend bool operator!=(const TemplateArgumentLocContainerIterator &X, 3773f7dd69969aa25093ca9a7897a0d8819c145d1c77Douglas Gregor const TemplateArgumentLocContainerIterator &Y) { 37747ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor return !(X == Y); 37757ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor } 37767ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor }; 37777ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor} 37787ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 37797ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 378043fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate <typename Derived> 3781577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::TransformTemplateSpecializationType( 3782833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TypeLocBuilder &TLB, 3783833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateSpecializationTypeLoc TL, 378443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TemplateName Template) { 3785d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo NewTemplateArgs; 3786d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 3787d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 37887ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc> 37897ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgIterator; 37907ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 37917ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgIterator(TL, TL.getNumArgs()), 37927ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor NewTemplateArgs)) 37937f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return QualType(); 37941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3795833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall // FIXME: maybe don't rebuild if all the template arguments are the same. 3796833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 3797833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall QualType Result = 3798833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall getDerived().RebuildTemplateSpecializationType(Template, 3799833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TL.getTemplateNameLoc(), 3800d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NewTemplateArgs); 38011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3802833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall if (!Result.isNull()) { 3803833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateSpecializationTypeLoc NewTL 3804833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall = TLB.push<TemplateSpecializationTypeLoc>(Result); 3805833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setTemplateNameLoc(TL.getTemplateNameLoc()); 3806833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setLAngleLoc(TL.getLAngleLoc()); 3807833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setRAngleLoc(TL.getRAngleLoc()); 3808833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i) 3809833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo()); 3810833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall } 38111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3812833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall return Result; 3813577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 38141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3816a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3817465d41b92b2c862f3062c412a0538db65c6a2661Abramo BagnaraTreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB, 381843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ElaboratedTypeLoc TL) { 3819465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedType *T = TL.getTypePtr(); 3820465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara 3821465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara NestedNameSpecifier *NNS = 0; 3822465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara // NOTE: the qualifier in an ElaboratedType is optional. 3823465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara if (T->getQualifier() != 0) { 3824465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara NNS = getDerived().TransformNestedNameSpecifier(T->getQualifier(), 382543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TL.getQualifierRange()); 3826465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara if (!NNS) 3827465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara return QualType(); 3828465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara } 38291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 383043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc()); 383143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (NamedT.isNull()) 383243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return QualType(); 3833a63db84b164d3f1c987a3ea6251e3092db4f317bDaniel Dunbar 3834a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall QualType Result = TL.getType(); 3835a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (getDerived().AlwaysRebuild() || 3836a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall NNS != T->getQualifier() || 3837e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NamedT != T->getNamedType()) { 383821e413fe6305a198564d436ac515497716c47844John McCall Result = getDerived().RebuildElaboratedType(TL.getKeywordLoc(), 383921e413fe6305a198564d436ac515497716c47844John McCall T->getKeyword(), NNS, NamedT); 3840a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3841a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3842a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall } 3843577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 3844465d41b92b2c862f3062c412a0538db65c6a2661Abramo Bagnara ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 3845e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setKeywordLoc(TL.getKeywordLoc()); 3846e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setQualifierRange(TL.getQualifierRange()); 3847a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3848a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3849577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 38501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 38511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 3852075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraQualType 3853075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo BagnaraTreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB, 3854075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenTypeLoc TL) { 3855075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc()); 3856075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (Inner.isNull()) 3857075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(); 3858075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 3859075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara QualType Result = TL.getType(); 3860075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (getDerived().AlwaysRebuild() || 3861075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Inner != TL.getInnerLoc().getType()) { 3862075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara Result = getDerived().RebuildParenType(Inner); 3863075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara if (Result.isNull()) 3864075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return QualType(); 3865075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara } 3866075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 3867075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result); 3868075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara NewTL.setLParenLoc(TL.getLParenLoc()); 3869075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara NewTL.setRParenLoc(TL.getRParenLoc()); 3870075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara return Result; 3871075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara} 3872075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnara 3873075f8f1b6bed4d1b224c74f87508534cc6392ce6Abramo Bagnaratemplate<typename Derived> 38744714c12a1ab759156b78be8f109ea4c12213af57Douglas GregorQualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB, 387543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentNameTypeLoc TL) { 38764714c12a1ab759156b78be8f109ea4c12213af57Douglas Gregor DependentNameType *T = TL.getTypePtr(); 3877833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall 3878577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor NestedNameSpecifier *NNS 3879e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara = getDerived().TransformNestedNameSpecifier(T->getQualifier(), 388043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TL.getQualifierRange()); 3881577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (!NNS) 3882577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return QualType(); 38831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 388433500955d731c73717af52088b7fc0e7a85681e7John McCall QualType Result 388533500955d731c73717af52088b7fc0e7a85681e7John McCall = getDerived().RebuildDependentNameType(T->getKeyword(), NNS, 388633500955d731c73717af52088b7fc0e7a85681e7John McCall T->getIdentifier(), 388733500955d731c73717af52088b7fc0e7a85681e7John McCall TL.getKeywordLoc(), 388833500955d731c73717af52088b7fc0e7a85681e7John McCall TL.getQualifierRange(), 388933500955d731c73717af52088b7fc0e7a85681e7John McCall TL.getNameLoc()); 3890a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall if (Result.isNull()) 3891a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return QualType(); 3892a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 3893e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) { 3894e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara QualType NamedT = ElabT->getNamedType(); 389533500955d731c73717af52088b7fc0e7a85681e7John McCall TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc()); 389633500955d731c73717af52088b7fc0e7a85681e7John McCall 3897e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 3898e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setKeywordLoc(TL.getKeywordLoc()); 3899e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setQualifierRange(TL.getQualifierRange()); 390033500955d731c73717af52088b7fc0e7a85681e7John McCall } else { 3901e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result); 3902e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setKeywordLoc(TL.getKeywordLoc()); 3903e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setQualifierRange(TL.getQualifierRange()); 3904e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara NewTL.setNameLoc(TL.getNameLoc()); 3905e4da7a034a2fcf4b14d0bcc28d05de0878159061Abramo Bagnara } 3906a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return Result; 3907577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 39081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 3909577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 391033500955d731c73717af52088b7fc0e7a85681e7John McCallQualType TreeTransform<Derived>:: 391133500955d731c73717af52088b7fc0e7a85681e7John McCall TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 391243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentTemplateSpecializationTypeLoc TL) { 391333500955d731c73717af52088b7fc0e7a85681e7John McCall DependentTemplateSpecializationType *T = TL.getTypePtr(); 391433500955d731c73717af52088b7fc0e7a85681e7John McCall 391533500955d731c73717af52088b7fc0e7a85681e7John McCall NestedNameSpecifier *NNS 391633500955d731c73717af52088b7fc0e7a85681e7John McCall = getDerived().TransformNestedNameSpecifier(T->getQualifier(), 391743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TL.getQualifierRange()); 391833500955d731c73717af52088b7fc0e7a85681e7John McCall if (!NNS) 391933500955d731c73717af52088b7fc0e7a85681e7John McCall return QualType(); 392033500955d731c73717af52088b7fc0e7a85681e7John McCall 392143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return getDerived() 392243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall .TransformDependentTemplateSpecializationType(TLB, TL, NNS); 392343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall} 392443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 392543fed0de4f5bc189e45562491f83d5193eb8dac0John McCalltemplate<typename Derived> 392643fed0de4f5bc189e45562491f83d5193eb8dac0John McCallQualType TreeTransform<Derived>:: 392743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB, 392843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentTemplateSpecializationTypeLoc TL, 392943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NestedNameSpecifier *NNS) { 393043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall DependentTemplateSpecializationType *T = TL.getTypePtr(); 393143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 393233500955d731c73717af52088b7fc0e7a85681e7John McCall TemplateArgumentListInfo NewTemplateArgs; 393333500955d731c73717af52088b7fc0e7a85681e7John McCall NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc()); 393433500955d731c73717af52088b7fc0e7a85681e7John McCall NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc()); 39357ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor 39367ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor typedef TemplateArgumentLocContainerIterator< 39377ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor DependentTemplateSpecializationTypeLoc> ArgIterator; 39387ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0), 39397ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor ArgIterator(TL, TL.getNumArgs()), 39407ca7ac40ad45d5253ba474dddfa5ee233f35c2feDouglas Gregor NewTemplateArgs)) 39417f61f2fc1a880ac3bf5b0993525922dd2c1f09bfDouglas Gregor return QualType(); 394233500955d731c73717af52088b7fc0e7a85681e7John McCall 39431efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor QualType Result 39441efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(), 39451efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor NNS, 39461efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor TL.getQualifierRange(), 39471efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor T->getIdentifier(), 39481efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor TL.getNameLoc(), 39491efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor NewTemplateArgs); 395033500955d731c73717af52088b7fc0e7a85681e7John McCall if (Result.isNull()) 395133500955d731c73717af52088b7fc0e7a85681e7John McCall return QualType(); 395233500955d731c73717af52088b7fc0e7a85681e7John McCall 395333500955d731c73717af52088b7fc0e7a85681e7John McCall if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) { 395433500955d731c73717af52088b7fc0e7a85681e7John McCall QualType NamedT = ElabT->getNamedType(); 395533500955d731c73717af52088b7fc0e7a85681e7John McCall 395633500955d731c73717af52088b7fc0e7a85681e7John McCall // Copy information relevant to the template specialization. 395733500955d731c73717af52088b7fc0e7a85681e7John McCall TemplateSpecializationTypeLoc NamedTL 395833500955d731c73717af52088b7fc0e7a85681e7John McCall = TLB.push<TemplateSpecializationTypeLoc>(NamedT); 395933500955d731c73717af52088b7fc0e7a85681e7John McCall NamedTL.setLAngleLoc(TL.getLAngleLoc()); 396033500955d731c73717af52088b7fc0e7a85681e7John McCall NamedTL.setRAngleLoc(TL.getRAngleLoc()); 396133500955d731c73717af52088b7fc0e7a85681e7John McCall for (unsigned I = 0, E = TL.getNumArgs(); I != E; ++I) 396233500955d731c73717af52088b7fc0e7a85681e7John McCall NamedTL.setArgLocInfo(I, TL.getArgLocInfo(I)); 396333500955d731c73717af52088b7fc0e7a85681e7John McCall 396433500955d731c73717af52088b7fc0e7a85681e7John McCall // Copy information relevant to the elaborated type. 396533500955d731c73717af52088b7fc0e7a85681e7John McCall ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result); 396633500955d731c73717af52088b7fc0e7a85681e7John McCall NewTL.setKeywordLoc(TL.getKeywordLoc()); 396733500955d731c73717af52088b7fc0e7a85681e7John McCall NewTL.setQualifierRange(TL.getQualifierRange()); 396833500955d731c73717af52088b7fc0e7a85681e7John McCall } else { 3969e2872d0bda1d209d4409de2ed13648e6811628b7Douglas Gregor TypeLoc NewTL(Result, TL.getOpaqueData()); 3970e2872d0bda1d209d4409de2ed13648e6811628b7Douglas Gregor TLB.pushFullCopy(NewTL); 397133500955d731c73717af52088b7fc0e7a85681e7John McCall } 397233500955d731c73717af52088b7fc0e7a85681e7John McCall return Result; 397333500955d731c73717af52088b7fc0e7a85681e7John McCall} 397433500955d731c73717af52088b7fc0e7a85681e7John McCall 397533500955d731c73717af52088b7fc0e7a85681e7John McCalltemplate<typename Derived> 39767536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas GregorQualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB, 39777536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor PackExpansionTypeLoc TL) { 39787536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor // FIXME: Implement! 39797536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor getSema().Diag(TL.getEllipsisLoc(), 39807536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor diag::err_pack_expansion_instantiation_unsupported); 39817536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor return QualType(); 39827536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor} 39837536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregor 39847536dd5e6c99584481b7dab68b7e7d8df9c54054Douglas Gregortemplate<typename Derived> 3985a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 3986a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB, 398743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCInterfaceTypeLoc TL) { 3988ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor // ObjCInterfaceType is never dependent. 3989c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 3990c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall return TL.getType(); 3991c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall} 3992c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall 3993c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCalltemplate<typename Derived> 3994c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallQualType 3995c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCallTreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB, 399643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCObjectTypeLoc TL) { 3997c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall // ObjCObjectType is never dependent. 3998c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 3999ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor return TL.getType(); 4000577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 40011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 4003a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType 4004a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallTreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB, 400543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjCObjectPointerTypeLoc TL) { 4006ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor // ObjCObjectPointerType is never dependent. 4007c12c5bba6ceb6acd4e51e7a0fc03257da9cfd44eJohn McCall TLB.pushFullCopy(TL); 4008ef57c61ec3642ba7faaf7b9c0c4a6f23fa39d77cDouglas Gregor return TL.getType(); 400924fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis} 401024fab41057e4b67ed69a6b4027d5ae0f2f6934dcArgyrios Kyrtzidis 4011577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 401243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor// Statement transformation 401343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===// 401443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 401560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 40161eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformNullStmt(NullStmt *S) { 40173fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 401843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 401943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 402043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 402160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 402243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) { 402343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().TransformCompoundStmt(S, false); 402443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 402543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 402643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 402760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 40281eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S, 402943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool IsStmtExpr) { 40307114cbab7eb6e8b714eb22f014327daf2c741c08John McCall bool SubStmtInvalid = false; 403143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool SubStmtChanged = false; 4032ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Stmt*> Statements(getSema()); 403343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (CompoundStmt::body_iterator B = S->body_begin(), BEnd = S->body_end(); 403443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor B != BEnd; ++B) { 403560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Result = getDerived().TransformStmt(*B); 40367114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (Result.isInvalid()) { 40377114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // Immediately fail if this was a DeclStmt, since it's very 40387114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // likely that this will cause problems for future statements. 40397114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (isa<DeclStmt>(*B)) 40407114cbab7eb6e8b714eb22f014327daf2c741c08John McCall return StmtError(); 40417114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 40427114cbab7eb6e8b714eb22f014327daf2c741c08John McCall // Otherwise, just keep processing substatements and fail later. 40437114cbab7eb6e8b714eb22f014327daf2c741c08John McCall SubStmtInvalid = true; 40447114cbab7eb6e8b714eb22f014327daf2c741c08John McCall continue; 40457114cbab7eb6e8b714eb22f014327daf2c741c08John McCall } 40461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 404743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SubStmtChanged = SubStmtChanged || Result.get() != *B; 404843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Statements.push_back(Result.takeAs<Stmt>()); 404943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 40501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 40517114cbab7eb6e8b714eb22f014327daf2c741c08John McCall if (SubStmtInvalid) 40527114cbab7eb6e8b714eb22f014327daf2c741c08John McCall return StmtError(); 40537114cbab7eb6e8b714eb22f014327daf2c741c08John McCall 405443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 405543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !SubStmtChanged) 40563fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 405743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 405843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildCompoundStmt(S->getLBracLoc(), 405943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor move_arg(Statements), 406043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getRBracLoc(), 406143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor IsStmtExpr); 406243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 40631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 406443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 406560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 40661eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) { 406760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS, RHS; 4068264c1f8ec895952466eab59b84b8b06801e721faEli Friedman { 4069264c1f8ec895952466eab59b84b8b06801e721faEli Friedman // The case value expressions are not potentially evaluated. 4070f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 40711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4072264c1f8ec895952466eab59b84b8b06801e721faEli Friedman // Transform the left-hand case value. 4073264c1f8ec895952466eab59b84b8b06801e721faEli Friedman LHS = getDerived().TransformExpr(S->getLHS()); 4074264c1f8ec895952466eab59b84b8b06801e721faEli Friedman if (LHS.isInvalid()) 4075f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 40761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4077264c1f8ec895952466eab59b84b8b06801e721faEli Friedman // Transform the right-hand case value (for the GNU case-range extension). 4078264c1f8ec895952466eab59b84b8b06801e721faEli Friedman RHS = getDerived().TransformExpr(S->getRHS()); 4079264c1f8ec895952466eab59b84b8b06801e721faEli Friedman if (RHS.isInvalid()) 4080f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4081264c1f8ec895952466eab59b84b8b06801e721faEli Friedman } 40821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 408343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Build the case statement. 408443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Case statements are always rebuilt so that they will attached to their 408543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transformed switch statement. 408660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(), 40879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), 408843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getEllipsisLoc(), 40899ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get(), 409043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getColonLoc()); 409143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Case.isInvalid()) 4092f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 40931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 409443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the statement following the case 409560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 409643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 4097f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 40981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 409943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Attach the body to the case statement 41009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get()); 410143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 410243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 410343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 410460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 41051eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) { 410643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the statement following the default case 410760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 410843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 4109f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 41101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 411143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Default statements are always rebuilt 411243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(), 41139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubStmt.get()); 411443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 41151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 411643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 411760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 41181eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) { 411960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt()); 412043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (SubStmt.isInvalid()) 4121f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 41221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 412343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // FIXME: Pass the real colon location in. 412443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor SourceLocation ColonLoc = SemaRef.PP.getLocForEndOfToken(S->getIdentLoc()); 412543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildLabelStmt(S->getIdentLoc(), S->getID(), ColonLoc, 41261a18600b85aaa691122983dd8dcf4225cfc9ef68Argyrios Kyrtzidis SubStmt.get(), S->HasUnusedAttribute()); 412743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 41281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 412943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 413060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 41311eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIfStmt(IfStmt *S) { 413243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 413360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 41348cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor VarDecl *ConditionVar = 0; 41358cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor if (S->getConditionVariable()) { 4136c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 41378cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor = cast_or_null<VarDecl>( 4138aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 4139aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 4140aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 41418cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor if (!ConditionVar) 4142f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 414399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 41448cfe5a784133d90bf329fd20801824a6f71bb8caDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 4145c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 414699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 4147f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4148eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 4149eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor // Convert the condition to a boolean value. 4150afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 41518491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getIfLoc(), 41528491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 4153afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 4154f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4155eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 41569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE.get(); 4157afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 415899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 4159c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 41609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 41619ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 4162f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4163eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 416443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the "then" branch. 416560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Then = getDerived().TransformStmt(S->getThen()); 416643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Then.isInvalid()) 4167f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 41681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 416943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the "else" branch. 417060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Else = getDerived().TransformStmt(S->getElse()); 417143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Else.isInvalid()) 4172f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 41731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 417443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 41759ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 417699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor ConditionVar == S->getConditionVariable() && 417743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Then.get() == S->getThen() && 417843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Else.get() == S->getElse()) 41793fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 41801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4181eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar, 418244aa1f397855f130e88e62ffc1029f7f83bb5d2eArgyrios Kyrtzidis Then.get(), 41839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall S->getElseLoc(), Else.get()); 418443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 418543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 418643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 418760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 41881eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) { 418943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition. 419060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 4191d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor VarDecl *ConditionVar = 0; 4192d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor if (S->getConditionVariable()) { 4193c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 4194d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor = cast_or_null<VarDecl>( 4195aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 4196aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 4197aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 4198d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor if (!ConditionVar) 4199f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 420099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 4201d3d5301c44138b92bf01286183f5bf310cdd37cfDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 4202c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 420399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 4204f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 420599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 42061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 420743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Rebuild the switch statement. 420860d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Switch 42099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(), 4210586596fd7f7a336a2847b300c80614dcf39ab6d5Douglas Gregor ConditionVar); 421143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Switch.isInvalid()) 4212f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 42131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 421443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body of the switch statement. 421560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 421643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 4217f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 42181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 421943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Complete the switch statement. 42209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(), 42219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 422243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 42231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 422443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 422560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 42261eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) { 422743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 422860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 42295656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor VarDecl *ConditionVar = 0; 42305656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor if (S->getConditionVariable()) { 4231c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 42325656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor = cast_or_null<VarDecl>( 4233aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 4234aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 4235aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 42365656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor if (!ConditionVar) 4237f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 423899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 42395656e14d91405417182171a705ed3e3d2d6d7aa3Douglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 4240c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 424199e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 4242f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4243afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 4244afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 4245afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor // Convert the condition to a boolean value. 42468491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getWhileLoc(), 42478491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 4248afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 4249f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 42509ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE; 4251afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 425299e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 42531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42549ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 42559ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 4256f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4257eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 425843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 425960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 426043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 4261f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 42621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 426343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 42649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 426599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor ConditionVar == S->getConditionVariable() && 426643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 42679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return Owned(S); 42681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4269eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond, 42709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ConditionVar, Body.get()); 427143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 42721eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 427343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 427460d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 427543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformDoStmt(DoStmt *S) { 427643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 427760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 427843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 4279f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 42801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4281eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor // Transform the condition 428260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(S->getCond()); 4283eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor if (Cond.isInvalid()) 4284f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4285eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 428643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 428743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Cond.get() == S->getCond() && 428843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 42893fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 42901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 42919ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(), 42929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall /*FIXME:*/S->getWhileLoc(), Cond.get(), 429343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getRParenLoc()); 429443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 42951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 429643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 429760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 42981eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformForStmt(ForStmt *S) { 429943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the initialization statement 430060d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Init = getDerived().TransformStmt(S->getInit()); 430143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Init.isInvalid()) 4302f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 43031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 430443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the condition 430560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond; 430699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor VarDecl *ConditionVar = 0; 430799e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (S->getConditionVariable()) { 4308c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ConditionVar 430999e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor = cast_or_null<VarDecl>( 4310aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor getDerived().TransformDefinition( 4311aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable()->getLocation(), 4312aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor S->getConditionVariable())); 431399e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (!ConditionVar) 4314f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 431599e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } else { 431699e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor Cond = getDerived().TransformExpr(S->getCond()); 4317c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 431899e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor if (Cond.isInvalid()) 4319f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4320afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 4321afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (S->getCond()) { 4322afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor // Convert the condition to a boolean value. 43238491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor ExprResult CondE = getSema().ActOnBooleanCondition(0, S->getForLoc(), 43248491ffe86c50241b47c6d7ef8cd9ee00f5e675daDouglas Gregor Cond.get()); 4325afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor if (CondE.isInvalid()) 4326f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4327afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor 43289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond = CondE.get(); 4329afa0fefb573f74ac7836daf1601c214eda946212Douglas Gregor } 433099e9b4d172f6877e6ba5ebe75bb8238721f5e01cDouglas Gregor } 43311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 43329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.take())); 43339ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!S->getConditionVariable() && S->getCond() && !FullCond.get()) 4334f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4335eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 433643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the increment 433760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Inc = getDerived().TransformExpr(S->getInc()); 433843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Inc.isInvalid()) 4339f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 43401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 43419ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Sema::FullExprArg FullInc(getSema().MakeFullExpr(Inc.get())); 43429ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (S->getInc() && !FullInc.get()) 4343f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4344eaa18e449bb09c1e580aa35f9606ff2ca682f4cbDouglas Gregor 434543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the body 434660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 434743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Body.isInvalid()) 4348f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 43491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 435043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 435143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Init.get() == S->getInit() && 43529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullCond.get() == S->getCond() && 435343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Inc.get() == S->getInc() && 435443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Body.get() == S->getBody()) 43553fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 43561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 435743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(), 43589ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init.get(), FullCond, ConditionVar, 43599ae2f076ca5ab1feb3ba95629099ec2319833701John McCall FullInc, S->getRParenLoc(), Body.get()); 436043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 436143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 436243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 436360d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 43641eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) { 436543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Goto statements must always be rebuilt, to resolve the label. 43661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(), 436743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getLabel()); 436843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 436943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 437043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 437160d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 43721eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) { 437360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Target = getDerived().TransformExpr(S->getTarget()); 437443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Target.isInvalid()) 4375f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 43761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 437743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 437843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Target.get() == S->getTarget()) 43793fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 438043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 438143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(), 43829ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Target.get()); 438343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 438443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 438543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 438660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 43871eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) { 43883fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 438943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 43901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 439143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 439260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 43931eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) { 43943fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 439543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 43961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 439743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 439860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 43991eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) { 440060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(S->getRetValue()); 440143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Result.isInvalid()) 4402f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 440343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 44041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // FIXME: We always rebuild the return statement because there is no way 440543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // to tell whether the return type of the function has changed. 44069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get()); 440743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 44081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 440943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 441060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 44111eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) { 441243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool DeclChanged = false; 441343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor llvm::SmallVector<Decl *, 4> Decls; 441443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (DeclStmt::decl_iterator D = S->decl_begin(), DEnd = S->decl_end(); 441543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor D != DEnd; ++D) { 4416aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor Decl *Transformed = getDerived().TransformDefinition((*D)->getLocation(), 4417aac571c68de0a7c58d92fba0057e308f0e6d115cDouglas Gregor *D); 441843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!Transformed) 4419f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 44201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 442143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Transformed != *D) 442243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor DeclChanged = true; 44231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 442443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Decls.push_back(Transformed); 442543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 44261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 442743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && !DeclChanged) 44283fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 44291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 44301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildDeclStmt(Decls.data(), Decls.size(), 443143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor S->getStartLoc(), S->getEndLoc()); 443243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 44331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 443443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 443560d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 44361eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformSwitchCase(SwitchCase *S) { 443743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor assert(false && "SwitchCase is abstract and cannot be transformed"); 44383fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 443943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 444043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 444143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 444260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 444343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformAsmStmt(AsmStmt *S) { 4444c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4445ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Constraints(getSema()); 4446ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Exprs(getSema()); 4447ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson llvm::SmallVector<IdentifierInfo *, 4> Names; 4448a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson 444960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult AsmString; 4450ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Clobbers(getSema()); 4451703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 4452703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson bool ExprsChanged = false; 4453c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4454703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the outputs. 4455703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) { 4456ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson Names.push_back(S->getOutputIdentifier(I)); 4457c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4458703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the constraint literal. 44593fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Constraints.push_back(S->getOutputConstraintLiteral(I)); 4460c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4461703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Transform the output expr. 4462703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson Expr *OutputExpr = S->getOutputExpr(I); 446360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(OutputExpr); 4464703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (Result.isInvalid()) 4465f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4466c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4467703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson ExprsChanged |= Result.get() != OutputExpr; 4468c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 44699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs.push_back(Result.get()); 4470703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 4471c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4472703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the inputs. 4473703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) { 4474ff93dbd887e40588ed55d135037bb9287488b285Anders Carlsson Names.push_back(S->getInputIdentifier(I)); 4475c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4476703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the constraint literal. 44773fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Constraints.push_back(S->getInputConstraintLiteral(I)); 4478c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4479703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Transform the input expr. 4480703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson Expr *InputExpr = S->getInputExpr(I); 448160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result = getDerived().TransformExpr(InputExpr); 4482703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (Result.isInvalid()) 4483f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4484c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4485703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson ExprsChanged |= Result.get() != InputExpr; 4486c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 44879ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Exprs.push_back(Result.get()); 4488703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson } 4489c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4490703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson if (!getDerived().AlwaysRebuild() && !ExprsChanged) 44913fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 4492703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 4493703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // Go through the clobbers. 4494703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I) 44953fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall Clobbers.push_back(S->getClobber(I)); 4496703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 4497703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson // No need to transform the asm string literal. 4498703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson AsmString = SemaRef.Owned(S->getAsmString()); 4499703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson 4500703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson return getDerived().RebuildAsmStmt(S->getAsmLoc(), 4501703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isSimple(), 4502703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isVolatile(), 4503703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getNumOutputs(), 4504703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getNumInputs(), 4505a5a79f7d16b48d3be8bcc8c7650e31aefd92b657Anders Carlsson Names.data(), 4506703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson move_arg(Constraints), 4507703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson move_arg(Exprs), 45089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall AsmString.get(), 4509703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson move_arg(Clobbers), 4510703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->getRParenLoc(), 4511703e39486689d6660e75f6b6de0068db031a51c7Anders Carlsson S->isMSAsm()); 451243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 451343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 451443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 451543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 451660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 45171eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) { 45184dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the body of the @try. 451960d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TryBody = getDerived().TransformStmt(S->getTryBody()); 45204dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (TryBody.isInvalid()) 4521f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4522c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 45238f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor // Transform the @catch statements (if present). 45248f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor bool AnyCatchChanged = false; 4525ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Stmt*> CatchStmts(SemaRef); 45268f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) { 452760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I)); 45284dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Catch.isInvalid()) 4529f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 45308f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor if (Catch.get() != S->getCatchStmt(I)) 45318f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor AnyCatchChanged = true; 45328f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor CatchStmts.push_back(Catch.release()); 45334dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 4534c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 45354dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the @finally statement (if present). 453660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Finally; 45374dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (S->getFinallyStmt()) { 45384dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Finally = getDerived().TransformStmt(S->getFinallyStmt()); 45394dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Finally.isInvalid()) 4540f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 45414dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor } 45424dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 45434dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // If nothing changed, just retain this statement. 45444dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (!getDerived().AlwaysRebuild() && 45454dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor TryBody.get() == S->getTryBody() && 45468f5e3dd32e443768d9dbbad7191e123e6733750cDouglas Gregor !AnyCatchChanged && 45474dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Finally.get() == S->getFinallyStmt()) 45483fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 4549c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 45504dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Build a new statement. 45519ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(), 45529ae2f076ca5ab1feb3ba95629099ec2319833701John McCall move_arg(CatchStmts), Finally.get()); 455343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 45541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 455543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 455660d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 45571eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) { 4558be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor // Transform the @catch parameter, if there is one. 4559be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor VarDecl *Var = 0; 4560be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (VarDecl *FromVar = S->getCatchParamDecl()) { 4561be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TypeSourceInfo *TSInfo = 0; 4562be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (FromVar->getTypeSourceInfo()) { 4563be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo()); 4564be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (!TSInfo) 4565f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4566be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 4567c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4568be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor QualType T; 4569be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (TSInfo) 4570be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor T = TSInfo->getType(); 4571be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor else { 4572be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor T = getDerived().TransformType(FromVar->getType()); 4573be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (T.isNull()) 4574f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4575be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 4576c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4577be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T); 4578be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (!Var) 4579f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4580be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor } 4581c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 458260d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getCatchBody()); 4583be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor if (Body.isInvalid()) 4584f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4585c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4586c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(), 4587be270a0fae647ae3fb4d6a21ba1ea5ab9c40853aDouglas Gregor S->getRParenLoc(), 45889ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Var, Body.get()); 458943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 45901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 459143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 459260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 45931eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) { 45944dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Transform the body. 459560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getFinallyBody()); 45964dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (Body.isInvalid()) 4597f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4598c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 45994dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // If nothing changed, just retain this statement. 46004dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor if (!getDerived().AlwaysRebuild() && 46014dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor Body.get() == S->getFinallyBody()) 46023fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 46034dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor 46044dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor // Build a new statement. 46054dfdd1b5eb49999e3871f92310f2c53e1739f4f4Douglas Gregor return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(), 46069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 460743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 46081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 460943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 461060d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 46111eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) { 461260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Operand; 4613d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (S->getThrowExpr()) { 4614d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor Operand = getDerived().TransformExpr(S->getThrowExpr()); 4615d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (Operand.isInvalid()) 4616f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4617d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor } 4618c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4619d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor if (!getDerived().AlwaysRebuild() && 4620d1377b25a36adfe6604f78cbd3a23a07cf0f29e6Douglas Gregor Operand.get() == S->getThrowExpr()) 46213fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return getSema().Owned(S); 4622c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 46239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get()); 462443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 46251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 462643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 462760d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 462843959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCAtSynchronizedStmt( 46291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCAtSynchronizedStmt *S) { 46308fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Transform the object we are locking. 463160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Object = getDerived().TransformExpr(S->getSynchExpr()); 46328fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (Object.isInvalid()) 4633f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4634c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 46358fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Transform the body. 463660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getSynchBody()); 46378fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (Body.isInvalid()) 4638f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4639c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 46408fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // If nothing change, just retain the current statement. 46418fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor if (!getDerived().AlwaysRebuild() && 46428fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor Object.get() == S->getSynchExpr() && 46438fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor Body.get() == S->getSynchBody()) 46443fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 46458fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor 46468fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor // Build a new statement. 46478fdc13a78a43f09ac396e682c35d57ca0b48216dDouglas Gregor return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(), 46489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Object.get(), Body.get()); 464943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 465043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 465143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 465260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 465343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformObjCForCollectionStmt( 46541eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ObjCForCollectionStmt *S) { 4655c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the element statement. 465660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Element = getDerived().TransformStmt(S->getElement()); 4657c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Element.isInvalid()) 4658f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4659c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4660c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the collection expression. 466160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Collection = getDerived().TransformExpr(S->getCollection()); 4662c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Collection.isInvalid()) 4663f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4664c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4665c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Transform the body. 466660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Body = getDerived().TransformStmt(S->getBody()); 4667c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (Body.isInvalid()) 4668f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 4669c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4670c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // If nothing changed, just retain this statement. 4671c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor if (!getDerived().AlwaysRebuild() && 4672c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Element.get() == S->getElement() && 4673c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Collection.get() == S->getCollection() && 4674c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor Body.get() == S->getBody()) 46753fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 4676c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4677c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor // Build a new statement. 4678c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(), 4679c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor /*FIXME:*/S->getForLoc(), 46809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Element.get(), 46819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Collection.get(), 4682c3203e7ee1464a096f341c2e2a83a10be2da000aDouglas Gregor S->getRParenLoc(), 46839ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Body.get()); 468443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 468543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 468643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 468743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 468860d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 468943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) { 469043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the exception declaration, if any. 469143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor VarDecl *Var = 0; 469243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (S->getExceptionDecl()) { 469343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor VarDecl *ExceptionDecl = S->getExceptionDecl(); 469483cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor TypeSourceInfo *T = getDerived().TransformType( 469583cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor ExceptionDecl->getTypeSourceInfo()); 469683cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor if (!T) 4697f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 46981eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 469983cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor Var = getDerived().RebuildExceptionDecl(ExceptionDecl, T, 470043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor ExceptionDecl->getIdentifier(), 470183cb94269015bf2770ade71e616c5322ea7e76e1Douglas Gregor ExceptionDecl->getLocation()); 4702ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor if (!Var || Var->isInvalidDecl()) 4703f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 470443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 47051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 470643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the actual exception handler. 470760d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock()); 4708ff331c15729f7d4439d253c97f4d60f2a7ffd0c6Douglas Gregor if (Handler.isInvalid()) 4709f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 47101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 471143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 471243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !Var && 471343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Handler.get() == S->getHandlerBlock()) 47143fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 471543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 471643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), 471743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Var, 47189ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Handler.get()); 471943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 47201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 472143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregortemplate<typename Derived> 472260d7b3a319d84d688752be3870615ac0f111fb16John McCallStmtResult 472343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas GregorTreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) { 472443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the try block itself. 472560d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult TryBlock 472643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor = getDerived().TransformCompoundStmt(S->getTryBlock()); 472743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (TryBlock.isInvalid()) 4728f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 47291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 473043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // Transform the handlers. 473143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor bool HandlerChanged = false; 4732ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Stmt*> Handlers(SemaRef); 473343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) { 473460d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult Handler 473543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor = getDerived().TransformCXXCatchStmt(S->getHandler(I)); 473643959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (Handler.isInvalid()) 4737f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return StmtError(); 47381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 473943959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I); 474043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor Handlers.push_back(Handler.takeAs<Stmt>()); 474143959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor } 47421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 474343959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor if (!getDerived().AlwaysRebuild() && 474443959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor TryBlock.get() == S->getTryBlock() && 474543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor !HandlerChanged) 47463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(S); 474743959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor 47489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(), 47491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump move_arg(Handlers)); 475043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor} 47511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 475243959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor//===----------------------------------------------------------------------===// 4753b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Expression transformation 4754577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor//===----------------------------------------------------------------------===// 47551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 475660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 4757454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) { 47583fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 47591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump} 47601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 47611eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 476260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 4763454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) { 4764a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor NestedNameSpecifier *Qualifier = 0; 4765a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (E->getQualifier()) { 4766a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), 4767edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor E->getQualifierRange()); 4768a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor if (!Qualifier) 4769f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 4770a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 4771dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 4772dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall ValueDecl *ND 47737c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), 47747c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getDecl())); 4775b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!ND) 4776f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 47771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4778ec8045d3f0375302eadaa63deb373bacaf25a569John McCall DeclarationNameInfo NameInfo = E->getNameInfo(); 4779ec8045d3f0375302eadaa63deb373bacaf25a569John McCall if (NameInfo.getName()) { 4780ec8045d3f0375302eadaa63deb373bacaf25a569John McCall NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo); 4781ec8045d3f0375302eadaa63deb373bacaf25a569John McCall if (!NameInfo.getName()) 4782f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 4783ec8045d3f0375302eadaa63deb373bacaf25a569John McCall } 47842577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 47852577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!getDerived().AlwaysRebuild() && 4786a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor Qualifier == E->getQualifier() && 4787a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor ND == E->getDecl() && 47882577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getDecl()->getDeclName() && 4789096832c5ed5b9106fa177ebc148489760c3bc496John McCall !E->hasExplicitTemplateArgs()) { 47901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4791dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // Mark it referenced in the new context regardless. 4792dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall // FIXME: this is a bit instantiation-specific. 4793dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); 4794a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor 47953fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 4796a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor } 4797dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 4798dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TemplateArgumentListInfo TransArgs, *TemplateArgs = 0; 4799096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (E->hasExplicitTemplateArgs()) { 4800dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TemplateArgs = &TransArgs; 4801dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TransArgs.setLAngleLoc(E->getLAngleLoc()); 4802dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall TransArgs.setRAngleLoc(E->getRAngleLoc()); 4803fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 4804fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 4805fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 4806fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 4807dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall } 4808dbd872f273a8dbf22e089b3def6c09f0a460965dJohn McCall 4809a2813cec2605ce7878d1b13471d685f689b251afDouglas Gregor return getDerived().RebuildDeclRefExpr(Qualifier, E->getQualifierRange(), 48102577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ND, NameInfo, TemplateArgs); 4811577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 48121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4813b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 481460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 4815454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) { 48163fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 4817577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 48181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4819b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 482060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 4821454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) { 48223fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 4823b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 48241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4825b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 482660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 4827454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) { 48283fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 4829b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 48301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 48311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 483260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 4833454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) { 48343fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 4835b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 48361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4837b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 483860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 4839454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) { 48403fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 4841b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 48421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4843b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 484460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 4845454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenExpr(ParenExpr *E) { 484660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 4847b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 4848f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 48491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4850b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) 48513fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 48521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 48539ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(), 4854b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParen()); 4855b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 4856b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 48571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 485860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 4859454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) { 486060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 4861b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 4862f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 48631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4864b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr()) 48653fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 48661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4867b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildUnaryOperator(E->getOperatorLoc(), 4868b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOpcode(), 48699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get()); 4870b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 48711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4872b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 487360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 48748ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas GregorTreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) { 48758ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Transform the type. 48768ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo()); 48778ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (!Type) 4878f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 4879c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 48808ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Transform all of the components into components similar to what the 48818ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // parser uses. 4882c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // FIXME: It would be slightly more efficient in the non-dependent case to 4883c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // just map FieldDecls, rather than requiring the rebuilder to look for 4884c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt // the fields again. However, __builtin_offsetof is rare enough in 48858ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // template code that we don't care. 48868ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor bool ExprChanged = false; 4887f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall typedef Sema::OffsetOfComponent Component; 48888ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor typedef OffsetOfExpr::OffsetOfNode Node; 48898ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor llvm::SmallVector<Component, 4> Components; 48908ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) { 48918ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor const Node &ON = E->getComponent(I); 48928ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Component Comp; 489372be24f39c162448e53dd73cf57cc6357114361eDouglas Gregor Comp.isBrackets = true; 48948ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.LocStart = ON.getRange().getBegin(); 48958ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.LocEnd = ON.getRange().getEnd(); 48968ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor switch (ON.getKind()) { 48978ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Array: { 48988ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex()); 489960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Index = getDerived().TransformExpr(FromIndex); 49008ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (Index.isInvalid()) 4901f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 4902c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 49038ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor ExprChanged = ExprChanged || Index.get() != FromIndex; 49048ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.isBrackets = true; 49059ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Comp.U.E = Index.get(); 49068ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor break; 49078ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 4908c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 49098ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Field: 49108ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor case Node::Identifier: 49118ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.isBrackets = false; 49128ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Comp.U.IdentInfo = ON.getFieldName(); 491329d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor if (!Comp.U.IdentInfo) 491429d2fd56b5eeeb52f7fdbdd232229e570c30d62bDouglas Gregor continue; 4915c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 49168ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor break; 4917c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 4918cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor case Node::Base: 4919cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor // Will be recomputed during the rebuild. 4920cc8a5d5f90bbbbcb46f342117b851b7e07ec34f1Douglas Gregor continue; 49218ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 4922c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 49238ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Components.push_back(Comp); 49248ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor } 4925c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 49268ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // If nothing changed, retain the existing expression. 49278ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor if (!getDerived().AlwaysRebuild() && 49288ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Type == E->getTypeSourceInfo() && 49298ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor !ExprChanged) 49303fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 4931c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 49328ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor // Build a new offsetof expression. 49338ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type, 49348ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor Components.data(), Components.size(), 49358ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor E->getRParenLoc()); 49367cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall} 49377cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall 49387cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCalltemplate<typename Derived> 49397cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallExprResult 49407cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCallTreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) { 49417cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall assert(getDerived().AlreadyTransformed(E->getType()) && 49427cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall "opaque value expression requires transformation"); 49437cd7d1ad33fdf49eef83942e8855fe20d95aa1b9John McCall return SemaRef.Owned(E); 49448ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor} 49458ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregor 49468ecdb65716cd7914ffb2eeee993fa9039fcd31e8Douglas Gregortemplate<typename Derived> 494760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 4948454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformSizeOfAlignOfExpr(SizeOfAlignOfExpr *E) { 4949b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->isArgumentType()) { 4950a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *OldT = E->getArgumentTypeInfo(); 49515557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor 4952a93c934af4fbf97cbe8e649d82e68ccacfe57c95John McCall TypeSourceInfo *NewT = getDerived().TransformType(OldT); 49535ab75172051a6d2ea71a80a79e81c65519fd3462John McCall if (!NewT) 4954f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 49551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49565ab75172051a6d2ea71a80a79e81c65519fd3462John McCall if (!getDerived().AlwaysRebuild() && OldT == NewT) 49573fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 49581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49595ab75172051a6d2ea71a80a79e81c65519fd3462John McCall return getDerived().RebuildSizeOfAlignOf(NewT, E->getOperatorLoc(), 49601eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump E->isSizeOf(), 4961b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getSourceRange()); 4962b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 49631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 496460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr; 49651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump { 4966b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // C++0x [expr.sizeof]p1: 4967b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // The operand is either an expression, which is an unevaluated operand 4968b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // [...] 4969f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 49701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4971b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr = getDerived().TransformExpr(E->getArgumentExpr()); 4972b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 4973f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 49741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4975b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr()) 49763fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 4977b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 49781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49799ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildSizeOfAlignOf(SubExpr.get(), E->getOperatorLoc(), 4980b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isSizeOf(), 4981b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getSourceRange()); 4982b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 49831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4984b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 498560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 4986454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) { 498760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 4988b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 4989f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 49901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 499160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 4992b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 4993f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 49941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 49951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 4996b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 4997b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 4998b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 49993fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 50001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 50019ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildArraySubscriptExpr(LHS.get(), 5002b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLHS()->getLocStart(), 50039ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get(), 5004b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRBracketLoc()); 5005b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 50061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 50071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 500860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5009454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCallExpr(CallExpr *E) { 5010b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the callee. 501160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 5012b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Callee.isInvalid()) 5013f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5014b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 5015b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform arguments. 5016b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgChanged = false; 5017ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 5018aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 5019aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgChanged)) 5020aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 5021aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 5022b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5023b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Callee.get() == E->getCallee() && 5024b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgChanged) 50253fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 50261eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5027b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Wrong source location information for the '('. 50281eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeLParenLoc 5029b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = ((Expr *)Callee.get())->getSourceRange().getBegin(); 50309ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc, 5031b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Args), 5032b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 5033b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 50341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 50351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 503660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5037454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) { 503860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 5039b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Base.isInvalid()) 5040f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 50411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 504283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor NestedNameSpecifier *Qualifier = 0; 504383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor if (E->hasQualifier()) { 50441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Qualifier 504583f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor = getDerived().TransformNestedNameSpecifier(E->getQualifier(), 5046edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor E->getQualifierRange()); 5047c4bf26fbdff42967d660f505a83f75a4df2cc752Douglas Gregor if (Qualifier == 0) 5048f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 504983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor } 50501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5051f595cc41c4d95fe323f8a2b209523de9956f874dEli Friedman ValueDecl *Member 50527c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(), 50537c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getMemberDecl())); 5054b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Member) 5055f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 50561eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 50576bb8017bb9e828d118e15e59d71c66bba323c364John McCall NamedDecl *FoundDecl = E->getFoundDecl(); 50586bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (FoundDecl == E->getMemberDecl()) { 50596bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl = Member; 50606bb8017bb9e828d118e15e59d71c66bba323c364John McCall } else { 50616bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl = cast_or_null<NamedDecl>( 50626bb8017bb9e828d118e15e59d71c66bba323c364John McCall getDerived().TransformDecl(E->getMemberLoc(), FoundDecl)); 50636bb8017bb9e828d118e15e59d71c66bba323c364John McCall if (!FoundDecl) 5064f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 50656bb8017bb9e828d118e15e59d71c66bba323c364John McCall } 50666bb8017bb9e828d118e15e59d71c66bba323c364John McCall 5067b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5068b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Base.get() == E->getBase() && 506983f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor Qualifier == E->getQualifier() && 50708a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor Member == E->getMemberDecl() && 50716bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl == E->getFoundDecl() && 5072096832c5ed5b9106fa177ebc148489760c3bc496John McCall !E->hasExplicitTemplateArgs()) { 5073c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 50741f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson // Mark it referenced in the new context regardless. 50751f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson // FIXME: this is a bit instantiation-specific. 50761f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson SemaRef.MarkDeclarationReferenced(E->getMemberLoc(), Member); 50773fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 50781f24032ea28d0df9d6227e4faf89306dfa990994Anders Carlsson } 5079b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 5080d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs; 5081096832c5ed5b9106fa177ebc148489760c3bc496John McCall if (E->hasExplicitTemplateArgs()) { 5082d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TransArgs.setLAngleLoc(E->getLAngleLoc()); 5083d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TransArgs.setRAngleLoc(E->getRAngleLoc()); 5084fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 5085fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 5086fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 5087fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 50888a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor } 5089c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5090b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Bogus source location for the operator 5091b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeOperatorLoc 5092b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd()); 5093b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 5094c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // FIXME: to do this check properly, we will need to preserve the 5095c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // first-qualifier-in-scope here, just in case we had a dependent 5096c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // base (and therefore couldn't do the check) and a 5097c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // nested-name-qualifier (and therefore could do the lookup). 5098c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall NamedDecl *FirstQualifierInScope = 0; 5099c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 51009ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc, 5101b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrow(), 510283f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor Qualifier, 510383f6faf37d9bf58986bedc9bc0ea897a56b4dbadDouglas Gregor E->getQualifierRange(), 51042577743c5650c646fb705df01403707e94f2df04Abramo Bagnara E->getMemberNameInfo(), 51058a4386b3634065b96d08f94736bc1f953e385f50Douglas Gregor Member, 51066bb8017bb9e828d118e15e59d71c66bba323c364John McCall FoundDecl, 5107096832c5ed5b9106fa177ebc148489760c3bc496John McCall (E->hasExplicitTemplateArgs() 5108d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall ? &TransArgs : 0), 5109c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall FirstQualifierInScope); 5110b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 51111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5112b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 511360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5114454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) { 511560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 5116b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 5117f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 51181eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 511960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 5120b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 5121f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 51221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5123b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5124b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 5125b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 51263fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 51271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5128b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(), 51299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), RHS.get()); 5130b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 5131b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 51321eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 513360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5134b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCompoundAssignOperator( 5135454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CompoundAssignOperator *E) { 5136454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformBinaryOperator(E); 5137b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 51381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5139b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 514060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5141454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) { 514260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(E->getCond()); 5143b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Cond.isInvalid()) 5144f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 51451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 514660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 5147b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 5148f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 51491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 515060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 5151b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 5152f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 51531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5154b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5155b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Cond.get() == E->getCond() && 5156b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 5157b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 51583fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 51591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 51609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildConditionalOperator(Cond.get(), 516147e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor E->getQuestionLoc(), 51629ae2f076ca5ab1feb3ba95629099ec2319833701John McCall LHS.get(), 516347e1f7c68bf375cac470fdb2b599ddbb395aeb52Douglas Gregor E->getColonLoc(), 51649ae2f076ca5ab1feb3ba95629099ec2319833701John McCall RHS.get()); 5165b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 51661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 51671eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 516860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5169454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) { 5170a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor // Implicit casts are eliminated during transformation, since they 5171a88cfbfac9bbcbb9858f048d6d73a48711d8e93dDouglas Gregor // will be recomputed by semantic analysis after transformation. 51726eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor return getDerived().TransformExpr(E->getSubExprAsWritten()); 5173b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 51741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5175b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 517660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5177454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) { 5178ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 5179ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 5180ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 5181ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor 518260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 51836eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 5184b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 5185f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 51861eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5187b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5188ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 5189b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 51903fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 51911eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 51929d125033a9853f3b572a4c9e2f9e2d4e5e346973John McCall return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(), 5193ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type, 5194b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc(), 51959ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get()); 5196b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 51971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5198b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 519960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5200454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) { 520142f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *OldT = E->getTypeSourceInfo(); 520242f56b50062cd3b3c6b23fdb9053578ae9145664John McCall TypeSourceInfo *NewT = getDerived().TransformType(OldT); 520342f56b50062cd3b3c6b23fdb9053578ae9145664John McCall if (!NewT) 5204f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 52051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 520660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Init = getDerived().TransformExpr(E->getInitializer()); 5207b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Init.isInvalid()) 5208f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 52091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5210b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 521142f56b50062cd3b3c6b23fdb9053578ae9145664John McCall OldT == NewT && 5212b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Init.get() == E->getInitializer()) 52133fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5214b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 52151d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // Note: the expression type doesn't necessarily match the 52161d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // type-as-written, but that's okay, because it should always be 52171d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall // derivable from the initializer. 52181d7d8d66eff7ed0f3e957d330930cc9ab8047addJohn McCall 521942f56b50062cd3b3c6b23fdb9053578ae9145664John McCall return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT, 5220b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getInitializer()->getLocEnd(), 52219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Init.get()); 5222b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 52231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5224b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 522560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5226454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) { 522760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 5228b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Base.isInvalid()) 5229f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 52301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5231b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5232b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Base.get() == E->getBase()) 52333fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 52341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5235b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Bad source location 52361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeOperatorLoc 5237b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getBase()->getLocEnd()); 52389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc, 5239b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getAccessorLoc(), 5240b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getAccessor()); 5241b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 52421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5243b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 524460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5245454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) { 5246b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool InitChanged = false; 52471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5248ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*, 4> Inits(SemaRef); 5249aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false, 5250aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Inits, &InitChanged)) 5251aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 5252aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 5253b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && !InitChanged) 52543fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 52551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5256b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildInitList(E->getLBraceLoc(), move_arg(Inits), 5257e48319a8a901bc915d48d02b99c62e5f2589dbd9Douglas Gregor E->getRBraceLoc(), E->getType()); 5258b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 52591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5260b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 526160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5262454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) { 5263b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Designation Desig; 52641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 526543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transform the initializer value 526660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Init = getDerived().TransformExpr(E->getInit()); 5267b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Init.isInvalid()) 5268f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 52691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 527043959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transform the designators. 5271ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*, 4> ArrayExprs(SemaRef); 5272b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ExprChanged = false; 5273b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor for (DesignatedInitExpr::designators_iterator D = E->designators_begin(), 5274b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor DEnd = E->designators_end(); 5275b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D != DEnd; ++D) { 5276b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (D->isFieldDesignator()) { 5277b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Desig.AddDesignator(Designator::getField(D->getFieldName(), 5278b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getDotLoc(), 5279b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getFieldLoc())); 5280b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor continue; 5281b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 52821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5283b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (D->isArrayDesignator()) { 528460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D)); 5285b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Index.isInvalid()) 5286f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 52871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 52881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Desig.AddDesignator(Designator::getArray(Index.get(), 5289b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getLBracketLoc())); 52901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5291b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D); 5292b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(Index.release()); 5293b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor continue; 5294b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 52951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5296b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor assert(D->isArrayRangeDesignator() && "New kind of designator?"); 529760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Start 5298b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = getDerived().TransformExpr(E->getArrayRangeStart(*D)); 5299b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Start.isInvalid()) 5300f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 53011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 530260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D)); 5303b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (End.isInvalid()) 5304f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 53051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 53061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump Desig.AddDesignator(Designator::getArrayRange(Start.get(), 5307b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor End.get(), 5308b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getLBracketLoc(), 5309b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor D->getEllipsisLoc())); 53101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5311b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) || 5312b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor End.get() != E->getArrayRangeEnd(*D); 53131eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5314b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(Start.release()); 5315b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArrayExprs.push_back(End.release()); 5316b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 53171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5318b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5319b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Init.get() == E->getInit() && 5320b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ExprChanged) 53213fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 53221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5323b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildDesignatedInitExpr(Desig, move_arg(ArrayExprs), 5324b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getEqualOrColonLoc(), 53259ae2f076ca5ab1feb3ba95629099ec2319833701John McCall E->usesGNUSyntax(), Init.get()); 5326b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 53271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5328b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 532960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5330b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformImplicitValueInitExpr( 5331454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall ImplicitValueInitExpr *E) { 53325557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName()); 5333c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 53345557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor // FIXME: Will we ever have proper type location here? Will we actually 53355557b25bdbd63536f687ebb63a0bab55aa227626Douglas Gregor // need to transform the type? 5336b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor QualType T = getDerived().TransformType(E->getType()); 5337b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (T.isNull()) 5338f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 53391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5340b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5341b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T == E->getType()) 53423fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 53431eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5344b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildImplicitValueInitExpr(T); 5345b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 53461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5347b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 534860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5349454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) { 53509bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo()); 53519bcd4d4a4b9281ba3526b0e86e6d422db93a9074Douglas Gregor if (!TInfo) 5352f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 53531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 535460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 5355b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 5356f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 53571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5358b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 53592cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TInfo == E->getWrittenTypeInfo() && 5360b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 53613fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 53621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 53639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(), 53642cad900202561cdda18ea6cc51ddbf3e20e3c23aAbramo Bagnara TInfo, E->getRParenLoc()); 5365b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 5366b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 5367b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 536860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5369454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) { 5370b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 5371ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*, 4> Inits(SemaRef); 5372aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits, 5373aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 5374aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 5375aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 5376b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildParenListExpr(E->getLParenLoc(), 5377b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Inits), 5378b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 5379b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 53801eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5381b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform an address-of-label expression. 5382b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 5383b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// By default, the transformation of an address-of-label expression always 5384b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// rebuilds the expression, so that the label identifier can be resolved to 5385b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// the corresponding label statement by semantic analysis. 5386b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 538760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5388454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) { 5389b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(), 5390b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLabel()); 5391b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 53921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 53931eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 539460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5395454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) { 539660d7b3a319d84d688752be3870615ac0f111fb16John McCall StmtResult SubStmt 5397b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = getDerived().TransformCompoundStmt(E->getSubStmt(), true); 5398b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubStmt.isInvalid()) 5399f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 54001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5401b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5402b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubStmt.get() == E->getSubStmt()) 54033fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 54041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 54051eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildStmtExpr(E->getLParenLoc(), 54069ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubStmt.get(), 5407b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 5408b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 54091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5410b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 541160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5412454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) { 541360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Cond = getDerived().TransformExpr(E->getCond()); 5414b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Cond.isInvalid()) 5415f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 54161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 541760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult LHS = getDerived().TransformExpr(E->getLHS()); 5418b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (LHS.isInvalid()) 5419f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 54201eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 542160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult RHS = getDerived().TransformExpr(E->getRHS()); 5422b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (RHS.isInvalid()) 5423f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 54241eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5425b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5426b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Cond.get() == E->getCond() && 5427b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor LHS.get() == E->getLHS() && 5428b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor RHS.get() == E->getRHS()) 54293fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 54301eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5431b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildChooseExpr(E->getBuiltinLoc(), 54329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Cond.get(), LHS.get(), RHS.get(), 5433b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 5434b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 54351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5436b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 543760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5438454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) { 54393fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5440b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 5441b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 5442b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 544360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5444454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) { 5445668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor switch (E->getOperator()) { 5446668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_New: 5447668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Delete: 5448668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Array_New: 5449668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Array_Delete: 5450668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr"); 5451f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5452c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5453668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Call: { 5454668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // This is a call to an object's operator(). 5455668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor assert(E->getNumArgs() >= 1 && "Object call is missing arguments"); 5456668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 5457668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Transform the object itself. 545860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Object = getDerived().TransformExpr(E->getArg(0)); 5459668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor if (Object.isInvalid()) 5460f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5461668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 5462668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // FIXME: Poor location information 5463668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor SourceLocation FakeLParenLoc 5464668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor = SemaRef.PP.getLocForEndOfToken( 5465668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor static_cast<Expr *>(Object.get())->getLocEnd()); 5466668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 5467668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Transform the call arguments. 5468ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 5469aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true, 5470aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args)) 5471aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 5472668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 54739ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc, 5474668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor move_arg(Args), 5475668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor E->getLocEnd()); 5476668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor } 5477668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 5478668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \ 5479668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_##Name: 5480668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly) 5481668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor#include "clang/Basic/OperatorKinds.def" 5482668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Subscript: 5483668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor // Handled below. 5484668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor break; 5485668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 5486668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_Conditional: 5487668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("conditional operator is not actually overloadable"); 5488f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5489668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 5490668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case OO_None: 5491668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor case NUM_OVERLOADED_OPERATORS: 5492668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor llvm_unreachable("not an overloaded operator?"); 5493f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5494668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor } 5495668d6d9dc100b3ef28a9b8e6fe987c2f5b6edcc9Douglas Gregor 549660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Callee = getDerived().TransformExpr(E->getCallee()); 5497b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Callee.isInvalid()) 5498f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 54991eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 550060d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult First = getDerived().TransformExpr(E->getArg(0)); 5501b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (First.isInvalid()) 5502f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5503b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 550460d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Second; 5505b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->getNumArgs() == 2) { 5506b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Second = getDerived().TransformExpr(E->getArg(1)); 5507b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Second.isInvalid()) 5508f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5509b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 55101eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5511b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5512b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Callee.get() == E->getCallee() && 5513b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor First.get() == E->getArg(0) && 55141eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump (E->getNumArgs() != 2 || Second.get() == E->getArg(1))) 55153fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 55161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5517b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(), 5518b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOperatorLoc(), 55199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Callee.get(), 55209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall First.get(), 55219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Second.get()); 5522b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 55231eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5524b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 552560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5526454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) { 5527454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCallExpr(E); 5528b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 55291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5530b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 553160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5532454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) { 5533ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 5534ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 5535ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 5536ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor 553760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 55386eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 5539b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 5540f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 55411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5542b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5543ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 5544b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 55453fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 55461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5547b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: Poor source location information here. 55481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SourceLocation FakeLAngleLoc 5549b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken(E->getOperatorLoc()); 5550b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeRAngleLoc = E->getSubExpr()->getSourceRange().getBegin(); 5551b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation FakeRParenLoc 5552b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.PP.getLocForEndOfToken( 5553b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getSubExpr()->getSourceRange().getEnd()); 5554b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXNamedCastExpr(E->getOperatorLoc(), 55551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump E->getStmtClass(), 5556b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeLAngleLoc, 5557ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type, 5558b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRAngleLoc, 5559b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRAngleLoc, 55609ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 5561b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor FakeRParenLoc); 5562b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 55631eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5564b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 556560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5566454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) { 5567454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 5568b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 55691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5570b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 557160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5572454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) { 5573454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 5574b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 55751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5576b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 557760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5578b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXReinterpretCastExpr( 5579454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXReinterpretCastExpr *E) { 5580454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 5581b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 55821eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5583b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 558460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5585454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) { 5586454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall return getDerived().TransformCXXNamedCastExpr(E); 5587b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 55881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5589b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 559060d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5591b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXFunctionalCastExpr( 5592454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXFunctionalCastExpr *E) { 5593ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten()); 5594ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!Type) 5595ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return ExprError(); 55961eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 559760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr 55986eef519fc8a97bb7ca6066f23d35e10f06b2c1b5Douglas Gregor = getDerived().TransformExpr(E->getSubExprAsWritten()); 5599b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 5600f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 56011eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5602b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5603ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor Type == E->getTypeInfoAsWritten() && 5604b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 56053fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 56061eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5607ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor return getDerived().RebuildCXXFunctionalCastExpr(Type, 5608b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getSubExpr()->getLocStart(), 56099ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 5610b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 5611b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 56121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5613b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 561460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5615454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) { 5616b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (E->isTypeOperand()) { 561757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TypeSourceInfo *TInfo 561857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor = getDerived().TransformType(E->getTypeOperandSourceInfo()); 561957fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor if (!TInfo) 5620f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 56211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5622b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 562357fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TInfo == E->getTypeOperandSourceInfo()) 56243fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 56251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 562657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return getDerived().RebuildCXXTypeidExpr(E->getType(), 562757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor E->getLocStart(), 562857fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor TInfo, 5629b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 5630b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 56311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5632b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // We don't know whether the expression is potentially evaluated until 5633b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // after we perform semantic analysis, so the expression is potentially 5634b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // potentially evaluated. 56351eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump EnterExpressionEvaluationContext Unevaluated(SemaRef, 5636f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall Sema::PotentiallyPotentiallyEvaluated); 56371eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 563860d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); 5639b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 5640f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 56411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5642b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5643b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getExprOperand()) 56443fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 56451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 564657fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor return getDerived().RebuildCXXTypeidExpr(E->getType(), 564757fdc8a4382164955c7b30d09f4ce46fc7e67659Douglas Gregor E->getLocStart(), 56489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SubExpr.get(), 5649b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 5650b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 5651b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 5652b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 565360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 565401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetTreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) { 565501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (E->isTypeOperand()) { 565601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TypeSourceInfo *TInfo 565701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet = getDerived().TransformType(E->getTypeOperandSourceInfo()); 565801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!TInfo) 565901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return ExprError(); 566001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 566101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!getDerived().AlwaysRebuild() && 566201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TInfo == E->getTypeOperandSourceInfo()) 56633fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 566401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 566501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getDerived().RebuildCXXTypeidExpr(E->getType(), 566601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocStart(), 566701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet TInfo, 566801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocEnd()); 566901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet } 567001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 567101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // We don't know whether the expression is potentially evaluated until 567201b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // after we perform semantic analysis, so the expression is potentially 567301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet // potentially evaluated. 567401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated); 567501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 567601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand()); 567701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (SubExpr.isInvalid()) 567801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return ExprError(); 567901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 568001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet if (!getDerived().AlwaysRebuild() && 568101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SubExpr.get() == E->getExprOperand()) 56823fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 568301b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 568401b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet return getDerived().RebuildCXXUuidofExpr(E->getType(), 568501b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocStart(), 568601b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet SubExpr.get(), 568701b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet E->getLocEnd()); 568801b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet} 568901b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichet 569001b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois Pichettemplate<typename Derived> 569101b7c3028da5bbcb9f8e52ba67e4613070de0e60Francois PichetExprResult 5692454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) { 56933fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5694b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 56951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5696b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 569760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5698b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXNullPtrLiteralExpr( 5699454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXNullPtrLiteralExpr *E) { 57003fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5701b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 57021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5703b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 570460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5705454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) { 5706ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor DeclContext *DC = getSema().getFunctionLevelDeclContext(); 5707ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(DC); 5708ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor QualType T = MD->getThisType(getSema().Context); 57091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5710ba48d6aad11a684d8557b25831764a61a37f65a2Douglas Gregor if (!getDerived().AlwaysRebuild() && T == E->getType()) 57113fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 57121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5713828a197317288e3333b0ce6f5cedadd036e3531fDouglas Gregor return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit()); 5714b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 57151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5716b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 571760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5718454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) { 571960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr()); 5720b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (SubExpr.isInvalid()) 5721f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 57221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5723b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5724b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SubExpr.get() == E->getSubExpr()) 57253fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 5726b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 57279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get()); 5728b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 57291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5730b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 573160d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5732454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) { 57331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump ParmVarDecl *Param 57347c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(), 57357c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getParam())); 5736b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Param) 5737f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 57381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 573953cb6f82c41397917b14fb8cdcb32e6c9bd07655Chandler Carruth if (!getDerived().AlwaysRebuild() && 5740b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Param == E->getParam()) 57413fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 57421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5743036aed18662e0193aafe0e8ae13d2e57efe6df25Douglas Gregor return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param); 5744b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 57451eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5746b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 574760d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5748ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas GregorTreeTransform<Derived>::TransformCXXScalarValueInitExpr( 5749ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXScalarValueInitExpr *E) { 5750ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 5751ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 5752f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5753ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor 5754b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 5755ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo()) 57563fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 57571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5758ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXScalarValueInitExpr(T, 5759ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /*FIXME:*/T->getTypeLoc().getEndLoc(), 5760ed8abf18329df67b0abcbb3a10458bd8c1d2a595Douglas Gregor E->getRParenLoc()); 5761b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 57621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5763b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 576460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5765454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) { 5766b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the type that we're allocating 57671bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor TypeSourceInfo *AllocTypeInfo 57681bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor = getDerived().TransformType(E->getAllocatedTypeSourceInfo()); 57691bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor if (!AllocTypeInfo) 5770f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 57711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5772b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the size of the array we're allocating (if any). 577360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize()); 5774b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (ArraySize.isInvalid()) 5775f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 57761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5777b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the placement arguments (if any). 5778b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 5779ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> PlacementArgs(SemaRef); 5780aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getPlacementArgs(), 5781aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor E->getNumPlacementArgs(), true, 5782aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor PlacementArgs, &ArgumentChanged)) 5783aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 57841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 578543959a93c6aba8b03b09116fe077f4ce8e80005eDouglas Gregor // transform the constructor arguments (if any). 5786ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> ConstructorArgs(SemaRef); 5787aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (TransformExprs(E->getConstructorArgs(), E->getNumConstructorArgs(), true, 5788aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor ConstructorArgs, &ArgumentChanged)) 5789aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 57901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 57911af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Transform constructor, new operator, and delete operator. 57921af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor CXXConstructorDecl *Constructor = 0; 57931af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getConstructor()) { 57941af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor Constructor = cast_or_null<CXXConstructorDecl>( 57957c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 57967c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 57971af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!Constructor) 5798f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 57991af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 58001af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor 58011af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorNew = 0; 58021af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorNew()) { 58031af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorNew = cast_or_null<FunctionDecl>( 58047c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 58057c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorNew())); 58061af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorNew) 5807f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 58081af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 58091af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor 58101af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorDelete = 0; 58111af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorDelete()) { 58121af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete = cast_or_null<FunctionDecl>( 58137c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 58147c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorDelete())); 58151af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorDelete) 5816f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 58171af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 5818c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5819b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 58201bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocTypeInfo == E->getAllocatedTypeSourceInfo() && 5821b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor ArraySize.get() == E->getArraySize() && 58221af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor Constructor == E->getConstructor() && 58231af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorNew == E->getOperatorNew() && 58241af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete == E->getOperatorDelete() && 58251af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor !ArgumentChanged) { 58261af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark any declarations we need as referenced. 58271af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: instantiation-specific. 58281af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (Constructor) 58291af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); 58301af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorNew) 58311af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorNew); 58321af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorDelete) 58331af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); 58343fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 58351af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 58361eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 58371bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor QualType AllocType = AllocTypeInfo->getType(); 58385b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (!ArraySize.get()) { 58395b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // If no array size was specified, but the new expression was 58405b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // instantiated with an array type (e.g., "new T" where T is 58415b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // instantiated with "int[4]"), extract the outer bound from the 58425b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // array type as our array size. We do this with constant and 58435b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // dependently-sized array types. 58445b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType); 58455b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (!ArrayT) { 58465b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor // Do nothing 58475b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } else if (const ConstantArrayType *ConsArrayT 58485b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor = dyn_cast<ConstantArrayType>(ArrayT)) { 5849c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt ArraySize 58509996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis = SemaRef.Owned(IntegerLiteral::Create(SemaRef.Context, 58519996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis ConsArrayT->getSize(), 58529996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis SemaRef.Context.getSizeType(), 58539996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /*FIXME:*/E->getLocStart())); 58545b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor AllocType = ConsArrayT->getElementType(); 58555b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } else if (const DependentSizedArrayType *DepArrayT 58565b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor = dyn_cast<DependentSizedArrayType>(ArrayT)) { 58575b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor if (DepArrayT->getSizeExpr()) { 58583fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall ArraySize = SemaRef.Owned(DepArrayT->getSizeExpr()); 58595b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor AllocType = DepArrayT->getElementType(); 58605b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 58615b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 58625b5ad8453c8e79f642c3ddfeeadf162ae67309c0Douglas Gregor } 58631bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor 5864b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXNewExpr(E->getLocStart(), 5865b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isGlobalNew(), 5866b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLocStart(), 5867b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(PlacementArgs), 5868b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLocStart(), 58694bd40318cbea15310a37343db46de96c4fcc15e6Douglas Gregor E->getTypeIdParens(), 5870b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor AllocType, 58711bb2a93ab7b1499dda6f6b58865bd0dce1864228Douglas Gregor AllocTypeInfo, 58729ae2f076ca5ab1feb3ba95629099ec2319833701John McCall ArraySize.get(), 5873b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor /*FIXME:*/E->getLocStart(), 5874b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(ConstructorArgs), 58751eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump E->getLocEnd()); 5876b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 58771eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5878b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 587960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5880454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) { 588160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Operand = getDerived().TransformExpr(E->getArgument()); 5882b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Operand.isInvalid()) 5883f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 58841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 58851af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Transform the delete operator, if known. 58861af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor FunctionDecl *OperatorDelete = 0; 58871af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (E->getOperatorDelete()) { 58881af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete = cast_or_null<FunctionDecl>( 58897c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 58907c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getOperatorDelete())); 58911af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (!OperatorDelete) 5892f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 58931af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 5894c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5895b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 58961af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor Operand.get() == E->getArgument() && 58971af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor OperatorDelete == E->getOperatorDelete()) { 58981af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark any declarations we need as referenced. 58991af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: instantiation-specific. 59001af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor if (OperatorDelete) 59011af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), OperatorDelete); 59025833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor 59035833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor if (!E->getArgument()->isTypeDependent()) { 59045833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor QualType Destroyed = SemaRef.Context.getBaseElementType( 59055833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor E->getDestroyedType()); 59065833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) { 59075833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl()); 59085833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), 59095833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor SemaRef.LookupDestructor(Record)); 59105833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor } 59115833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor } 59125833b0b831d6afae2885e6af420e2bda639652e6Douglas Gregor 59133fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 59141af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor } 59151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5916b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildCXXDeleteExpr(E->getLocStart(), 5917b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isGlobalDelete(), 5918b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrayForm(), 59199ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Operand.get()); 5920b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 59211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5922b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 592360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 5924a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas GregorTreeTransform<Derived>::TransformCXXPseudoDestructorExpr( 5925454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXPseudoDestructorExpr *E) { 592660d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 5927a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor if (Base.isInvalid()) 5928f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 59291eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5930b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectTypePtr; 5931a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor bool MayBePseudoDestructor = false; 59329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), 5933a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getOperatorLoc(), 5934a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->isArrow()? tok::arrow : tok::period, 5935a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor ObjectTypePtr, 5936a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor MayBePseudoDestructor); 5937a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (Base.isInvalid()) 5938f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5939c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5940b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall QualType ObjectType = ObjectTypePtr.get(); 594143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NestedNameSpecifier *Qualifier = E->getQualifier(); 594243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (Qualifier) { 594343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall Qualifier 594443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = getDerived().TransformNestedNameSpecifier(E->getQualifier(), 594543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall E->getQualifierRange(), 594643fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType); 594743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall if (!Qualifier) 594843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return ExprError(); 594943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall } 59501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 5951a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed; 5952a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (E->getDestroyedTypeInfo()) { 5953a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor TypeSourceInfo *DestroyedTypeInfo 595443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(), 595543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ObjectType, 0, Qualifier); 5956a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (!DestroyedTypeInfo) 5957f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5958a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed = DestroyedTypeInfo; 5959a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } else if (ObjectType->isDependentType()) { 5960a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // We aren't likely to be able to resolve the identifier down to a type 5961a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // now anyway, so just retain the identifier. 5962a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(), 5963a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc()); 5964a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } else { 5965a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor // Look for a destructor known with the given name. 5966a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor CXXScopeSpec SS; 5967a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (Qualifier) { 5968a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor SS.setScopeRep(Qualifier); 5969a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor SS.setRange(E->getQualifierRange()); 5970a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 5971c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5972b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(), 5973a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor *E->getDestroyedTypeIdentifier(), 5974a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc(), 5975a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor /*Scope=*/0, 5976a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor SS, ObjectTypePtr, 5977a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor false); 5978a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor if (!T) 5979f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5980c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 5981a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed 5982a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T), 5983a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor E->getDestroyedTypeLoc()); 5984a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor } 598526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor 598626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor TypeSourceInfo *ScopeTypeInfo = 0; 598726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor if (E->getScopeTypeInfo()) { 598843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall ScopeTypeInfo = getDerived().TransformType(E->getScopeTypeInfo()); 598926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor if (!ScopeTypeInfo) 5990f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 5991a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor } 5992c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 59939ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(), 5994a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor E->getOperatorLoc(), 5995a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor E->isArrow(), 5996a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor Qualifier, 599726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor E->getQualifierRange(), 599826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor ScopeTypeInfo, 599926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor E->getColonColonLoc(), 6000fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor E->getTildeLoc(), 6001a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed); 6002a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregor} 60031eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6004a71d819bb8f50c28938db0f2867d3fb6e2ce5910Douglas Gregortemplate<typename Derived> 600560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6006ba13543329afac4a0d01304ec2ec4924d99306a6John McCallTreeTransform<Derived>::TransformUnresolvedLookupExpr( 6007454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall UnresolvedLookupExpr *Old) { 6008f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall TemporaryBase Rebase(*this, Old->getNameLoc(), DeclarationName()); 6009f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 6010f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(), 6011f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall Sema::LookupOrdinaryName); 6012f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 6013f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Transform all the decls. 6014f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(), 6015f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall E = Old->decls_end(); I != E; ++I) { 60167c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor NamedDecl *InstD = static_cast<NamedDecl*>( 60177c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(Old->getNameLoc(), 60187c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor *I)); 60199f54ad4381370c6b771424b53d219e661d6d6706John McCall if (!InstD) { 60209f54ad4381370c6b771424b53d219e661d6d6706John McCall // Silently ignore these if a UsingShadowDecl instantiated to nothing. 60219f54ad4381370c6b771424b53d219e661d6d6706John McCall // This can happen because of dependent hiding. 60229f54ad4381370c6b771424b53d219e661d6d6706John McCall if (isa<UsingShadowDecl>(*I)) 60239f54ad4381370c6b771424b53d219e661d6d6706John McCall continue; 60249f54ad4381370c6b771424b53d219e661d6d6706John McCall else 6025f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 60269f54ad4381370c6b771424b53d219e661d6d6706John McCall } 6027f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 6028f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Expand using declarations. 6029f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (isa<UsingDecl>(InstD)) { 6030f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall UsingDecl *UD = cast<UsingDecl>(InstD); 6031f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall for (UsingDecl::shadow_iterator I = UD->shadow_begin(), 6032f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall E = UD->shadow_end(); I != E; ++I) 6033f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.addDecl(*I); 6034f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall continue; 6035f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 6036f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 6037f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.addDecl(InstD); 6038f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 6039f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 6040f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Resolve a kind, but don't do any further analysis. If it's 6041f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // ambiguous, the callee needs to deal with it. 6042f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall R.resolveKind(); 6043f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 6044f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // Rebuild the nested-name qualifier, if present. 6045f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall CXXScopeSpec SS; 6046f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall NestedNameSpecifier *Qualifier = 0; 6047f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (Old->getQualifier()) { 6048f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall Qualifier = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), 6049edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor Old->getQualifierRange()); 6050f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!Qualifier) 6051f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6052c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6053f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall SS.setScopeRep(Qualifier); 6054f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall SS.setRange(Old->getQualifierRange()); 6055c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt } 6056c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6057c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor if (Old->getNamingClass()) { 605866c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor CXXRecordDecl *NamingClass 605966c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( 606066c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNameLoc(), 606166c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNamingClass())); 606266c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor if (!NamingClass) 6063f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6064c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 606566c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor R.setNamingClass(NamingClass); 6066f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall } 6067f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 6068f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // If we have no template arguments, it's a normal declaration name. 6069f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!Old->hasExplicitTemplateArgs()) 6070f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL()); 6071f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 6072f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // If we have template arguments, rebuild them, then rebuild the 6073f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall // templateid expression. 6074f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc()); 6075fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), 6076fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor Old->getNumTemplateArgs(), 6077fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 6078fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 6079f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall 6080f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getDerived().RebuildTemplateIdExpr(SS, R, Old->requiresADL(), 6081f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall TransArgs); 6082b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 60831eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6084b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 608560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6086454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnaryTypeTraitExpr(UnaryTypeTraitExpr *E) { 60873d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo()); 60883d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor if (!T) 6089f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 60901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6091b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 60923d37c0ada0e46b87be0a10e8d52d990a97d3907aDouglas Gregor T == E->getQueriedTypeSourceInfo()) 60933fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 60941eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 60951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildUnaryTypeTrait(E->getTrait(), 6096b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocStart(), 6097b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T, 6098b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 6099b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 61001eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6101b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 610260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 61036ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetTreeTransform<Derived>::TransformBinaryTypeTraitExpr(BinaryTypeTraitExpr *E) { 61046ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *LhsT = getDerived().TransformType(E->getLhsTypeSourceInfo()); 61056ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!LhsT) 61066ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return ExprError(); 61076ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 61086ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet TypeSourceInfo *RhsT = getDerived().TransformType(E->getRhsTypeSourceInfo()); 61096ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!RhsT) 61106ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return ExprError(); 61116ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 61126ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet if (!getDerived().AlwaysRebuild() && 61136ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet LhsT == E->getLhsTypeSourceInfo() && RhsT == E->getRhsTypeSourceInfo()) 61146ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return SemaRef.Owned(E); 61156ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 61166ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet return getDerived().RebuildBinaryTypeTrait(E->getTrait(), 61176ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet E->getLocStart(), 61186ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet LhsT, RhsT, 61196ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet E->getLocEnd()); 61206ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet} 61216ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichet 61226ad6f2848d7652ab2991286eb48be440d3493b28Francois Pichettemplate<typename Derived> 61236ad6f2848d7652ab2991286eb48be440d3493b28Francois PichetExprResult 6124865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformDependentScopeDeclRefExpr( 61252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DependentScopeDeclRefExpr *E) { 6126b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor NestedNameSpecifier *NNS 6127f17bb74e74aca9bb0525d2249041ab65c7d1fd48Douglas Gregor = getDerived().TransformNestedNameSpecifier(E->getQualifier(), 6128edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor E->getQualifierRange()); 6129b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!NNS) 6130f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 613243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // TODO: If this is a conversion-function-id, verify that the 613343fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // destination type name (if present) resolves the same way after 613443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // instantiation as it did in the local scope. 613543fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 61362577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo 61372577743c5650c646fb705df01403707e94f2df04Abramo Bagnara = getDerived().TransformDeclarationNameInfo(E->getNameInfo()); 61382577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!NameInfo.getName()) 6139f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61401eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6141f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!E->hasExplicitTemplateArgs()) { 6142f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall if (!getDerived().AlwaysRebuild() && 6143f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall NNS == E->getQualifier() && 61442577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // Note: it is sufficient to compare the Name component of NameInfo: 61452577743c5650c646fb705df01403707e94f2df04Abramo Bagnara // if name has not changed, DNLoc has not changed either. 61462577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getDeclName()) 61473fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 61481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6149f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getDerived().RebuildDependentScopeDeclRefExpr(NNS, 6150f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall E->getQualifierRange(), 61512577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 6152f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall /*TemplateArgs*/ 0); 6153f17bb74e74aca9bb0525d2249041ab65c7d1fd48Douglas Gregor } 6154d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall 6155d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); 6156fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 6157fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 6158fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 6159fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 6160b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6161f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall return getDerived().RebuildDependentScopeDeclRefExpr(NNS, 6162f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall E->getQualifierRange(), 61632577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 6164f7a1a744eba4b29ceb0f20af8f34515d892fdd64John McCall &TransArgs); 6165b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6166b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6167b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 616860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6169454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) { 6170321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor // CXXConstructExprs are always implicit, so when we have a 6171321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor // 1-argument construction we just transform that argument. 6172321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor if (E->getNumArgs() == 1 || 6173321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) 6174321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor return getDerived().TransformExpr(E->getArg(0)); 6175321725d95d331d1612ac386d7d4235eca94b0021Douglas Gregor 6176b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName()); 6177b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6178b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor QualType T = getDerived().TransformType(E->getType()); 6179b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (T.isNull()) 6180f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6181b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6182b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXConstructorDecl *Constructor 6183b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = cast_or_null<CXXConstructorDecl>( 61847c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(E->getLocStart(), 61857c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 6186b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Constructor) 6187f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 61881eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6189b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 6190ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 6191aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 6192aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 6193aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6194aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 6195b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6196b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor T == E->getType() && 6197b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Constructor == E->getConstructor() && 6198c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor !ArgumentChanged) { 61991af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // Mark the constructor as referenced. 62001af745143eb3066660d8855c17ccec6b38f5d789Douglas Gregor // FIXME: Instantiation-specific 6201c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); 62023fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6203c845aad6f7d012ab0cd0a040515ab512d1a93566Douglas Gregor } 62041eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62054411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(), 62064411d2e674b0119f682ac472c3a377f14fa9fa30Douglas Gregor Constructor, E->isElidable(), 62078c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor move_arg(Args), 62088c3e554d00d456d5093c21ce8a0c205461279aabDouglas Gregor E->requiresZeroInitialization(), 6209428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth E->getConstructionKind(), 6210428edafa9eb80e01dd40aab31d4166a787a741e1Chandler Carruth E->getParenRange()); 6211b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 62121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6213b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// \brief Transform a C++ temporary-binding expression. 6214b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 62155132655e4296b780672e9a96b46a740135073534Douglas Gregor/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just 62165132655e4296b780672e9a96b46a740135073534Douglas Gregor/// transform the subexpression and return that. 6217b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 621860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6219454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { 62205132655e4296b780672e9a96b46a740135073534Douglas Gregor return getDerived().TransformExpr(E->getSubExpr()); 6221b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 62221eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 62234765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// \brief Transform a C++ expression that contains cleanups that should 62244765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// be run after the expression is evaluated. 6225b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor/// 62264765fa05b5652fcc4356371c2f481d0ea9a1b007John McCall/// Since ExprWithCleanups nodes are implicitly generated, we 62275132655e4296b780672e9a96b46a740135073534Douglas Gregor/// just transform the subexpression and return that. 6228b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 622960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 62304765fa05b5652fcc4356371c2f481d0ea9a1b007John McCallTreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) { 62315132655e4296b780672e9a96b46a740135073534Douglas Gregor return getDerived().TransformExpr(E->getSubExpr()); 6232b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 62331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6234b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 623560d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6236b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXTemporaryObjectExpr( 6237ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor CXXTemporaryObjectExpr *E) { 6238ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 6239ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 6240f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62411eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6242b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor CXXConstructorDecl *Constructor 6243b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = cast_or_null<CXXConstructorDecl>( 6244c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt getDerived().TransformDecl(E->getLocStart(), 62457c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor E->getConstructor())); 6246b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!Constructor) 6247f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6249b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 6250ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 6251b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Args.reserve(E->getNumArgs()); 6252aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args, 6253aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 6254aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 62551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6256b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6257ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo() && 6258b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor Constructor == E->getConstructor() && 625991be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor !ArgumentChanged) { 626091be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor // FIXME: Instantiation-specific 6261ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor SemaRef.MarkDeclarationReferenced(E->getLocStart(), Constructor); 62623fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.MaybeBindToTemporary(E); 626391be6f5ccbde073e592bed9a3e3bc363957714fbDouglas Gregor } 6264ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor 6265ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXTemporaryObjectExpr(T, 6266ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor /*FIXME:*/T->getTypeLoc().getEndLoc(), 6267b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Args), 6268b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLocEnd()); 6269b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 62701eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6271b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 627260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6273b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::TransformCXXUnresolvedConstructExpr( 6274454feb9da67504b475d032ca2a9fc34c5744748eJohn McCall CXXUnresolvedConstructExpr *E) { 6275ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo()); 6276ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor if (!T) 6277f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 62781eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6279b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 6280ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 6281aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args.reserve(E->arg_size()); 6282aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args, 6283aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgumentChanged)) 6284aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6285aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 6286b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6287ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor T == E->getTypeSourceInfo() && 6288b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgumentChanged) 62893fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 62901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6291b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // FIXME: we're faking the locations of the commas 6292ab6677ec401cfd2c82b34e4cdfebd55a9dc25778Douglas Gregor return getDerived().RebuildCXXUnresolvedConstructExpr(T, 6293b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getLParenLoc(), 6294b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(Args), 6295b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6296b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 62971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6298b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 629960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6300865d447ac6a4721ab58e898d014a21f2eff74b06John McCallTreeTransform<Derived>::TransformCXXDependentScopeMemberExpr( 63012577743c5650c646fb705df01403707e94f2df04Abramo Bagnara CXXDependentScopeMemberExpr *E) { 6302b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Transform the base of the expression. 630360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base((Expr*) 0); 6304aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Expr *OldBase; 6305aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType; 6306aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType ObjectType; 6307aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!E->isImplicitAccess()) { 6308aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OldBase = E->getBase(); 6309aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base = getDerived().TransformExpr(OldBase); 6310aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 6311f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63121eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6313aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall // Start the member reference and compute the object's type. 6314b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType ObjectTy; 6315d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor bool MayBePseudoDestructor = false; 63169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Base = SemaRef.ActOnStartCXXMemberReference(0, Base.get(), 6317aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall E->getOperatorLoc(), 6318a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor E->isArrow()? tok::arrow : tok::period, 6319d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor ObjectTy, 6320d4dca08d6b7ed2e3e3718caa6fd735960b135e9aDouglas Gregor MayBePseudoDestructor); 6321aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 6322f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6323aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall 6324b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ObjectType = ObjectTy.get(); 6325aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = ((Expr*) Base.get())->getType(); 6326aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } else { 6327aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall OldBase = 0; 6328aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = getDerived().TransformType(E->getBaseType()); 6329aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall ObjectType = BaseType->getAs<PointerType>()->getPointeeType(); 6330aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 63311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63326cd219879ffce00920189ec1dcea927a42602961Douglas Gregor // Transform the first part of the nested-name-specifier that qualifies 63336cd219879ffce00920189ec1dcea927a42602961Douglas Gregor // the member name. 6334c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor NamedDecl *FirstQualifierInScope 63356cd219879ffce00920189ec1dcea927a42602961Douglas Gregor = getDerived().TransformFirstQualifierInScope( 63366cd219879ffce00920189ec1dcea927a42602961Douglas Gregor E->getFirstQualifierFoundInScope(), 63376cd219879ffce00920189ec1dcea927a42602961Douglas Gregor E->getQualifierRange().getBegin()); 63381eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6339a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor NestedNameSpecifier *Qualifier = 0; 6340a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor if (E->getQualifier()) { 6341a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor Qualifier = getDerived().TransformNestedNameSpecifier(E->getQualifier(), 6342a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor E->getQualifierRange(), 6343aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall ObjectType, 6344aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall FirstQualifierInScope); 6345a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor if (!Qualifier) 6346f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6347a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor } 63481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 634943fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // TODO: If this is a conversion-function-id, verify that the 635043fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // destination type name (if present) resolves the same way after 635143fed0de4f5bc189e45562491f83d5193eb8dac0John McCall // instantiation as it did in the local scope. 635243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall 63532577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo 635443fed0de4f5bc189e45562491f83d5193eb8dac0John McCall = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo()); 63552577743c5650c646fb705df01403707e94f2df04Abramo Bagnara if (!NameInfo.getName()) 6356f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 63571eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6358aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!E->hasExplicitTemplateArgs()) { 63593b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor // This is a reference to a member without an explicitly-specified 63603b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor // template argument list. Optimize for this common case. 63613b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor if (!getDerived().AlwaysRebuild() && 6362aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base.get() == OldBase && 6363aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType == E->getBaseType() && 63643b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor Qualifier == E->getQualifier() && 63652577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.getName() == E->getMember() && 63663b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor FirstQualifierInScope == E->getFirstQualifierFoundInScope()) 63673fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 63681eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63699ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), 6370aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 63713b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor E->isArrow(), 63723b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor E->getOperatorLoc(), 63733b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor Qualifier, 63743b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor E->getQualifierRange(), 6375129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall FirstQualifierInScope, 63762577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 6377129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall /*TemplateArgs*/ 0); 63783b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor } 63793b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor 6380d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc()); 6381fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(E->getTemplateArgs(), 6382fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor E->getNumTemplateArgs(), 6383fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 6384fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 63851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 63869ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(), 6387aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 6388b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->isArrow(), 6389b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getOperatorLoc(), 6390a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor Qualifier, 6391a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor E->getQualifierRange(), 63923b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor FirstQualifierInScope, 63932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 6394129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall &TransArgs); 6395129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall} 6396129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 6397129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCalltemplate<typename Derived> 639860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6399454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) { 6400129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Transform the base of the expression. 640160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base((Expr*) 0); 6402aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall QualType BaseType; 6403aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (!Old->isImplicitAccess()) { 6404aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall Base = getDerived().TransformExpr(Old->getBase()); 6405aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall if (Base.isInvalid()) 6406f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6407aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = ((Expr*) Base.get())->getType(); 6408aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } else { 6409aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType = getDerived().TransformType(Old->getBaseType()); 6410aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall } 6411129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 6412129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall NestedNameSpecifier *Qualifier = 0; 6413129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (Old->getQualifier()) { 6414129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Qualifier 6415129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall = getDerived().TransformNestedNameSpecifier(Old->getQualifier(), 6416edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor Old->getQualifierRange()); 6417129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (Qualifier == 0) 6418f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6419129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 6420129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 64212577743c5650c646fb705df01403707e94f2df04Abramo Bagnara LookupResult R(SemaRef, Old->getMemberNameInfo(), 6422129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Sema::LookupOrdinaryName); 6423129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 6424129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Transform all the decls. 6425129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(), 6426129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall E = Old->decls_end(); I != E; ++I) { 64277c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor NamedDecl *InstD = static_cast<NamedDecl*>( 64287c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor getDerived().TransformDecl(Old->getMemberLoc(), 64297c1e98f1cb37b40e619a0c8aee8b337f037b432bDouglas Gregor *I)); 64309f54ad4381370c6b771424b53d219e661d6d6706John McCall if (!InstD) { 64319f54ad4381370c6b771424b53d219e661d6d6706John McCall // Silently ignore these if a UsingShadowDecl instantiated to nothing. 64329f54ad4381370c6b771424b53d219e661d6d6706John McCall // This can happen because of dependent hiding. 64339f54ad4381370c6b771424b53d219e661d6d6706John McCall if (isa<UsingShadowDecl>(*I)) 64349f54ad4381370c6b771424b53d219e661d6d6706John McCall continue; 64359f54ad4381370c6b771424b53d219e661d6d6706John McCall else 6436f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 64379f54ad4381370c6b771424b53d219e661d6d6706John McCall } 6438129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 6439129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall // Expand using declarations. 6440129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (isa<UsingDecl>(InstD)) { 6441129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall UsingDecl *UD = cast<UsingDecl>(InstD); 6442129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall for (UsingDecl::shadow_iterator I = UD->shadow_begin(), 6443129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall E = UD->shadow_end(); I != E; ++I) 6444129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.addDecl(*I); 6445129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall continue; 6446129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 6447129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 6448129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.addDecl(InstD); 6449129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 6450129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 6451129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R.resolveKind(); 6452129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall 6453c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor // Determine the naming class. 6454042d6f98ea73d781e43cc17077e8fc84a4201eefChandler Carruth if (Old->getNamingClass()) { 6455c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt CXXRecordDecl *NamingClass 6456c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl( 645766c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getMemberLoc(), 645866c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor Old->getNamingClass())); 645966c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor if (!NamingClass) 6460f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6461c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 646266c45154186b7786d5dca645d548d73c47cf5d87Douglas Gregor R.setNamingClass(NamingClass); 6463c96be1ea33cdf63d07cec48d18fe8e3afea48f8dDouglas Gregor } 6464c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6465129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TemplateArgumentListInfo TransArgs; 6466129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall if (Old->hasExplicitTemplateArgs()) { 6467129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TransArgs.setLAngleLoc(Old->getLAngleLoc()); 6468129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall TransArgs.setRAngleLoc(Old->getRAngleLoc()); 6469fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(), 6470fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor Old->getNumTemplateArgs(), 6471fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor TransArgs)) 6472fcc1253ba28d1d1debacd147be15e1684cc2eda5Douglas Gregor return ExprError(); 6473129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall } 6474c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall 6475c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // FIXME: to do this check properly, we will need to preserve the 6476c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // first-qualifier-in-scope here, just in case we had a dependent 6477c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // base (and therefore couldn't do the check) and a 6478c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall // nested-name-qualifier (and therefore could do the lookup). 6479c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall NamedDecl *FirstQualifierInScope = 0; 6480c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 64819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildUnresolvedMemberExpr(Base.get(), 6482aa81e1658d87b9011125c632aa902d154ae4b02cJohn McCall BaseType, 6483129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Old->getOperatorLoc(), 6484129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Old->isArrow(), 6485129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Qualifier, 6486129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall Old->getQualifierRange(), 6487c2233c5c46eafebd5529bf2bbd1f0a723b892e61John McCall FirstQualifierInScope, 6488129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall R, 6489129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall (Old->hasExplicitTemplateArgs() 6490129e2df52ed7e0434b3f1cf1867fd6a5cb083ff6John McCall ? &TransArgs : 0)); 6491b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6492b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6493b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 649460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 64952e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlTreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) { 64962e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl ExprResult SubExpr = getDerived().TransformExpr(E->getOperand()); 64972e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl if (SubExpr.isInvalid()) 64982e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return ExprError(); 64992e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 65002e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand()) 65013fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 65022e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 65032e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get()); 65042e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl} 65052e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redl 65062e156225a29407a50dd19041aa5750171ad44ea3Sebastian Redltemplate<typename Derived> 65072e156225a29407a50dd19041aa5750171ad44ea3Sebastian RedlExprResult 6508be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorTreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) { 6509be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor llvm_unreachable("pack expansion expression in unhandled context"); 6510be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor return ExprError(); 6511be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor} 6512ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 6513ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregortemplate<typename Derived> 6514ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorExprResult 6515ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas GregorTreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) { 6516ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // If E is not value-dependent, then nothing will change when we transform it. 6517ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // Note: This is an instantiation-centric view. 6518ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor if (!E->isValueDependent()) 6519ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return SemaRef.Owned(E); 6520ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 6521ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // Note: None of the implementations of TryExpandParameterPacks can ever 6522ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // produce a diagnostic when given only a single unexpanded parameter pack, 6523ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // so 6524ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc()); 6525ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor bool ShouldExpand = false; 6526ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor unsigned NumExpansions = 0; 6527ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(), 6528ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor &Unexpanded, 1, 6529ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor ShouldExpand, NumExpansions)) 6530ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return ExprError(); 6531ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 6532ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor if (!ShouldExpand) 6533ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return SemaRef.Owned(E); 6534be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregor 6535ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // We now know the length of the parameter pack, so build a new expression 6536ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor // that stores that length. 6537ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(), 6538ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor E->getPackLoc(), E->getRParenLoc(), 6539ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor NumExpansions); 6540ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor} 6541ee8aff06f6a96214731de17b2cb6df407c6c1820Douglas Gregor 6542be230c36e32142cbdcdbe9c97511d097beeecbabDouglas Gregortemplate<typename Derived> 6543be230c36e32142cbdcdbe9c97511d097beeecbabDouglas GregorExprResult 6544454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) { 65453fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6546b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6547b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 65481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 654960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6550454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) { 655181d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor TypeSourceInfo *EncodedTypeInfo 655281d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor = getDerived().TransformType(E->getEncodedTypeSourceInfo()); 655381d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor if (!EncodedTypeInfo) 6554f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 65551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6556b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 655781d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedTypeInfo == E->getEncodedTypeSourceInfo()) 65583fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6559b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 6560b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(), 656181d3466d037dc5844234c7a93dab21a6ad986e7dDouglas Gregor EncodedTypeInfo, 6562b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6563b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 65641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6565b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 656660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6567454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) { 656892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Transform arguments. 656992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor bool ArgChanged = false; 6570ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> Args(SemaRef); 6571aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor Args.reserve(E->getNumArgs()); 6572aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args, 6573aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor &ArgChanged)) 6574aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 6575aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor 657692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (E->getReceiverKind() == ObjCMessageExpr::Class) { 657792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Class message: transform the receiver type. 657892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor TypeSourceInfo *ReceiverTypeInfo 657992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor = getDerived().TransformType(E->getClassReceiverTypeInfo()); 658092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!ReceiverTypeInfo) 6581f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6582c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 658392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // If nothing changed, just retain the existing message send. 658492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!getDerived().AlwaysRebuild() && 658592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged) 65863fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 658792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 658892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Build a new class message send. 658992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo, 659092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getSelector(), 6591f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis E->getSelectorLoc(), 659292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getMethodDecl(), 659392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getLeftLoc(), 659492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor move_arg(Args), 659592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getRightLoc()); 659692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor } 659792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 659892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Instance message: transform the receiver 659992e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor assert(E->getReceiverKind() == ObjCMessageExpr::Instance && 660092e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor "Only class and instance messages may be instantiated"); 660160d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Receiver 660292e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor = getDerived().TransformExpr(E->getInstanceReceiver()); 660392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (Receiver.isInvalid()) 6604f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 660592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor 660692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // If nothing changed, just retain the existing message send. 660792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor if (!getDerived().AlwaysRebuild() && 660892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor Receiver.get() == E->getInstanceReceiver() && !ArgChanged) 66093fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6610c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 661192e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // Build a new instance message send. 66129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCMessageExpr(Receiver.get(), 661392e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getSelector(), 6614f40f0d5a382395e0301d7dcbeaa2b8e90b8973b1Argyrios Kyrtzidis E->getSelectorLoc(), 661592e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getMethodDecl(), 661692e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getLeftLoc(), 661792e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor move_arg(Args), 661892e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor E->getRightLoc()); 6619b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6620b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 66211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 662260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6623454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) { 66243fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6625b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6626b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 66271eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 662860d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6629454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) { 66303fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6631b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6632b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 66331eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 663460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6635454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) { 6636f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // Transform the base expression. 663760d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 6638f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Base.isInvalid()) 6639f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6640f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor 6641f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // We don't need to transform the ivar; it will never change. 6642c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6643f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // If nothing changed, just retain the existing expression. 6644f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (!getDerived().AlwaysRebuild() && 6645f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Base.get() == E->getBase()) 66463fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6647c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 66489ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(), 6649f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->getLocation(), 6650f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->isArrow(), E->isFreeIvar()); 6651b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6652b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 66531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 665460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6655454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) { 665612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // 'super' and types never change. Property never changes. Just 665712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall // retain the existing expression. 665812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (!E->isObjectReceiver()) 66593fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 66608ac2d449820fd0df00fcbde5bf82165c1f49854dFariborz Jahanian 6661e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // Transform the base expression. 666260d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 6663e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (Base.isInvalid()) 6664f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6665c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6666e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // We don't need to transform the property; it will never change. 6667c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6668e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor // If nothing changed, just retain the existing expression. 6669e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor if (!getDerived().AlwaysRebuild() && 6670e330354c6bfbb0d7856432fa9055d5236f1b2fa4Douglas Gregor Base.get() == E->getBase()) 66713fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6672b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 667312f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall if (E->isExplicitProperty()) 667412f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getDerived().RebuildObjCPropertyRefExpr(Base.get(), 667512f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getExplicitProperty(), 667612f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getLocation()); 667712f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall 667812f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall return getDerived().RebuildObjCPropertyRefExpr(Base.get(), 667912f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getType(), 668012f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getImplicitPropertyGetter(), 668112f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getImplicitPropertySetter(), 668212f78a6741a4cb3d904340f8d3d2714568b50e7aJohn McCall E->getLocation()); 6683b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6684b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 66851eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 668660d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6687454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) { 6688f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // Transform the base expression. 668960d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Base = getDerived().TransformExpr(E->getBase()); 6690f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (Base.isInvalid()) 6691f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 6692c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6693f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor // If nothing changed, just retain the existing expression. 6694f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor if (!getDerived().AlwaysRebuild() && 6695f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor Base.get() == E->getBase()) 66963fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6697c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 66989ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(), 6699f9b9eab747e911ded499924b2616d8712d65efceDouglas Gregor E->isArrow()); 6700b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6701b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 67021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 670360d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6704454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) { 6705b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor bool ArgumentChanged = false; 6706ca0408fb49c1370430672acf2d770b7151cf71deJohn McCall ASTOwningVector<Expr*> SubExprs(SemaRef); 6707aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor SubExprs.reserve(E->getNumSubExprs()); 6708aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false, 6709aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor SubExprs, &ArgumentChanged)) 6710aa165f8458b51c546bebff947343e1a36f3594cbDouglas Gregor return ExprError(); 67111eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6712b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (!getDerived().AlwaysRebuild() && 6713b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor !ArgumentChanged) 67143fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 67151eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6716b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(), 6717b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor move_arg(SubExprs), 6718b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor E->getRParenLoc()); 6719b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6720b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 67211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 672260d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6723454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) { 6724a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian SourceLocation CaretLoc(E->getExprLoc()); 6725a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 6726a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian SemaRef.ActOnBlockStart(CaretLoc, /*Scope=*/0); 6727a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian BlockScopeInfo *CurBlock = SemaRef.getCurBlock(); 6728a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian CurBlock->TheDecl->setIsVariadic(E->getBlockDecl()->isVariadic()); 6729a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian llvm::SmallVector<ParmVarDecl*, 4> Params; 6730a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian llvm::SmallVector<QualType, 4> ParamTypes; 6731a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 6732a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian // Parameter substitution. 6733a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian const BlockDecl *BD = E->getBlockDecl(); 6734a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian for (BlockDecl::param_const_iterator P = BD->param_begin(), 6735a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian EN = BD->param_end(); P != EN; ++P) { 6736a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian ParmVarDecl *OldParm = (*P); 6737a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian ParmVarDecl *NewParm = getDerived().TransformFunctionTypeParam(OldParm); 6738a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian QualType NewType = NewParm->getType(); 6739a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian Params.push_back(NewParm); 6740a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian ParamTypes.push_back(NewParm->getType()); 6741a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian } 6742a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 6743a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian const FunctionType *BExprFunctionType = E->getFunctionType(); 6744a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian QualType BExprResultType = BExprFunctionType->getResultType(); 6745a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian if (!BExprResultType.isNull()) { 6746a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian if (!BExprResultType->isDependentType()) 6747a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian CurBlock->ReturnType = BExprResultType; 6748a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian else if (BExprResultType != SemaRef.Context.DependentTy) 6749a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian CurBlock->ReturnType = getDerived().TransformType(BExprResultType); 6750a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian } 6751711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 6752a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian QualType FunctionType = getDerived().RebuildFunctionProtoType( 6753a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian CurBlock->ReturnType, 6754a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian ParamTypes.data(), 6755a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian ParamTypes.size(), 6756a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian BD->isVariadic(), 6757fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman 0, 6758fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman BExprFunctionType->getExtInfo()); 6759a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian CurBlock->FunctionType = FunctionType; 6760711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 6761711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Set the parameters on the block decl. 6762711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (!Params.empty()) 6763711c52bb20d0c69063b52a99826fb7d2835501f1John McCall CurBlock->TheDecl->setParams(Params.data(), Params.size()); 6764711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 6765711c52bb20d0c69063b52a99826fb7d2835501f1John McCall // Transform the body 6766711c52bb20d0c69063b52a99826fb7d2835501f1John McCall StmtResult Body = getDerived().TransformStmt(E->getBody()); 6767711c52bb20d0c69063b52a99826fb7d2835501f1John McCall if (Body.isInvalid()) 6768711c52bb20d0c69063b52a99826fb7d2835501f1John McCall return ExprError(); 6769711c52bb20d0c69063b52a99826fb7d2835501f1John McCall 67709ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.ActOnBlockStmtExpr(CaretLoc, Body.get(), /*Scope=*/0); 6771b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6772b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 67731eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 677460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 6775454feb9da67504b475d032ca2a9fc34c5744748eJohn McCallTreeTransform<Derived>::TransformBlockDeclRefExpr(BlockDeclRefExpr *E) { 6776a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian NestedNameSpecifier *Qualifier = 0; 6777a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 6778a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian ValueDecl *ND 6779a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(), 6780a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian E->getDecl())); 6781a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian if (!ND) 6782f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 67832577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 6784a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian if (!getDerived().AlwaysRebuild() && 6785a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian ND == E->getDecl()) { 6786a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian // Mark it referenced in the new context regardless. 6787a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian // FIXME: this is a bit instantiation-specific. 6788a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian SemaRef.MarkDeclarationReferenced(E->getLocation(), ND); 6789a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 67903fa5cae9b3812cab9fab6c042c3329bb70a3d046John McCall return SemaRef.Owned(E); 6791a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian } 6792a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian 67932577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(E->getDecl()->getDeclName(), E->getLocation()); 6794a729da2c29e7df26319acf2675d51e377287a139Fariborz Jahanian return getDerived().RebuildDeclRefExpr(Qualifier, SourceLocation(), 67952577743c5650c646fb705df01403707e94f2df04Abramo Bagnara ND, NameInfo, 0); 6796b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 67971eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6798b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===// 6799b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor// Type reconstruction 6800b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor//===----------------------------------------------------------------------===// 6801b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 68021eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 680385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType, 680485737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Star) { 68052865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildPointerType(PointeeType, Star, 6806b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor getDerived().getBaseEntity()); 6807b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6808b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 68091eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 681085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallQualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType, 681185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Star) { 68122865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildBlockPointerType(PointeeType, Star, 6813b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor getDerived().getBaseEntity()); 6814b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6815b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 68161eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 68171eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 681885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildReferenceType(QualType ReferentType, 681985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall bool WrittenAsLValue, 682085737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil) { 68212865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue, 682285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Sigil, getDerived().getBaseEntity()); 6823b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 6824b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor 68251eb4433ac451dc16f4133a88af2d002ac26c58efMike Stumptemplate<typename Derived> 68261eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 682785737a71fee8c737f7cfba79a0aca89298fe573bJohn McCallTreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType, 682885737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall QualType ClassType, 682985737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceLocation Sigil) { 68302865474261a608c7873b87ba4af110d17907896dJohn McCall return SemaRef.BuildMemberPointerType(PointeeType, ClassType, 683185737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall Sigil, getDerived().getBaseEntity()); 6832577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 6833577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 6834577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 68351eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 6836577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorTreeTransform<Derived>::RebuildArrayType(QualType ElementType, 6837577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 6838577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt *Size, 6839577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Expr *SizeExpr, 6840577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 6841577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 6842577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (SizeExpr || !Size) 6843577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr, 6844577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange, 6845577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor getDerived().getBaseEntity()); 68461eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 68471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType Types[] = { 68481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy, 68491eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy, 68501eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty 6851577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor }; 6852577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const unsigned NumTypes = sizeof(Types) / sizeof(QualType); 6853577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor QualType SizeType; 6854577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor for (unsigned I = 0; I != NumTypes; ++I) 6855577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) { 6856577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SizeType = Types[I]; 6857577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor break; 6858577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor } 68591eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 68609996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType, 68619996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis /*FIXME*/BracketsRange.getBegin()); 68621eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize, 6863577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange, 68641eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump getDerived().getBaseEntity()); 6865577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 68661eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6867577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 68681eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 68691eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType, 6870577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 6871577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor const llvm::APInt &Size, 687285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 687385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange) { 68741eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, 0, 687585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall IndexTypeQuals, BracketsRange); 6876577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 6877577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 6878577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 68791eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 68801eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType, 6881577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 688285737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall unsigned IndexTypeQuals, 688385737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall SourceRange BracketsRange) { 68841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 0, 688585737a71fee8c737f7cfba79a0aca89298fe573bJohn McCall IndexTypeQuals, BracketsRange); 6886577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 68871eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6888577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 68891eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 68901eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType, 6891577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 68929ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 6893577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 6894577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 68951eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 68969ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SizeExpr, 6897577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange); 6898577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 6899577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 6900577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 69011eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 69021eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType, 6903577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor ArrayType::ArraySizeModifier SizeMod, 69049ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 6905577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned IndexTypeQuals, 6906577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceRange BracketsRange) { 69071eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return getDerived().RebuildArrayType(ElementType, SizeMod, 0, 69089ae2f076ca5ab1feb3ba95629099ec2319833701John McCall SizeExpr, 6909577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IndexTypeQuals, BracketsRange); 6910577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 6911577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 6912577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 6913577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType, 6914e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson unsigned NumElements, 6915e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson VectorType::VectorKind VecKind) { 6916577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor // FIXME: semantic checking! 6917e86d78cf4754a6aef2cf9a33d847aa15338e276fBob Wilson return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind); 6918577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 69191eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6920577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 6921577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType, 6922577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumElements, 6923577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc) { 6924577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy), 6925577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor NumElements, true); 6926577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor IntegerLiteral *VectorSize 69279996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy, 69289996a7f06a3c5b4554692e7177930cf4e8ef09afArgyrios Kyrtzidis AttributeLoc); 69299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc); 6930577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 69311eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6932577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 69331eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpQualType 69341eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType, 69359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *SizeExpr, 6936577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor SourceLocation AttributeLoc) { 69379ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc); 6938577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 69391eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6940577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 6941577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildFunctionProtoType(QualType T, 69421eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump QualType *ParamTypes, 6943577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor unsigned NumParamTypes, 69441eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump bool Variadic, 6945fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman unsigned Quals, 6946fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman const FunctionType::ExtInfo &Info) { 69471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SemaRef.BuildFunctionType(T, ParamTypes, NumParamTypes, Variadic, 6948577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor Quals, 6949577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor getDerived().getBaseLocation(), 6950fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman getDerived().getBaseEntity(), 6951fa869547eb1cab12d7e0c0dfa8ba594e336b9b32Eli Friedman Info); 6952577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 69531eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 6954577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 6955a2becad14a0eb19cde2f441ced588b975433d2edJohn McCallQualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) { 6956a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall return SemaRef.Context.getFunctionNoProtoType(T); 6957a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall} 6958a2becad14a0eb19cde2f441ced588b975433d2edJohn McCall 6959a2becad14a0eb19cde2f441ced588b975433d2edJohn McCalltemplate<typename Derived> 6960ed97649e9574b9d854fa4d6109c9333ae0993554John McCallQualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) { 6961ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(D && "no decl found"); 6962ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (D->isInvalidDecl()) return QualType(); 6963ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 696492e986e0adb79e8a47f738bd608e6c97c547641dDouglas Gregor // FIXME: Doesn't account for ObjCInterfaceDecl! 6965ed97649e9574b9d854fa4d6109c9333ae0993554John McCall TypeDecl *Ty; 6966ed97649e9574b9d854fa4d6109c9333ae0993554John McCall if (isa<UsingDecl>(D)) { 6967ed97649e9574b9d854fa4d6109c9333ae0993554John McCall UsingDecl *Using = cast<UsingDecl>(D); 6968ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(Using->isTypeName() && 6969ed97649e9574b9d854fa4d6109c9333ae0993554John McCall "UnresolvedUsingTypenameDecl transformed to non-typename using"); 6970ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 6971ed97649e9574b9d854fa4d6109c9333ae0993554John McCall // A valid resolved using typename decl points to exactly one type decl. 6972ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(++Using->shadow_begin() == Using->shadow_end()); 6973ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl()); 6974c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 6975ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } else { 6976ed97649e9574b9d854fa4d6109c9333ae0993554John McCall assert(isa<UnresolvedUsingTypenameDecl>(D) && 6977ed97649e9574b9d854fa4d6109c9333ae0993554John McCall "UnresolvedUsingTypenameDecl transformed to non-using decl"); 6978ed97649e9574b9d854fa4d6109c9333ae0993554John McCall Ty = cast<UnresolvedUsingTypenameDecl>(D); 6979ed97649e9574b9d854fa4d6109c9333ae0993554John McCall } 6980ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 6981ed97649e9574b9d854fa4d6109c9333ae0993554John McCall return SemaRef.Context.getTypeDeclType(Ty); 6982ed97649e9574b9d854fa4d6109c9333ae0993554John McCall} 6983ed97649e9574b9d854fa4d6109c9333ae0993554John McCall 6984ed97649e9574b9d854fa4d6109c9333ae0993554John McCalltemplate<typename Derived> 69852a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E, 69862a984cad5ac3fdceeff2bd99daa7b90979313475John McCall SourceLocation Loc) { 69872a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return SemaRef.BuildTypeofExprType(E, Loc); 6988577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 6989577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 6990577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 6991577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) { 6992577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor return SemaRef.Context.getTypeOfType(Underlying); 6993577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 6994577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 6995577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 69962a984cad5ac3fdceeff2bd99daa7b90979313475John McCallQualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E, 69972a984cad5ac3fdceeff2bd99daa7b90979313475John McCall SourceLocation Loc) { 69982a984cad5ac3fdceeff2bd99daa7b90979313475John McCall return SemaRef.BuildDecltypeType(E, Loc); 6999577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 7000577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 7001577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregortemplate<typename Derived> 7002577f75a7498e9e2536434da0ef0da0eea390d18bDouglas GregorQualType TreeTransform<Derived>::RebuildTemplateSpecializationType( 7003833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall TemplateName Template, 7004833ca991c1bfc967f0995974ca86f66ba1f666b5John McCall SourceLocation TemplateNameLoc, 7005d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall const TemplateArgumentListInfo &TemplateArgs) { 7006d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs); 7007577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} 70081eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7009dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived> 7010dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier * 7011dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, 7012dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor SourceRange Range, 7013a38c687ef5354678b9d76a7b29354159f2b83736Douglas Gregor IdentifierInfo &II, 7014c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor QualType ObjectType, 7015d5532b6cfff2977e0c59fa6ead7f7973984a620dJohn McCall NamedDecl *FirstQualifierInScope) { 7016dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor CXXScopeSpec SS; 7017dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor // FIXME: The source location information is all wrong. 7018dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor SS.setRange(Range); 7019dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor SS.setScopeRep(Prefix); 7020dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor return static_cast<NestedNameSpecifier *>( 70211eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SemaRef.BuildCXXNestedNameSpecifier(0, SS, Range.getEnd(), 7022495c35d291da48c4f5655bbb54d15128ddde0d4dDouglas Gregor Range.getEnd(), II, 7023c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor ObjectType, 7024c68afe2cbe7f875a9243c411077602fb5f5dc74bDouglas Gregor FirstQualifierInScope, 702546646491834cd8faabb22482dfe93b24ce28a6c1Chris Lattner false, false)); 7026dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor} 7027dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor 7028dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived> 7029dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier * 7030dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, 7031dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor SourceRange Range, 7032dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor NamespaceDecl *NS) { 7033dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor return NestedNameSpecifier::Create(SemaRef.Context, Prefix, NS); 7034dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor} 7035dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor 7036dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregortemplate<typename Derived> 7037dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorNestedNameSpecifier * 7038dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas GregorTreeTransform<Derived>::RebuildNestedNameSpecifier(NestedNameSpecifier *Prefix, 7039dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor SourceRange Range, 7040dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor bool TemplateKW, 7041edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor QualType T) { 7042edc90500b1d2587bf0b698fada14537d6741fddfDouglas Gregor if (T->isDependentType() || T->isRecordType() || 7043dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor (SemaRef.getLangOptions().CPlusPlus0x && T->isEnumeralType())) { 7044a4923eb7c4b04d360cb2747641a5e92818edf804Douglas Gregor assert(!T.hasLocalQualifiers() && "Can't get cv-qualifiers here"); 7045dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor return NestedNameSpecifier::Create(SemaRef.Context, Prefix, TemplateKW, 7046dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor T.getTypePtr()); 7047dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor } 70481eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7049dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor SemaRef.Diag(Range.getBegin(), diag::err_nested_name_spec_non_tag) << T; 7050dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor return 0; 7051dcee1a12c83a6cbc9b5bf42df5d4efbc502664e7Douglas Gregor} 70521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7053d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived> 70541eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 7055d1067e5a0a6e2aee7260c392452df9553034c92bDouglas GregorTreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, 7056d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor bool TemplateKW, 7057d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor TemplateDecl *Template) { 70581eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return SemaRef.Context.getQualifiedTemplateName(Qualifier, TemplateKW, 7059d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor Template); 7060d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor} 7061d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor 7062d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregortemplate<typename Derived> 70631eb4433ac451dc16f4133a88af2d002ac26c58efMike StumpTemplateName 7064d1067e5a0a6e2aee7260c392452df9553034c92bDouglas GregorTreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, 70651efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor SourceRange QualifierRange, 70663b6afbb99a1c44b4076f8e15fb7311405941b306Douglas Gregor const IdentifierInfo &II, 706743fed0de4f5bc189e45562491f83d5193eb8dac0John McCall QualType ObjectType, 706843fed0de4f5bc189e45562491f83d5193eb8dac0John McCall NamedDecl *FirstQualifierInScope) { 7069d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor CXXScopeSpec SS; 70701efb6c716397f2c4e3ede3a4853c5efebb375441Douglas Gregor SS.setRange(QualifierRange); 70711eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump SS.setScopeRep(Qualifier); 7072014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor UnqualifiedId Name; 7073014e88d94ff83e3aad4e33b16413a2d1817ec208Douglas Gregor Name.setIdentifier(&II, /*FIXME:*/getDerived().getBaseLocation()); 7074d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Sema::TemplateTy Template; 7075d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor getSema().ActOnDependentTemplateName(/*Scope=*/0, 7076d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor /*FIXME:*/getDerived().getBaseLocation(), 7077d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor SS, 7078d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Name, 7079b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType::make(ObjectType), 7080d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor /*EnteringContext=*/false, 7081d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Template); 708243fed0de4f5bc189e45562491f83d5193eb8dac0John McCall return Template.get(); 7083d1067e5a0a6e2aee7260c392452df9553034c92bDouglas Gregor} 70841eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7085b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregortemplate<typename Derived> 7086ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTemplateName 7087ca1bdd7c269a2390d43c040a60511edd017ee130Douglas GregorTreeTransform<Derived>::RebuildTemplateName(NestedNameSpecifier *Qualifier, 7088ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor OverloadedOperatorKind Operator, 7089ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor QualType ObjectType) { 7090ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor CXXScopeSpec SS; 7091ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor SS.setRange(SourceRange(getDerived().getBaseLocation())); 7092ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor SS.setScopeRep(Qualifier); 7093ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor UnqualifiedId Name; 7094ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor SourceLocation SymbolLocations[3]; // FIXME: Bogus location information. 7095ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor Name.setOperatorFunctionId(/*FIXME:*/getDerived().getBaseLocation(), 7096ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor Operator, SymbolLocations); 7097d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Sema::TemplateTy Template; 7098d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor getSema().ActOnDependentTemplateName(/*Scope=*/0, 7099ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor /*FIXME:*/getDerived().getBaseLocation(), 7100d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor SS, 7101d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Name, 7102b3d8748e797c6c2f1dc01186c8eeb3b1b5fe970cJohn McCall ParsedType::make(ObjectType), 7103d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor /*EnteringContext=*/false, 7104d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor Template); 7105d6ab232bb3ec9847de5af06249afb63078b5f2eeDouglas Gregor return Template.template getAsVal<TemplateName>(); 7106ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregor} 7107c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt 7108ca1bdd7c269a2390d43c040a60511edd017ee130Douglas Gregortemplate<typename Derived> 710960d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 7110b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas GregorTreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op, 7111b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor SourceLocation OpLoc, 71129ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *OrigCallee, 71139ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *First, 71149ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Second) { 71159ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Callee = OrigCallee->IgnoreParenCasts(); 71169ae2f076ca5ab1feb3ba95629099ec2319833701John McCall bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus); 71171eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7118b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Determine whether this should be a builtin operation. 7119f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl if (Op == OO_Subscript) { 71209ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType() && 71219ae2f076ca5ab1feb3ba95629099ec2319833701John McCall !Second->getType()->isOverloadableType()) 71229ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().CreateBuiltinArraySubscriptExpr(First, 71239ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Callee->getLocStart(), 71249ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Second, OpLoc); 71251a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman } else if (Op == OO_Arrow) { 71261a3c75f32f0d27de5f3f6b2ef4c6bbe7e18bddadEli Friedman // -> is never a builtin operation. 71279ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildOverloadedArrowExpr(0, First, OpLoc); 71289ae2f076ca5ab1feb3ba95629099ec2319833701John McCall } else if (Second == 0 || isPostIncDec) { 71299ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType()) { 7130b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // The argument is not of overloadable type, so try to create a 7131b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // built-in unary operation. 71322de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc 7133b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); 71341eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71359ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First); 7136b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 7137b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } else { 71389ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (!First->getType()->isOverloadableType() && 71399ae2f076ca5ab1feb3ba95629099ec2319833701John McCall !Second->getType()->isOverloadableType()) { 7140b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Neither of the arguments is an overloadable type, so try to 7141b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // create a built-in binary operation. 71422de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 714360d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 71449ae2f076ca5ab1feb3ba95629099ec2319833701John McCall = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second); 7145b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 7146f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 71471eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7148b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor return move(Result); 7149b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 7150b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 71511eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71521eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump // Compute the transformed set of functions (and function templates) to be 7153b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // used during overload resolution. 71546e26689f5d513e24ad7783a4493201930fdeccc0John McCall UnresolvedSet<16> Functions; 71551eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71569ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) { 7157ba13543329afac4a0d01304ec2ec4924d99306a6John McCall assert(ULE->requiresADL()); 7158ba13543329afac4a0d01304ec2ec4924d99306a6John McCall 7159ba13543329afac4a0d01304ec2ec4924d99306a6John McCall // FIXME: Do we have to check 7160ba13543329afac4a0d01304ec2ec4924d99306a6John McCall // IsAcceptableNonMemberOperatorCandidate for each of these? 71616e26689f5d513e24ad7783a4493201930fdeccc0John McCall Functions.append(ULE->decls_begin(), ULE->decls_end()); 7162ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } else { 71639ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Functions.addDecl(cast<DeclRefExpr>(Callee)->getDecl()); 7164ba13543329afac4a0d01304ec2ec4924d99306a6John McCall } 71651eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7166b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Add any functions found via argument-dependent lookup. 71679ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Expr *Args[2] = { First, Second }; 71689ae2f076ca5ab1feb3ba95629099ec2319833701John McCall unsigned NumArgs = 1 + (Second != 0); 71691eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7170b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Create the overloaded operator invocation for unary operators. 7171b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (NumArgs == 1 || isPostIncDec) { 71722de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall UnaryOperatorKind Opc 7173b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec); 71749ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First); 7175b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor } 71761eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 7177f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl if (Op == OO_Subscript) 71789ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.CreateOverloadedArraySubscriptExpr(Callee->getLocStart(), 7179ba13543329afac4a0d01304ec2ec4924d99306a6John McCall OpLoc, 71809ae2f076ca5ab1feb3ba95629099ec2319833701John McCall First, 71819ae2f076ca5ab1feb3ba95629099ec2319833701John McCall Second); 7182f322ed6d39a30f509023cf88588c1e6514226127Sebastian Redl 7183b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor // Create the overloaded operator invocation for binary operators. 71842de56d1d0c3a504ad1529de2677628bdfbb95cd4John McCall BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op); 718560d7b3a319d84d688752be3870615ac0f111fb16John McCall ExprResult Result 7186b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]); 7187b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor if (Result.isInvalid()) 7188f312b1ea179f1c44371f9ee0cd0bc006f612de11John McCall return ExprError(); 71891eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 71901eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump return move(Result); 7191b98b1991c7ad1eaedb863bdbdd784ec164277675Douglas Gregor} 71921eb4433ac451dc16f4133a88af2d002ac26c58efMike Stump 719326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregortemplate<typename Derived> 719460d7b3a319d84d688752be3870615ac0f111fb16John McCallExprResult 71959ae2f076ca5ab1feb3ba95629099ec2319833701John McCallTreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base, 719626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SourceLocation OperatorLoc, 719726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor bool isArrow, 719826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor NestedNameSpecifier *Qualifier, 719926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SourceRange QualifierRange, 720026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor TypeSourceInfo *ScopeType, 720126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SourceLocation CCLoc, 7202fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SourceLocation TildeLoc, 7203a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor PseudoDestructorTypeStorage Destroyed) { 720426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor CXXScopeSpec SS; 720526d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor if (Qualifier) { 720626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SS.setRange(QualifierRange); 720726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SS.setScopeRep(Qualifier); 720826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor } 720926d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor 72109ae2f076ca5ab1feb3ba95629099ec2319833701John McCall QualType BaseType = Base->getType(); 72119ae2f076ca5ab1feb3ba95629099ec2319833701John McCall if (Base->isTypeDependent() || Destroyed.getIdentifier() || 721226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor (!isArrow && !BaseType->getAs<RecordType>()) || 7213c302113179a1c2b1254224ea9b6f5316ceeb375cSean Hunt (isArrow && BaseType->getAs<PointerType>() && 7214bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif !BaseType->getAs<PointerType>()->getPointeeType() 7215bf2ca2f87ff0b33b839b1b51d233a79bb56e5bacGabor Greif ->template getAs<RecordType>())){ 721626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor // This pseudo-destructor expression is still a pseudo-destructor. 72179ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return SemaRef.BuildPseudoDestructorExpr(Base, OperatorLoc, 721826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor isArrow? tok::arrow : tok::period, 7219fce46ee68f779e239826e69e45d01d4c8e5323caDouglas Gregor SS, ScopeType, CCLoc, TildeLoc, 7220a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor Destroyed, 722126d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /*FIXME?*/true); 722226d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor } 72232577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 7224a2e7dd2f4a50d835351153aee568d35ccc986310Douglas Gregor TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo(); 72252577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName( 72262577743c5650c646fb705df01403707e94f2df04Abramo Bagnara SemaRef.Context.getCanonicalType(DestroyedType->getType()))); 72272577743c5650c646fb705df01403707e94f2df04Abramo Bagnara DeclarationNameInfo NameInfo(Name, Destroyed.getLocation()); 72282577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo.setNamedTypeInfo(DestroyedType); 72292577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 723026d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor // FIXME: the ScopeType should be tacked onto SS. 72312577743c5650c646fb705df01403707e94f2df04Abramo Bagnara 72329ae2f076ca5ab1feb3ba95629099ec2319833701John McCall return getSema().BuildMemberReferenceExpr(Base, BaseType, 723326d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor OperatorLoc, isArrow, 723426d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor SS, /*FIXME: FirstQualifier*/ 0, 72352577743c5650c646fb705df01403707e94f2df04Abramo Bagnara NameInfo, 723626d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor /*TemplateArgs*/ 0); 723726d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor} 723826d4ac97fb514bb60c2536eae6f203dc569159d9Douglas Gregor 7239577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor} // end namespace clang 7240577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor 7241577f75a7498e9e2536434da0ef0da0eea390d18bDouglas Gregor#endif // LLVM_CLANG_SEMA_TREETRANSFORM_H 7242