blob: de368ea90caaeb7edb227c20afc765ab1359a517 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000016
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Alexey Bataev1a3320e2015-08-25 14:24:04 +000024#include "clang/AST/ExprOpenMP.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000028#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000029#include "clang/Sema/Designator.h"
30#include "clang/Sema/Lookup.h"
31#include "clang/Sema/Ownership.h"
32#include "clang/Sema/ParsedTemplate.h"
33#include "clang/Sema/ScopeInfo.h"
34#include "clang/Sema/SemaDiagnostic.h"
35#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000036#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000037#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000038#include <algorithm>
39
40namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000041using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000042
Douglas Gregord6ff3322009-08-04 16:50:30 +000043/// \brief A semantic tree transformation that allows one to transform one
44/// abstract syntax tree into another.
45///
Mike Stump11289f42009-09-09 15:08:12 +000046/// A new tree transformation is defined by creating a new subclass \c X of
47/// \c TreeTransform<X> and then overriding certain operations to provide
48/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// instantiation is implemented as a tree transformation where the
50/// transformation of TemplateTypeParmType nodes involves substituting the
51/// template arguments for their corresponding template parameters; a similar
52/// transformation is performed for non-type template parameters and
53/// template template parameters.
54///
55/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000056/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000057/// override any of the transformation or rebuild operators by providing an
58/// operation with the same signature as the default implementation. The
59/// overridding function should not be virtual.
60///
61/// Semantic tree transformations are split into two stages, either of which
62/// can be replaced by a subclass. The "transform" step transforms an AST node
63/// or the parts of an AST node using the various transformation functions,
64/// then passes the pieces on to the "rebuild" step, which constructs a new AST
65/// node of the appropriate kind from the pieces. The default transformation
66/// routines recursively transform the operands to composite AST nodes (e.g.,
67/// the pointee type of a PointerType node) and, if any of those operand nodes
68/// were changed by the transformation, invokes the rebuild operation to create
69/// a new AST node.
70///
Mike Stump11289f42009-09-09 15:08:12 +000071/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000072/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000073/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// TransformTemplateName(), or TransformTemplateArgument() with entirely
75/// new implementations.
76///
77/// For more fine-grained transformations, subclasses can replace any of the
78/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000079/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000080/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000081/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// parameters. Additionally, subclasses can override the \c RebuildXXX
83/// functions to control how AST nodes are rebuilt when their operands change.
84/// By default, \c TreeTransform will invoke semantic analysis to rebuild
85/// AST nodes. However, certain other tree transformations (e.g, cloning) may
86/// be able to use more efficient rebuild steps.
87///
88/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000089/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000090/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91/// operands have not changed (\c AlwaysRebuild()), and customize the
92/// default locations and entity names used for type-checking
93/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000094template<typename Derived>
95class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000096 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000102
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000103 public:
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000107
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113protected:
114 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000115
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000116 /// \brief The set of local declarations that have been transformed, for
117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000120
Mike Stump11289f42009-09-09 15:08:12 +0000121public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000124
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 /// \brief Retrieves a reference to the derived class.
126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
128 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000131 }
132
John McCalldadc5752010-08-24 06:29:42 +0000133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000135
Douglas Gregord6ff3322009-08-04 16:50:30 +0000136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Douglas Gregord6ff3322009-08-04 16:50:30 +0000140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000145 ///
146 /// We must always rebuild all AST nodes when performing variadic template
147 /// pack expansion, in order to avoid violating the AST invariant that each
148 /// statement node appears at most once in its containing declaration.
149 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregord6ff3322009-08-04 16:50:30 +0000151 /// \brief Returns the location of the entity being transformed, if that
152 /// information was not available elsewhere in the AST.
153 ///
Mike Stump11289f42009-09-09 15:08:12 +0000154 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000155 /// provide an alternative implementation that provides better location
156 /// information.
157 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregord6ff3322009-08-04 16:50:30 +0000159 /// \brief Returns the name of the entity being transformed, if that
160 /// information was not available elsewhere in the AST.
161 ///
162 /// By default, returns an empty name. Subclasses can provide an alternative
163 /// implementation with a more precise name.
164 DeclarationName getBaseEntity() { return DeclarationName(); }
165
Douglas Gregora16548e2009-08-11 05:31:07 +0000166 /// \brief Sets the "base" location and entity when that
167 /// information is known based on another transformation.
168 ///
169 /// By default, the source location and entity are ignored. Subclasses can
170 /// override this function to provide a customized implementation.
171 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000172
Douglas Gregora16548e2009-08-11 05:31:07 +0000173 /// \brief RAII object that temporarily sets the base location and entity
174 /// used for reporting diagnostics in types.
175 class TemporaryBase {
176 TreeTransform &Self;
177 SourceLocation OldLocation;
178 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000179
Douglas Gregora16548e2009-08-11 05:31:07 +0000180 public:
181 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000182 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000183 OldLocation = Self.getDerived().getBaseLocation();
184 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000185
Douglas Gregora518d5b2011-01-25 17:51:48 +0000186 if (Location.isValid())
187 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000188 }
Mike Stump11289f42009-09-09 15:08:12 +0000189
Douglas Gregora16548e2009-08-11 05:31:07 +0000190 ~TemporaryBase() {
191 Self.getDerived().setBase(OldLocation, OldEntity);
192 }
193 };
Mike Stump11289f42009-09-09 15:08:12 +0000194
195 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 /// transformed.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000199 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000200 /// not change. For example, template instantiation need not traverse
201 /// non-dependent types.
202 bool AlreadyTransformed(QualType T) {
203 return T.isNull();
204 }
205
Douglas Gregord196a582009-12-14 19:27:10 +0000206 /// \brief Determine whether the given call argument should be dropped, e.g.,
207 /// because it is a default argument.
208 ///
209 /// Subclasses can provide an alternative implementation of this routine to
210 /// determine which kinds of call arguments get dropped. By default,
211 /// CXXDefaultArgument nodes are dropped (prior to transformation).
212 bool DropCallArgument(Expr *E) {
213 return E->isDefaultArgument();
214 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000215
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000216 /// \brief Determine whether we should expand a pack expansion with the
217 /// given set of parameter packs into separate arguments by repeatedly
218 /// transforming the pattern.
219 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000220 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000221 /// Subclasses can override this routine to provide different behavior.
222 ///
223 /// \param EllipsisLoc The location of the ellipsis that identifies the
224 /// pack expansion.
225 ///
226 /// \param PatternRange The source range that covers the entire pattern of
227 /// the pack expansion.
228 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000229 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000230 /// pattern.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param ShouldExpand Will be set to \c true if the transformer should
233 /// expand the corresponding pack expansions into separate arguments. When
234 /// set, \c NumExpansions must also be set.
235 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000236 /// \param RetainExpansion Whether the caller should add an unexpanded
237 /// pack expansion after all of the expanded arguments. This is used
238 /// when extending explicitly-specified template argument packs per
239 /// C++0x [temp.arg.explicit]p9.
240 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000241 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000242 /// the expanded form of the corresponding pack expansion. This is both an
243 /// input and an output parameter, which can be set by the caller if the
244 /// number of expansions is known a priori (e.g., due to a prior substitution)
245 /// and will be set by the callee when the number of expansions is known.
246 /// The callee must set this value when \c ShouldExpand is \c true; it may
247 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000248 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000249 /// \returns true if an error occurred (e.g., because the parameter packs
250 /// are to be instantiated with arguments of different lengths), false
251 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 /// must be set.
253 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
254 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000255 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000256 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000257 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000258 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000259 ShouldExpand = false;
260 return false;
261 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000262
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000263 /// \brief "Forget" about the partially-substituted pack template argument,
264 /// when performing an instantiation that must preserve the parameter pack
265 /// use.
266 ///
267 /// This routine is meant to be overridden by the template instantiator.
268 TemplateArgument ForgetPartiallySubstitutedPack() {
269 return TemplateArgument();
270 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000271
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000272 /// \brief "Remember" the partially-substituted pack template argument
273 /// after performing an instantiation that must preserve the parameter pack
274 /// use.
275 ///
276 /// This routine is meant to be overridden by the template instantiator.
277 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000278
Douglas Gregorf3010112011-01-07 16:43:16 +0000279 /// \brief Note to the derived class when a function parameter pack is
280 /// being expanded.
281 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transforms the given type into another type.
284 ///
John McCall550e0c22009-10-21 00:40:46 +0000285 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000286 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000287 /// function. This is expensive, but we don't mind, because
288 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000289 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000290 ///
291 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000292 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000293
John McCall550e0c22009-10-21 00:40:46 +0000294 /// \brief Transforms the given type-with-location into a new
295 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000296 ///
John McCall550e0c22009-10-21 00:40:46 +0000297 /// By default, this routine transforms a type by delegating to the
298 /// appropriate TransformXXXType to build a new type. Subclasses
299 /// may override this function (to take over all type
300 /// transformations) or some set of the TransformXXXType functions
301 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000302 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000303
304 /// \brief Transform the given type-with-location into a new
305 /// type, collecting location information in the given builder
306 /// as necessary.
307 ///
John McCall31f82722010-11-12 08:19:04 +0000308 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000309
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000310 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000311 ///
Mike Stump11289f42009-09-09 15:08:12 +0000312 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000313 /// appropriate TransformXXXStmt function to transform a specific kind of
314 /// statement or the TransformExpr() function to transform an expression.
315 /// Subclasses may override this function to transform statements using some
316 /// other mechanism.
317 ///
318 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000319 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000320
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000321 /// \brief Transform the given statement.
322 ///
323 /// By default, this routine transforms a statement by delegating to the
324 /// appropriate TransformOMPXXXClause function to transform a specific kind
325 /// of clause. Subclasses may override this function to transform statements
326 /// using some other mechanism.
327 ///
328 /// \returns the transformed OpenMP clause.
329 OMPClause *TransformOMPClause(OMPClause *S);
330
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000331 /// \brief Transform the given attribute.
332 ///
333 /// By default, this routine transforms a statement by delegating to the
334 /// appropriate TransformXXXAttr function to transform a specific kind
335 /// of attribute. Subclasses may override this function to transform
336 /// attributed statements using some other mechanism.
337 ///
338 /// \returns the transformed attribute
339 const Attr *TransformAttr(const Attr *S);
340
341/// \brief Transform the specified attribute.
342///
343/// Subclasses should override the transformation of attributes with a pragma
344/// spelling to transform expressions stored within the attribute.
345///
346/// \returns the transformed attribute.
347#define ATTR(X)
348#define PRAGMA_SPELLING_ATTR(X) \
349 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
350#include "clang/Basic/AttrList.inc"
351
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000352 /// \brief Transform the given expression.
353 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000354 /// By default, this routine transforms an expression by delegating to the
355 /// appropriate TransformXXXExpr function to build a new expression.
356 /// Subclasses may override this function to transform expressions using some
357 /// other mechanism.
358 ///
359 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000360 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000361
Richard Smithd59b8322012-12-19 01:39:02 +0000362 /// \brief Transform the given initializer.
363 ///
364 /// By default, this routine transforms an initializer by stripping off the
365 /// semantic nodes added by initialization, then passing the result to
366 /// TransformExpr or TransformExprs.
367 ///
368 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000369 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000370
Douglas Gregora3efea12011-01-03 19:04:46 +0000371 /// \brief Transform the given list of expressions.
372 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000373 /// This routine transforms a list of expressions by invoking
374 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000375 /// support for variadic templates by expanding any pack expansions (if the
376 /// derived class permits such expansion) along the way. When pack expansions
377 /// are present, the number of outputs may not equal the number of inputs.
378 ///
379 /// \param Inputs The set of expressions to be transformed.
380 ///
381 /// \param NumInputs The number of expressions in \c Inputs.
382 ///
383 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000384 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000385 /// be.
386 ///
387 /// \param Outputs The transformed input expressions will be added to this
388 /// vector.
389 ///
390 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
391 /// due to transformation.
392 ///
393 /// \returns true if an error occurred, false otherwise.
394 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000395 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000396 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregord6ff3322009-08-04 16:50:30 +0000398 /// \brief Transform the given declaration, which is referenced from a type
399 /// or expression.
400 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000401 /// By default, acts as the identity function on declarations, unless the
402 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000403 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000404 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000405 llvm::DenseMap<Decl *, Decl *>::iterator Known
406 = TransformedLocalDecls.find(D);
407 if (Known != TransformedLocalDecls.end())
408 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000409
410 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000411 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000412
Chad Rosier1dcde962012-08-08 18:46:20 +0000413 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000414 /// place them on the new declaration.
415 ///
416 /// By default, this operation does nothing. Subclasses may override this
417 /// behavior to transform attributes.
418 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000419
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000420 /// \brief Note that a local declaration has been transformed by this
421 /// transformer.
422 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000423 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000424 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
425 /// the transformer itself has to transform the declarations. This routine
426 /// can be overridden by a subclass that keeps track of such mappings.
427 void transformedLocalDecl(Decl *Old, Decl *New) {
428 TransformedLocalDecls[Old] = New;
429 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000430
Douglas Gregorebe10102009-08-20 07:17:43 +0000431 /// \brief Transform the definition of the given declaration.
432 ///
Mike Stump11289f42009-09-09 15:08:12 +0000433 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000434 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000435 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
436 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000437 }
Mike Stump11289f42009-09-09 15:08:12 +0000438
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000439 /// \brief Transform the given declaration, which was the first part of a
440 /// nested-name-specifier in a member access expression.
441 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000442 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000443 /// identifier in a nested-name-specifier of a member access expression, e.g.,
444 /// the \c T in \c x->T::member
445 ///
446 /// By default, invokes TransformDecl() to transform the declaration.
447 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000448 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
449 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000450 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000451
Douglas Gregor14454802011-02-25 02:25:35 +0000452 /// \brief Transform the given nested-name-specifier with source-location
453 /// information.
454 ///
455 /// By default, transforms all of the types and declarations within the
456 /// nested-name-specifier. Subclasses may override this function to provide
457 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000458 NestedNameSpecifierLoc
459 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
460 QualType ObjectType = QualType(),
461 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000462
Douglas Gregorf816bd72009-09-03 22:13:48 +0000463 /// \brief Transform the given declaration name.
464 ///
465 /// By default, transforms the types of conversion function, constructor,
466 /// and destructor names and then (if needed) rebuilds the declaration name.
467 /// Identifiers and selectors are returned unmodified. Sublcasses may
468 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000469 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000470 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000471
Douglas Gregord6ff3322009-08-04 16:50:30 +0000472 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000473 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000474 /// \param SS The nested-name-specifier that qualifies the template
475 /// name. This nested-name-specifier must already have been transformed.
476 ///
477 /// \param Name The template name to transform.
478 ///
479 /// \param NameLoc The source location of the template name.
480 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000481 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000482 /// access expression, this is the type of the object whose member template
483 /// is being referenced.
484 ///
485 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
486 /// also refers to a name within the current (lexical) scope, this is the
487 /// declaration it refers to.
488 ///
489 /// By default, transforms the template name by transforming the declarations
490 /// and nested-name-specifiers that occur within the template name.
491 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000492 TemplateName
493 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
494 SourceLocation NameLoc,
495 QualType ObjectType = QualType(),
496 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000497
Douglas Gregord6ff3322009-08-04 16:50:30 +0000498 /// \brief Transform the given template argument.
499 ///
Mike Stump11289f42009-09-09 15:08:12 +0000500 /// By default, this operation transforms the type, expression, or
501 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000502 /// new template argument from the transformed result. Subclasses may
503 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000504 ///
505 /// Returns true if there was an error.
506 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000507 TemplateArgumentLoc &Output,
508 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000509
Douglas Gregor62e06f22010-12-20 17:31:10 +0000510 /// \brief Transform the given set of template arguments.
511 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000512 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000513 /// in the input set using \c TransformTemplateArgument(), and appends
514 /// the transformed arguments to the output list.
515 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000516 /// Note that this overload of \c TransformTemplateArguments() is merely
517 /// a convenience function. Subclasses that wish to override this behavior
518 /// should override the iterator-based member template version.
519 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000520 /// \param Inputs The set of template arguments to be transformed.
521 ///
522 /// \param NumInputs The number of template arguments in \p Inputs.
523 ///
524 /// \param Outputs The set of transformed template arguments output by this
525 /// routine.
526 ///
527 /// Returns true if an error occurred.
528 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
529 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000530 TemplateArgumentListInfo &Outputs,
531 bool Uneval = false) {
532 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
533 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000534 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000535
536 /// \brief Transform the given set of template arguments.
537 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000538 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000539 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000540 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000541 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000542 /// \param First An iterator to the first template argument.
543 ///
544 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000545 ///
546 /// \param Outputs The set of transformed template arguments output by this
547 /// routine.
548 ///
549 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000550 template<typename InputIterator>
551 bool TransformTemplateArguments(InputIterator First,
552 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000553 TemplateArgumentListInfo &Outputs,
554 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000555
John McCall0ad16662009-10-29 08:12:44 +0000556 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
557 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
558 TemplateArgumentLoc &ArgLoc);
559
John McCallbcd03502009-12-07 02:54:59 +0000560 /// \brief Fakes up a TypeSourceInfo for a type.
561 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
562 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000563 getDerived().getBaseLocation());
564 }
Mike Stump11289f42009-09-09 15:08:12 +0000565
John McCall550e0c22009-10-21 00:40:46 +0000566#define ABSTRACT_TYPELOC(CLASS, PARENT)
567#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000568 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000569#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000570
Richard Smith2e321552014-11-12 02:00:47 +0000571 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000572 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
573 FunctionProtoTypeLoc TL,
574 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000575 unsigned ThisTypeQuals,
576 Fn TransformExceptionSpec);
577
578 bool TransformExceptionSpec(SourceLocation Loc,
579 FunctionProtoType::ExceptionSpecInfo &ESI,
580 SmallVectorImpl<QualType> &Exceptions,
581 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000582
David Majnemerfad8f482013-10-15 09:33:02 +0000583 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000584
Chad Rosier1dcde962012-08-08 18:46:20 +0000585 QualType
John McCall31f82722010-11-12 08:19:04 +0000586 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
587 TemplateSpecializationTypeLoc TL,
588 TemplateName Template);
589
Chad Rosier1dcde962012-08-08 18:46:20 +0000590 QualType
John McCall31f82722010-11-12 08:19:04 +0000591 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
592 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000593 TemplateName Template,
594 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000595
Nico Weberc153d242014-07-28 00:02:09 +0000596 QualType TransformDependentTemplateSpecializationType(
597 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
598 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000599
John McCall58f10c32010-03-11 09:03:00 +0000600 /// \brief Transforms the parameters of a function type into the
601 /// given vectors.
602 ///
603 /// The result vectors should be kept in sync; null entries in the
604 /// variables vector are acceptable.
605 ///
606 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000607 bool TransformFunctionTypeParams(SourceLocation Loc,
608 ParmVarDecl **Params, unsigned NumParams,
609 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000610 SmallVectorImpl<QualType> &PTypes,
611 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000612
613 /// \brief Transforms a single function-type parameter. Return null
614 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000615 ///
616 /// \param indexAdjustment - A number to add to the parameter's
617 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000618 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000619 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000620 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000621 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000622
John McCall31f82722010-11-12 08:19:04 +0000623 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000624
John McCalldadc5752010-08-24 06:29:42 +0000625 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
626 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000627
Faisal Vali2cba1332013-10-23 06:44:28 +0000628 TemplateParameterList *TransformTemplateParameterList(
629 TemplateParameterList *TPL) {
630 return TPL;
631 }
632
Richard Smithdb2630f2012-10-21 03:28:35 +0000633 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000634
Richard Smithdb2630f2012-10-21 03:28:35 +0000635 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000636 bool IsAddressOfOperand,
637 TypeSourceInfo **RecoveryTSI);
638
639 ExprResult TransformParenDependentScopeDeclRefExpr(
640 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
641 TypeSourceInfo **RecoveryTSI);
642
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000643 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000644
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000645// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
646// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000647#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000648 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000649 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000650#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000651 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000652 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000653#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000654#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000655
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000656#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000657 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000658 OMPClause *Transform ## Class(Class *S);
659#include "clang/Basic/OpenMPKinds.def"
660
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661 /// \brief Build a new pointer type given its pointee type.
662 ///
663 /// By default, performs semantic analysis when building the pointer type.
664 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000665 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666
667 /// \brief Build a new block pointer type given its pointee type.
668 ///
Mike Stump11289f42009-09-09 15:08:12 +0000669 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000670 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000671 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000672
John McCall70dd5f62009-10-30 00:06:24 +0000673 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000674 ///
John McCall70dd5f62009-10-30 00:06:24 +0000675 /// By default, performs semantic analysis when building the
676 /// reference type. Subclasses may override this routine to provide
677 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000678 ///
John McCall70dd5f62009-10-30 00:06:24 +0000679 /// \param LValue whether the type was written with an lvalue sigil
680 /// or an rvalue sigil.
681 QualType RebuildReferenceType(QualType ReferentType,
682 bool LValue,
683 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000684
Douglas Gregord6ff3322009-08-04 16:50:30 +0000685 /// \brief Build a new member pointer type given the pointee type and the
686 /// class type it refers into.
687 ///
688 /// By default, performs semantic analysis when building the member pointer
689 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000690 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
691 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000692
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000693 /// \brief Build an Objective-C object type.
694 ///
695 /// By default, performs semantic analysis when building the object type.
696 /// Subclasses may override this routine to provide different behavior.
697 QualType RebuildObjCObjectType(QualType BaseType,
698 SourceLocation Loc,
699 SourceLocation TypeArgsLAngleLoc,
700 ArrayRef<TypeSourceInfo *> TypeArgs,
701 SourceLocation TypeArgsRAngleLoc,
702 SourceLocation ProtocolLAngleLoc,
703 ArrayRef<ObjCProtocolDecl *> Protocols,
704 ArrayRef<SourceLocation> ProtocolLocs,
705 SourceLocation ProtocolRAngleLoc);
706
707 /// \brief Build a new Objective-C object pointer type given the pointee type.
708 ///
709 /// By default, directly builds the pointer type, with no additional semantic
710 /// analysis.
711 QualType RebuildObjCObjectPointerType(QualType PointeeType,
712 SourceLocation Star);
713
Douglas Gregord6ff3322009-08-04 16:50:30 +0000714 /// \brief Build a new array type given the element type, size
715 /// modifier, size of the array (if known), size expression, and index type
716 /// qualifiers.
717 ///
718 /// By default, performs semantic analysis when building the array type.
719 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000720 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000721 QualType RebuildArrayType(QualType ElementType,
722 ArrayType::ArraySizeModifier SizeMod,
723 const llvm::APInt *Size,
724 Expr *SizeExpr,
725 unsigned IndexTypeQuals,
726 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000727
Douglas Gregord6ff3322009-08-04 16:50:30 +0000728 /// \brief Build a new constant array type given the element type, size
729 /// modifier, (known) size of the array, and index type qualifiers.
730 ///
731 /// By default, performs semantic analysis when building the array type.
732 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000733 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000734 ArrayType::ArraySizeModifier SizeMod,
735 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000736 unsigned IndexTypeQuals,
737 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000738
Douglas Gregord6ff3322009-08-04 16:50:30 +0000739 /// \brief Build a new incomplete array type given the element type, size
740 /// modifier, and index type qualifiers.
741 ///
742 /// By default, performs semantic analysis when building the array type.
743 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000744 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000745 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000746 unsigned IndexTypeQuals,
747 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000748
Mike Stump11289f42009-09-09 15:08:12 +0000749 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000750 /// size modifier, size expression, and index type qualifiers.
751 ///
752 /// By default, performs semantic analysis when building the array type.
753 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000754 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000755 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000756 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000757 unsigned IndexTypeQuals,
758 SourceRange BracketsRange);
759
Mike Stump11289f42009-09-09 15:08:12 +0000760 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000761 /// size modifier, size expression, and index type qualifiers.
762 ///
763 /// By default, performs semantic analysis when building the array type.
764 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000765 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000766 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000767 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000768 unsigned IndexTypeQuals,
769 SourceRange BracketsRange);
770
771 /// \brief Build a new vector type given the element type and
772 /// number of elements.
773 ///
774 /// By default, performs semantic analysis when building the vector type.
775 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000776 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000777 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000778
Douglas Gregord6ff3322009-08-04 16:50:30 +0000779 /// \brief Build a new extended vector type given the element type and
780 /// number of elements.
781 ///
782 /// By default, performs semantic analysis when building the vector type.
783 /// Subclasses may override this routine to provide different behavior.
784 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
785 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000786
787 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000788 /// given the element type and number of elements.
789 ///
790 /// By default, performs semantic analysis when building the vector type.
791 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000792 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000793 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000794 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000795
Douglas Gregord6ff3322009-08-04 16:50:30 +0000796 /// \brief Build a new function type.
797 ///
798 /// By default, performs semantic analysis when building the function type.
799 /// Subclasses may override this routine to provide different behavior.
800 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000801 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000802 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000803
John McCall550e0c22009-10-21 00:40:46 +0000804 /// \brief Build a new unprototyped function type.
805 QualType RebuildFunctionNoProtoType(QualType ResultType);
806
John McCallb96ec562009-12-04 22:46:56 +0000807 /// \brief Rebuild an unresolved typename type, given the decl that
808 /// the UnresolvedUsingTypenameDecl was transformed to.
809 QualType RebuildUnresolvedUsingType(Decl *D);
810
Douglas Gregord6ff3322009-08-04 16:50:30 +0000811 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000812 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000813 return SemaRef.Context.getTypeDeclType(Typedef);
814 }
815
816 /// \brief Build a new class/struct/union type.
817 QualType RebuildRecordType(RecordDecl *Record) {
818 return SemaRef.Context.getTypeDeclType(Record);
819 }
820
821 /// \brief Build a new Enum type.
822 QualType RebuildEnumType(EnumDecl *Enum) {
823 return SemaRef.Context.getTypeDeclType(Enum);
824 }
John McCallfcc33b02009-09-05 00:15:47 +0000825
Mike Stump11289f42009-09-09 15:08:12 +0000826 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000827 ///
828 /// By default, performs semantic analysis when building the typeof type.
829 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000830 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000831
Mike Stump11289f42009-09-09 15:08:12 +0000832 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000833 ///
834 /// By default, builds a new TypeOfType with the given underlying type.
835 QualType RebuildTypeOfType(QualType Underlying);
836
Alexis Hunte852b102011-05-24 22:41:36 +0000837 /// \brief Build a new unary transform type.
838 QualType RebuildUnaryTransformType(QualType BaseType,
839 UnaryTransformType::UTTKind UKind,
840 SourceLocation Loc);
841
Richard Smith74aeef52013-04-26 16:15:35 +0000842 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000843 ///
844 /// By default, performs semantic analysis when building the decltype type.
845 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000846 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000847
Richard Smith74aeef52013-04-26 16:15:35 +0000848 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000849 ///
850 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000851 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000852 // Note, IsDependent is always false here: we implicitly convert an 'auto'
853 // which has been deduced to a dependent type into an undeduced 'auto', so
854 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000855 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
856 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000857 }
858
Douglas Gregord6ff3322009-08-04 16:50:30 +0000859 /// \brief Build a new template specialization type.
860 ///
861 /// By default, performs semantic analysis when building the template
862 /// specialization type. Subclasses may override this routine to provide
863 /// different behavior.
864 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000865 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000866 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000867
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000868 /// \brief Build a new parenthesized type.
869 ///
870 /// By default, builds a new ParenType type from the inner type.
871 /// Subclasses may override this routine to provide different behavior.
872 QualType RebuildParenType(QualType InnerType) {
873 return SemaRef.Context.getParenType(InnerType);
874 }
875
Douglas Gregord6ff3322009-08-04 16:50:30 +0000876 /// \brief Build a new qualified name type.
877 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000878 /// By default, builds a new ElaboratedType type from the keyword,
879 /// the nested-name-specifier and the named type.
880 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000881 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
882 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000883 NestedNameSpecifierLoc QualifierLoc,
884 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000885 return SemaRef.Context.getElaboratedType(Keyword,
886 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000887 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000888 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000889
890 /// \brief Build a new typename type that refers to a template-id.
891 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000892 /// By default, builds a new DependentNameType type from the
893 /// nested-name-specifier and the given type. Subclasses may override
894 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000895 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000896 ElaboratedTypeKeyword Keyword,
897 NestedNameSpecifierLoc QualifierLoc,
898 const IdentifierInfo *Name,
899 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000900 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000901 // Rebuild the template name.
902 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000903 CXXScopeSpec SS;
904 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000905 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000906 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
907 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000908
Douglas Gregora7a795b2011-03-01 20:11:18 +0000909 if (InstName.isNull())
910 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000911
Douglas Gregora7a795b2011-03-01 20:11:18 +0000912 // If it's still dependent, make a dependent specialization.
913 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000914 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
915 QualifierLoc.getNestedNameSpecifier(),
916 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000917 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000918
Douglas Gregora7a795b2011-03-01 20:11:18 +0000919 // Otherwise, make an elaborated type wrapping a non-dependent
920 // specialization.
921 QualType T =
922 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
923 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000924
Craig Topperc3ec1492014-05-26 06:22:03 +0000925 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000926 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000927
928 return SemaRef.Context.getElaboratedType(Keyword,
929 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000930 T);
931 }
932
Douglas Gregord6ff3322009-08-04 16:50:30 +0000933 /// \brief Build a new typename type that refers to an identifier.
934 ///
935 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000936 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000937 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000938 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000939 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000940 NestedNameSpecifierLoc QualifierLoc,
941 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000942 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000943 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000944 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000945
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000946 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000947 // If the name is still dependent, just build a new dependent name type.
948 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000949 return SemaRef.Context.getDependentNameType(Keyword,
950 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000951 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000952 }
953
Abramo Bagnara6150c882010-05-11 21:36:43 +0000954 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000955 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000956 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000957
958 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
959
Abramo Bagnarad7548482010-05-19 21:37:53 +0000960 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000961 // into a non-dependent elaborated-type-specifier. Find the tag we're
962 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000963 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000964 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
965 if (!DC)
966 return QualType();
967
John McCallbf8c5192010-05-27 06:40:31 +0000968 if (SemaRef.RequireCompleteDeclContext(SS, DC))
969 return QualType();
970
Craig Topperc3ec1492014-05-26 06:22:03 +0000971 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000972 SemaRef.LookupQualifiedName(Result, DC);
973 switch (Result.getResultKind()) {
974 case LookupResult::NotFound:
975 case LookupResult::NotFoundInCurrentInstantiation:
976 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000977
Douglas Gregore677daf2010-03-31 22:19:08 +0000978 case LookupResult::Found:
979 Tag = Result.getAsSingle<TagDecl>();
980 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000981
Douglas Gregore677daf2010-03-31 22:19:08 +0000982 case LookupResult::FoundOverloaded:
983 case LookupResult::FoundUnresolvedValue:
984 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000985
Douglas Gregore677daf2010-03-31 22:19:08 +0000986 case LookupResult::Ambiguous:
987 // Let the LookupResult structure handle ambiguities.
988 return QualType();
989 }
990
991 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000992 // Check where the name exists but isn't a tag type and use that to emit
993 // better diagnostics.
994 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
995 SemaRef.LookupQualifiedName(Result, DC);
996 switch (Result.getResultKind()) {
997 case LookupResult::Found:
998 case LookupResult::FoundOverloaded:
999 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001000 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +00001001 unsigned Kind = 0;
1002 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +00001003 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
1004 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +00001005 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
1006 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1007 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001008 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001009 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001010 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001011 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001012 break;
1013 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001014 return QualType();
1015 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001016
Richard Trieucaa33d32011-06-10 03:11:26 +00001017 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001018 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001019 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001020 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1021 return QualType();
1022 }
1023
1024 // Build the elaborated-type-specifier type.
1025 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001026 return SemaRef.Context.getElaboratedType(Keyword,
1027 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001028 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001029 }
Mike Stump11289f42009-09-09 15:08:12 +00001030
Douglas Gregor822d0302011-01-12 17:07:58 +00001031 /// \brief Build a new pack expansion type.
1032 ///
1033 /// By default, builds a new PackExpansionType type from the given pattern.
1034 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001035 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001036 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001037 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001038 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001039 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1040 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001041 }
1042
Eli Friedman0dfb8892011-10-06 23:00:33 +00001043 /// \brief Build a new atomic type given its value type.
1044 ///
1045 /// By default, performs semantic analysis when building the atomic type.
1046 /// Subclasses may override this routine to provide different behavior.
1047 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1048
Douglas Gregor71dc5092009-08-06 06:41:21 +00001049 /// \brief Build a new template name given a nested name specifier, a flag
1050 /// indicating whether the "template" keyword was provided, and the template
1051 /// that the template name refers to.
1052 ///
1053 /// By default, builds the new template name directly. Subclasses may override
1054 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001055 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001056 bool TemplateKW,
1057 TemplateDecl *Template);
1058
Douglas Gregor71dc5092009-08-06 06:41:21 +00001059 /// \brief Build a new template name given a nested name specifier and the
1060 /// name that is referred to as a template.
1061 ///
1062 /// By default, performs semantic analysis to determine whether the name can
1063 /// be resolved to a specific template, then builds the appropriate kind of
1064 /// template name. Subclasses may override this routine to provide different
1065 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001066 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1067 const IdentifierInfo &Name,
1068 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001069 QualType ObjectType,
1070 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001071
Douglas Gregor71395fa2009-11-04 00:56:37 +00001072 /// \brief Build a new template name given a nested name specifier and the
1073 /// overloaded operator name that is referred to as a template.
1074 ///
1075 /// By default, performs semantic analysis to determine whether the name can
1076 /// be resolved to a specific template, then builds the appropriate kind of
1077 /// template name. Subclasses may override this routine to provide different
1078 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001079 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001080 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001081 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001082 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001083
1084 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001085 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001086 ///
1087 /// By default, performs semantic analysis to determine whether the name can
1088 /// be resolved to a specific template, then builds the appropriate kind of
1089 /// template name. Subclasses may override this routine to provide different
1090 /// behavior.
1091 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1092 const TemplateArgument &ArgPack) {
1093 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1094 }
1095
Douglas Gregorebe10102009-08-20 07:17:43 +00001096 /// \brief Build a new compound statement.
1097 ///
1098 /// By default, performs semantic analysis to build the new statement.
1099 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001100 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001101 MultiStmtArg Statements,
1102 SourceLocation RBraceLoc,
1103 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001104 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001105 IsStmtExpr);
1106 }
1107
1108 /// \brief Build a new case statement.
1109 ///
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001112 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001113 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001114 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001115 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001116 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001117 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001118 ColonLoc);
1119 }
Mike Stump11289f42009-09-09 15:08:12 +00001120
Douglas Gregorebe10102009-08-20 07:17:43 +00001121 /// \brief Attach the body to a new case statement.
1122 ///
1123 /// By default, performs semantic analysis to build the new statement.
1124 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001125 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001126 getSema().ActOnCaseStmtBody(S, Body);
1127 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001128 }
Mike Stump11289f42009-09-09 15:08:12 +00001129
Douglas Gregorebe10102009-08-20 07:17:43 +00001130 /// \brief Build a new default statement.
1131 ///
1132 /// By default, performs semantic analysis to build the new statement.
1133 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001134 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001135 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001136 Stmt *SubStmt) {
1137 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001138 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001139 }
Mike Stump11289f42009-09-09 15:08:12 +00001140
Douglas Gregorebe10102009-08-20 07:17:43 +00001141 /// \brief Build a new label statement.
1142 ///
1143 /// By default, performs semantic analysis to build the new statement.
1144 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001145 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1146 SourceLocation ColonLoc, Stmt *SubStmt) {
1147 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001148 }
Mike Stump11289f42009-09-09 15:08:12 +00001149
Richard Smithc202b282012-04-14 00:33:13 +00001150 /// \brief Build a new label statement.
1151 ///
1152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001154 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1155 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001156 Stmt *SubStmt) {
1157 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1158 }
1159
Douglas Gregorebe10102009-08-20 07:17:43 +00001160 /// \brief Build a new "if" statement.
1161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001164 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001165 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001166 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001167 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001168 }
Mike Stump11289f42009-09-09 15:08:12 +00001169
Douglas Gregorebe10102009-08-20 07:17:43 +00001170 /// \brief Start building a new switch statement.
1171 ///
1172 /// By default, performs semantic analysis to build the new statement.
1173 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001174 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001175 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001176 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001177 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001178 }
Mike Stump11289f42009-09-09 15:08:12 +00001179
Douglas Gregorebe10102009-08-20 07:17:43 +00001180 /// \brief Attach the body to the switch statement.
1181 ///
1182 /// By default, performs semantic analysis to build the new statement.
1183 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001184 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001185 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001186 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001187 }
1188
1189 /// \brief Build a new while statement.
1190 ///
1191 /// By default, performs semantic analysis to build the new statement.
1192 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001193 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1194 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001195 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001196 }
Mike Stump11289f42009-09-09 15:08:12 +00001197
Douglas Gregorebe10102009-08-20 07:17:43 +00001198 /// \brief Build a new do-while statement.
1199 ///
1200 /// By default, performs semantic analysis to build the new statement.
1201 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001202 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001203 SourceLocation WhileLoc, SourceLocation LParenLoc,
1204 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001205 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1206 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001207 }
1208
1209 /// \brief Build a new for statement.
1210 ///
1211 /// By default, performs semantic analysis to build the new statement.
1212 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001213 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001214 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001215 VarDecl *CondVar, Sema::FullExprArg Inc,
1216 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001217 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001218 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 }
Mike Stump11289f42009-09-09 15:08:12 +00001220
Douglas Gregorebe10102009-08-20 07:17:43 +00001221 /// \brief Build a new goto statement.
1222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001225 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1226 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001227 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001228 }
1229
1230 /// \brief Build a new indirect goto statement.
1231 ///
1232 /// By default, performs semantic analysis to build the new statement.
1233 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001234 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001235 SourceLocation StarLoc,
1236 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001237 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001238 }
Mike Stump11289f42009-09-09 15:08:12 +00001239
Douglas Gregorebe10102009-08-20 07:17:43 +00001240 /// \brief Build a new return statement.
1241 ///
1242 /// By default, performs semantic analysis to build the new statement.
1243 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001244 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001245 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001246 }
Mike Stump11289f42009-09-09 15:08:12 +00001247
Douglas Gregorebe10102009-08-20 07:17:43 +00001248 /// \brief Build a new declaration statement.
1249 ///
1250 /// By default, performs semantic analysis to build the new statement.
1251 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001252 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001253 SourceLocation StartLoc, SourceLocation EndLoc) {
1254 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001255 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001256 }
Mike Stump11289f42009-09-09 15:08:12 +00001257
Anders Carlssonaaeef072010-01-24 05:50:09 +00001258 /// \brief Build a new inline asm statement.
1259 ///
1260 /// By default, performs semantic analysis to build the new statement.
1261 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001262 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1263 bool IsVolatile, unsigned NumOutputs,
1264 unsigned NumInputs, IdentifierInfo **Names,
1265 MultiExprArg Constraints, MultiExprArg Exprs,
1266 Expr *AsmString, MultiExprArg Clobbers,
1267 SourceLocation RParenLoc) {
1268 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1269 NumInputs, Names, Constraints, Exprs,
1270 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001271 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001272
Chad Rosier32503022012-06-11 20:47:18 +00001273 /// \brief Build a new MS style inline asm statement.
1274 ///
1275 /// By default, performs semantic analysis to build the new statement.
1276 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001277 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001278 ArrayRef<Token> AsmToks,
1279 StringRef AsmString,
1280 unsigned NumOutputs, unsigned NumInputs,
1281 ArrayRef<StringRef> Constraints,
1282 ArrayRef<StringRef> Clobbers,
1283 ArrayRef<Expr*> Exprs,
1284 SourceLocation EndLoc) {
1285 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1286 NumOutputs, NumInputs,
1287 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001288 }
1289
James Dennett2a4d13c2012-06-15 07:13:21 +00001290 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001291 ///
1292 /// By default, performs semantic analysis to build the new statement.
1293 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001294 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001295 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001296 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001297 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001298 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001299 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001300 }
1301
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001302 /// \brief Rebuild an Objective-C exception declaration.
1303 ///
1304 /// By default, performs semantic analysis to build the new declaration.
1305 /// Subclasses may override this routine to provide different behavior.
1306 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1307 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001308 return getSema().BuildObjCExceptionDecl(TInfo, T,
1309 ExceptionDecl->getInnerLocStart(),
1310 ExceptionDecl->getLocation(),
1311 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001312 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001313
James Dennett2a4d13c2012-06-15 07:13:21 +00001314 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001315 ///
1316 /// By default, performs semantic analysis to build the new statement.
1317 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001318 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001319 SourceLocation RParenLoc,
1320 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001321 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001322 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001323 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001324 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001325
James Dennett2a4d13c2012-06-15 07:13:21 +00001326 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001327 ///
1328 /// By default, performs semantic analysis to build the new statement.
1329 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001330 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001331 Stmt *Body) {
1332 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001333 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001334
James Dennett2a4d13c2012-06-15 07:13:21 +00001335 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001336 ///
1337 /// By default, performs semantic analysis to build the new statement.
1338 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001339 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001340 Expr *Operand) {
1341 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001342 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001343
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001344 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001345 ///
1346 /// By default, performs semantic analysis to build the new statement.
1347 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001348 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001349 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001350 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001351 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001352 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001353 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001354 return getSema().ActOnOpenMPExecutableDirective(
1355 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001356 }
1357
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001358 /// \brief Build a new OpenMP 'if' clause.
1359 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001360 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001361 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001362 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1363 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001364 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001365 SourceLocation NameModifierLoc,
1366 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001367 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001368 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1369 LParenLoc, NameModifierLoc, ColonLoc,
1370 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001371 }
1372
Alexey Bataev3778b602014-07-17 07:32:53 +00001373 /// \brief Build a new OpenMP 'final' clause.
1374 ///
1375 /// By default, performs semantic analysis to build the new OpenMP clause.
1376 /// Subclasses may override this routine to provide different behavior.
1377 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1378 SourceLocation LParenLoc,
1379 SourceLocation EndLoc) {
1380 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1381 EndLoc);
1382 }
1383
Alexey Bataev568a8332014-03-06 06:15:19 +00001384 /// \brief Build a new OpenMP 'num_threads' clause.
1385 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001386 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001387 /// Subclasses may override this routine to provide different behavior.
1388 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1389 SourceLocation StartLoc,
1390 SourceLocation LParenLoc,
1391 SourceLocation EndLoc) {
1392 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1393 LParenLoc, EndLoc);
1394 }
1395
Alexey Bataev62c87d22014-03-21 04:51:18 +00001396 /// \brief Build a new OpenMP 'safelen' clause.
1397 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001398 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001399 /// Subclasses may override this routine to provide different behavior.
1400 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1401 SourceLocation LParenLoc,
1402 SourceLocation EndLoc) {
1403 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1404 }
1405
Alexey Bataev66b15b52015-08-21 11:14:16 +00001406 /// \brief Build a new OpenMP 'simdlen' clause.
1407 ///
1408 /// By default, performs semantic analysis to build the new OpenMP clause.
1409 /// Subclasses may override this routine to provide different behavior.
1410 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1411 SourceLocation LParenLoc,
1412 SourceLocation EndLoc) {
1413 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1414 }
1415
Alexander Musman8bd31e62014-05-27 15:12:19 +00001416 /// \brief Build a new OpenMP 'collapse' clause.
1417 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001418 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001419 /// Subclasses may override this routine to provide different behavior.
1420 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1421 SourceLocation LParenLoc,
1422 SourceLocation EndLoc) {
1423 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1424 EndLoc);
1425 }
1426
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001427 /// \brief Build a new OpenMP 'default' clause.
1428 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001429 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001430 /// Subclasses may override this routine to provide different behavior.
1431 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1432 SourceLocation KindKwLoc,
1433 SourceLocation StartLoc,
1434 SourceLocation LParenLoc,
1435 SourceLocation EndLoc) {
1436 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1437 StartLoc, LParenLoc, EndLoc);
1438 }
1439
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001440 /// \brief Build a new OpenMP 'proc_bind' clause.
1441 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001442 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001443 /// Subclasses may override this routine to provide different behavior.
1444 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1445 SourceLocation KindKwLoc,
1446 SourceLocation StartLoc,
1447 SourceLocation LParenLoc,
1448 SourceLocation EndLoc) {
1449 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1450 StartLoc, LParenLoc, EndLoc);
1451 }
1452
Alexey Bataev56dafe82014-06-20 07:16:17 +00001453 /// \brief Build a new OpenMP 'schedule' clause.
1454 ///
1455 /// By default, performs semantic analysis to build the new OpenMP clause.
1456 /// Subclasses may override this routine to provide different behavior.
1457 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1458 Expr *ChunkSize,
1459 SourceLocation StartLoc,
1460 SourceLocation LParenLoc,
1461 SourceLocation KindLoc,
1462 SourceLocation CommaLoc,
1463 SourceLocation EndLoc) {
1464 return getSema().ActOnOpenMPScheduleClause(
1465 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1466 }
1467
Alexey Bataev10e775f2015-07-30 11:36:16 +00001468 /// \brief Build a new OpenMP 'ordered' clause.
1469 ///
1470 /// By default, performs semantic analysis to build the new OpenMP clause.
1471 /// Subclasses may override this routine to provide different behavior.
1472 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1473 SourceLocation EndLoc,
1474 SourceLocation LParenLoc, Expr *Num) {
1475 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1476 }
1477
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001478 /// \brief Build a new OpenMP 'private' clause.
1479 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001480 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001481 /// Subclasses may override this routine to provide different behavior.
1482 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1483 SourceLocation StartLoc,
1484 SourceLocation LParenLoc,
1485 SourceLocation EndLoc) {
1486 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1487 EndLoc);
1488 }
1489
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001490 /// \brief Build a new OpenMP 'firstprivate' clause.
1491 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001492 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001493 /// Subclasses may override this routine to provide different behavior.
1494 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1495 SourceLocation StartLoc,
1496 SourceLocation LParenLoc,
1497 SourceLocation EndLoc) {
1498 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1499 EndLoc);
1500 }
1501
Alexander Musman1bb328c2014-06-04 13:06:39 +00001502 /// \brief Build a new OpenMP 'lastprivate' clause.
1503 ///
1504 /// By default, performs semantic analysis to build the new OpenMP clause.
1505 /// Subclasses may override this routine to provide different behavior.
1506 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1507 SourceLocation StartLoc,
1508 SourceLocation LParenLoc,
1509 SourceLocation EndLoc) {
1510 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1511 EndLoc);
1512 }
1513
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001514 /// \brief Build a new OpenMP 'shared' clause.
1515 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001516 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001517 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001518 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1519 SourceLocation StartLoc,
1520 SourceLocation LParenLoc,
1521 SourceLocation EndLoc) {
1522 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1523 EndLoc);
1524 }
1525
Alexey Bataevc5e02582014-06-16 07:08:35 +00001526 /// \brief Build a new OpenMP 'reduction' clause.
1527 ///
1528 /// By default, performs semantic analysis to build the new statement.
1529 /// Subclasses may override this routine to provide different behavior.
1530 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1531 SourceLocation StartLoc,
1532 SourceLocation LParenLoc,
1533 SourceLocation ColonLoc,
1534 SourceLocation EndLoc,
1535 CXXScopeSpec &ReductionIdScopeSpec,
1536 const DeclarationNameInfo &ReductionId) {
1537 return getSema().ActOnOpenMPReductionClause(
1538 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1539 ReductionId);
1540 }
1541
Alexander Musman8dba6642014-04-22 13:09:42 +00001542 /// \brief Build a new OpenMP 'linear' clause.
1543 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001544 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001545 /// Subclasses may override this routine to provide different behavior.
1546 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1547 SourceLocation StartLoc,
1548 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001549 OpenMPLinearClauseKind Modifier,
1550 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001551 SourceLocation ColonLoc,
1552 SourceLocation EndLoc) {
1553 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001554 Modifier, ModifierLoc, ColonLoc,
1555 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001556 }
1557
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001558 /// \brief Build a new OpenMP 'aligned' clause.
1559 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001560 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001561 /// Subclasses may override this routine to provide different behavior.
1562 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1563 SourceLocation StartLoc,
1564 SourceLocation LParenLoc,
1565 SourceLocation ColonLoc,
1566 SourceLocation EndLoc) {
1567 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1568 LParenLoc, ColonLoc, EndLoc);
1569 }
1570
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001571 /// \brief Build a new OpenMP 'copyin' clause.
1572 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001573 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001574 /// Subclasses may override this routine to provide different behavior.
1575 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1576 SourceLocation StartLoc,
1577 SourceLocation LParenLoc,
1578 SourceLocation EndLoc) {
1579 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1580 EndLoc);
1581 }
1582
Alexey Bataevbae9a792014-06-27 10:37:06 +00001583 /// \brief Build a new OpenMP 'copyprivate' clause.
1584 ///
1585 /// By default, performs semantic analysis to build the new OpenMP clause.
1586 /// Subclasses may override this routine to provide different behavior.
1587 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1588 SourceLocation StartLoc,
1589 SourceLocation LParenLoc,
1590 SourceLocation EndLoc) {
1591 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1592 EndLoc);
1593 }
1594
Alexey Bataev6125da92014-07-21 11:26:11 +00001595 /// \brief Build a new OpenMP 'flush' pseudo clause.
1596 ///
1597 /// By default, performs semantic analysis to build the new OpenMP clause.
1598 /// Subclasses may override this routine to provide different behavior.
1599 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1600 SourceLocation StartLoc,
1601 SourceLocation LParenLoc,
1602 SourceLocation EndLoc) {
1603 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1604 EndLoc);
1605 }
1606
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001607 /// \brief Build a new OpenMP 'depend' pseudo clause.
1608 ///
1609 /// By default, performs semantic analysis to build the new OpenMP clause.
1610 /// Subclasses may override this routine to provide different behavior.
1611 OMPClause *
1612 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1613 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1614 SourceLocation StartLoc, SourceLocation LParenLoc,
1615 SourceLocation EndLoc) {
1616 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1617 StartLoc, LParenLoc, EndLoc);
1618 }
1619
Michael Wonge710d542015-08-07 16:16:36 +00001620 /// \brief Build a new OpenMP 'device' clause.
1621 ///
1622 /// By default, performs semantic analysis to build the new statement.
1623 /// Subclasses may override this routine to provide different behavior.
1624 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1625 SourceLocation LParenLoc,
1626 SourceLocation EndLoc) {
1627 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
1628 EndLoc);
1629 }
1630
James Dennett2a4d13c2012-06-15 07:13:21 +00001631 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001632 ///
1633 /// By default, performs semantic analysis to build the new statement.
1634 /// Subclasses may override this routine to provide different behavior.
1635 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1636 Expr *object) {
1637 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1638 }
1639
James Dennett2a4d13c2012-06-15 07:13:21 +00001640 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001641 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001642 /// By default, performs semantic analysis to build the new statement.
1643 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001644 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001645 Expr *Object, Stmt *Body) {
1646 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001647 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001648
James Dennett2a4d13c2012-06-15 07:13:21 +00001649 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001650 ///
1651 /// By default, performs semantic analysis to build the new statement.
1652 /// Subclasses may override this routine to provide different behavior.
1653 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1654 Stmt *Body) {
1655 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1656 }
John McCall53848232011-07-27 01:07:15 +00001657
Douglas Gregorf68a5082010-04-22 23:10:45 +00001658 /// \brief Build a new Objective-C fast enumeration statement.
1659 ///
1660 /// By default, performs semantic analysis to build the new statement.
1661 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001662 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001663 Stmt *Element,
1664 Expr *Collection,
1665 SourceLocation RParenLoc,
1666 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001667 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001668 Element,
John McCallb268a282010-08-23 23:25:46 +00001669 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001670 RParenLoc);
1671 if (ForEachStmt.isInvalid())
1672 return StmtError();
1673
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001674 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001675 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001676
Douglas Gregorebe10102009-08-20 07:17:43 +00001677 /// \brief Build a new C++ exception declaration.
1678 ///
1679 /// By default, performs semantic analysis to build the new decaration.
1680 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001681 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001682 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001683 SourceLocation StartLoc,
1684 SourceLocation IdLoc,
1685 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001686 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001687 StartLoc, IdLoc, Id);
1688 if (Var)
1689 getSema().CurContext->addDecl(Var);
1690 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001691 }
1692
1693 /// \brief Build a new C++ catch statement.
1694 ///
1695 /// By default, performs semantic analysis to build the new statement.
1696 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001697 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001698 VarDecl *ExceptionDecl,
1699 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001700 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1701 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001702 }
Mike Stump11289f42009-09-09 15:08:12 +00001703
Douglas Gregorebe10102009-08-20 07:17:43 +00001704 /// \brief Build a new C++ try statement.
1705 ///
1706 /// By default, performs semantic analysis to build the new statement.
1707 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001708 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1709 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001710 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001711 }
Mike Stump11289f42009-09-09 15:08:12 +00001712
Richard Smith02e85f32011-04-14 22:09:26 +00001713 /// \brief Build a new C++0x range-based for statement.
1714 ///
1715 /// By default, performs semantic analysis to build the new statement.
1716 /// Subclasses may override this routine to provide different behavior.
1717 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1718 SourceLocation ColonLoc,
1719 Stmt *Range, Stmt *BeginEnd,
1720 Expr *Cond, Expr *Inc,
1721 Stmt *LoopVar,
1722 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001723 // If we've just learned that the range is actually an Objective-C
1724 // collection, treat this as an Objective-C fast enumeration loop.
1725 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1726 if (RangeStmt->isSingleDecl()) {
1727 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001728 if (RangeVar->isInvalidDecl())
1729 return StmtError();
1730
Douglas Gregorf7106af2013-04-08 18:40:13 +00001731 Expr *RangeExpr = RangeVar->getInit();
1732 if (!RangeExpr->isTypeDependent() &&
1733 RangeExpr->getType()->isObjCObjectPointerType())
1734 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1735 RParenLoc);
1736 }
1737 }
1738 }
1739
Richard Smith02e85f32011-04-14 22:09:26 +00001740 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001741 Cond, Inc, LoopVar, RParenLoc,
1742 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001743 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001744
1745 /// \brief Build a new C++0x range-based for statement.
1746 ///
1747 /// By default, performs semantic analysis to build the new statement.
1748 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001749 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001750 bool IsIfExists,
1751 NestedNameSpecifierLoc QualifierLoc,
1752 DeclarationNameInfo NameInfo,
1753 Stmt *Nested) {
1754 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1755 QualifierLoc, NameInfo, Nested);
1756 }
1757
Richard Smith02e85f32011-04-14 22:09:26 +00001758 /// \brief Attach body to a C++0x range-based for statement.
1759 ///
1760 /// By default, performs semantic analysis to finish the new statement.
1761 /// Subclasses may override this routine to provide different behavior.
1762 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1763 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1764 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001765
David Majnemerfad8f482013-10-15 09:33:02 +00001766 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001767 Stmt *TryBlock, Stmt *Handler) {
1768 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001769 }
1770
David Majnemerfad8f482013-10-15 09:33:02 +00001771 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001772 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001773 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001774 }
1775
David Majnemerfad8f482013-10-15 09:33:02 +00001776 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001777 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001778 }
1779
Alexey Bataevec474782014-10-09 08:45:04 +00001780 /// \brief Build a new predefined expression.
1781 ///
1782 /// By default, performs semantic analysis to build the new expression.
1783 /// Subclasses may override this routine to provide different behavior.
1784 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1785 PredefinedExpr::IdentType IT) {
1786 return getSema().BuildPredefinedExpr(Loc, IT);
1787 }
1788
Douglas Gregora16548e2009-08-11 05:31:07 +00001789 /// \brief Build a new expression that references a declaration.
1790 ///
1791 /// By default, performs semantic analysis to build the new expression.
1792 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001793 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001794 LookupResult &R,
1795 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001796 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1797 }
1798
1799
1800 /// \brief Build a new expression that references a declaration.
1801 ///
1802 /// By default, performs semantic analysis to build the new expression.
1803 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001804 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001805 ValueDecl *VD,
1806 const DeclarationNameInfo &NameInfo,
1807 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001808 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001809 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001810
1811 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001812
1813 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001814 }
Mike Stump11289f42009-09-09 15:08:12 +00001815
Douglas Gregora16548e2009-08-11 05:31:07 +00001816 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001817 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001818 /// By default, performs semantic analysis to build the new expression.
1819 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001820 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001821 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001822 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001823 }
1824
Douglas Gregorad8a3362009-09-04 17:36:40 +00001825 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001826 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001827 /// By default, performs semantic analysis to build the new expression.
1828 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001829 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001830 SourceLocation OperatorLoc,
1831 bool isArrow,
1832 CXXScopeSpec &SS,
1833 TypeSourceInfo *ScopeType,
1834 SourceLocation CCLoc,
1835 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001836 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001837
Douglas Gregora16548e2009-08-11 05:31:07 +00001838 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001839 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001840 /// By default, performs semantic analysis to build the new expression.
1841 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001842 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001843 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001844 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001845 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001846 }
Mike Stump11289f42009-09-09 15:08:12 +00001847
Douglas Gregor882211c2010-04-28 22:16:22 +00001848 /// \brief Build a new builtin offsetof expression.
1849 ///
1850 /// By default, performs semantic analysis to build the new expression.
1851 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001852 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001853 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001854 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001855 unsigned NumComponents,
1856 SourceLocation RParenLoc) {
1857 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1858 NumComponents, RParenLoc);
1859 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001860
1861 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001862 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001863 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001864 /// By default, performs semantic analysis to build the new expression.
1865 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001866 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1867 SourceLocation OpLoc,
1868 UnaryExprOrTypeTrait ExprKind,
1869 SourceRange R) {
1870 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001871 }
1872
Peter Collingbournee190dee2011-03-11 19:24:49 +00001873 /// \brief Build a new sizeof, alignof or vec step expression with an
1874 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001875 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001876 /// By default, performs semantic analysis to build the new expression.
1877 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001878 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1879 UnaryExprOrTypeTrait ExprKind,
1880 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001881 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001882 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001883 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001884 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001885
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001886 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001887 }
Mike Stump11289f42009-09-09 15:08:12 +00001888
Douglas Gregora16548e2009-08-11 05:31:07 +00001889 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001890 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001891 /// By default, performs semantic analysis to build the new expression.
1892 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001893 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001894 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001895 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001896 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001897 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001898 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001899 RBracketLoc);
1900 }
1901
Alexey Bataev1a3320e2015-08-25 14:24:04 +00001902 /// \brief Build a new array section expression.
1903 ///
1904 /// By default, performs semantic analysis to build the new expression.
1905 /// Subclasses may override this routine to provide different behavior.
1906 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
1907 Expr *LowerBound,
1908 SourceLocation ColonLoc, Expr *Length,
1909 SourceLocation RBracketLoc) {
1910 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
1911 ColonLoc, Length, RBracketLoc);
1912 }
1913
Douglas Gregora16548e2009-08-11 05:31:07 +00001914 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001915 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001916 /// By default, performs semantic analysis to build the new expression.
1917 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001918 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001919 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001920 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001921 Expr *ExecConfig = nullptr) {
1922 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001923 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001924 }
1925
1926 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001927 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001928 /// By default, performs semantic analysis to build the new expression.
1929 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001930 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001931 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001932 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001933 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001934 const DeclarationNameInfo &MemberNameInfo,
1935 ValueDecl *Member,
1936 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001937 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001938 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001939 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1940 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001941 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001942 // We have a reference to an unnamed field. This is always the
1943 // base of an anonymous struct/union member access, i.e. the
1944 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001945 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001946 assert(Member->getType()->isRecordType() &&
1947 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001948
Richard Smithcab9a7d2011-10-26 19:06:56 +00001949 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001950 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001951 QualifierLoc.getNestedNameSpecifier(),
1952 FoundDecl, Member);
1953 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001954 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001955 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001956 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00001957 MemberExpr *ME = new (getSema().Context)
1958 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
1959 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001960 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001961 }
Mike Stump11289f42009-09-09 15:08:12 +00001962
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001963 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001964 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001965
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001966 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001967 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001968
John McCall16df1e52010-03-30 21:47:33 +00001969 // FIXME: this involves duplicating earlier analysis in a lot of
1970 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001971 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001972 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001973 R.resolveKind();
1974
John McCallb268a282010-08-23 23:25:46 +00001975 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001976 SS, TemplateKWLoc,
1977 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00001978 R, ExplicitTemplateArgs,
1979 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001980 }
Mike Stump11289f42009-09-09 15:08:12 +00001981
Douglas Gregora16548e2009-08-11 05:31:07 +00001982 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001983 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001984 /// By default, performs semantic analysis to build the new expression.
1985 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001986 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001987 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001988 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001989 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001990 }
1991
1992 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001993 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001994 /// By default, performs semantic analysis to build the new expression.
1995 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001996 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001997 SourceLocation QuestionLoc,
1998 Expr *LHS,
1999 SourceLocation ColonLoc,
2000 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002001 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2002 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 }
2004
Douglas Gregora16548e2009-08-11 05:31:07 +00002005 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002006 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002007 /// By default, performs semantic analysis to build the new expression.
2008 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002009 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002010 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002011 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002012 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002013 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002014 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002015 }
Mike Stump11289f42009-09-09 15:08:12 +00002016
Douglas Gregora16548e2009-08-11 05:31:07 +00002017 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002018 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 /// By default, performs semantic analysis to build the new expression.
2020 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002021 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002022 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002023 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002024 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002025 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002026 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002027 }
Mike Stump11289f42009-09-09 15:08:12 +00002028
Douglas Gregora16548e2009-08-11 05:31:07 +00002029 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002030 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002031 /// By default, performs semantic analysis to build the new expression.
2032 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002033 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002034 SourceLocation OpLoc,
2035 SourceLocation AccessorLoc,
2036 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002037
John McCall10eae182009-11-30 22:42:35 +00002038 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002039 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002040 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002041 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002042 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002043 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002044 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002045 /* TemplateArgs */ nullptr,
2046 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002047 }
Mike Stump11289f42009-09-09 15:08:12 +00002048
Douglas Gregora16548e2009-08-11 05:31:07 +00002049 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002050 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002051 /// By default, performs semantic analysis to build the new expression.
2052 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002053 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002054 MultiExprArg Inits,
2055 SourceLocation RBraceLoc,
2056 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002057 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002058 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002059 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002060 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002061
Douglas Gregord3d93062009-11-09 17:16:50 +00002062 // Patch in the result type we were given, which may have been computed
2063 // when the initial InitListExpr was built.
2064 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2065 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002066 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002067 }
Mike Stump11289f42009-09-09 15:08:12 +00002068
Douglas Gregora16548e2009-08-11 05:31:07 +00002069 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002070 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002071 /// By default, performs semantic analysis to build the new expression.
2072 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002073 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002074 MultiExprArg ArrayExprs,
2075 SourceLocation EqualOrColonLoc,
2076 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002077 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002078 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002079 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002080 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002081 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002082 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002083
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002084 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002085 }
Mike Stump11289f42009-09-09 15:08:12 +00002086
Douglas Gregora16548e2009-08-11 05:31:07 +00002087 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002088 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002089 /// By default, builds the implicit value initialization without performing
2090 /// any semantic analysis. Subclasses may override this routine to provide
2091 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002092 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002093 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002094 }
Mike Stump11289f42009-09-09 15:08:12 +00002095
Douglas Gregora16548e2009-08-11 05:31:07 +00002096 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002097 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002098 /// By default, performs semantic analysis to build the new expression.
2099 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002100 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002101 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002102 SourceLocation RParenLoc) {
2103 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002104 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002105 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002106 }
2107
2108 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002109 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002110 /// By default, performs semantic analysis to build the new expression.
2111 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002112 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002113 MultiExprArg SubExprs,
2114 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002115 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002116 }
Mike Stump11289f42009-09-09 15:08:12 +00002117
Douglas Gregora16548e2009-08-11 05:31:07 +00002118 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002119 ///
2120 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002121 /// rather than attempting to map the label statement itself.
2122 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002123 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002124 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002125 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002126 }
Mike Stump11289f42009-09-09 15:08:12 +00002127
Douglas Gregora16548e2009-08-11 05:31:07 +00002128 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002129 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002130 /// By default, performs semantic analysis to build the new expression.
2131 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002132 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002133 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002134 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002135 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002136 }
Mike Stump11289f42009-09-09 15:08:12 +00002137
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 /// \brief Build a new __builtin_choose_expr expression.
2139 ///
2140 /// By default, performs semantic analysis to build the new expression.
2141 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002142 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002143 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002144 SourceLocation RParenLoc) {
2145 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002146 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002147 RParenLoc);
2148 }
Mike Stump11289f42009-09-09 15:08:12 +00002149
Peter Collingbourne91147592011-04-15 00:35:48 +00002150 /// \brief Build a new generic selection expression.
2151 ///
2152 /// By default, performs semantic analysis to build the new expression.
2153 /// Subclasses may override this routine to provide different behavior.
2154 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2155 SourceLocation DefaultLoc,
2156 SourceLocation RParenLoc,
2157 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002158 ArrayRef<TypeSourceInfo *> Types,
2159 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002160 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002161 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002162 }
2163
Douglas Gregora16548e2009-08-11 05:31:07 +00002164 /// \brief Build a new overloaded operator call expression.
2165 ///
2166 /// By default, performs semantic analysis to build the new expression.
2167 /// The semantic analysis provides the behavior of template instantiation,
2168 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002169 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002170 /// argument-dependent lookup, etc. Subclasses may override this routine to
2171 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002172 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002173 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002174 Expr *Callee,
2175 Expr *First,
2176 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002177
2178 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002179 /// reinterpret_cast.
2180 ///
2181 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002182 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002183 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002184 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002185 Stmt::StmtClass Class,
2186 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002187 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002188 SourceLocation RAngleLoc,
2189 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002190 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002191 SourceLocation RParenLoc) {
2192 switch (Class) {
2193 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002194 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002195 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002196 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002197
2198 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002199 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002200 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002201 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002202
Douglas Gregora16548e2009-08-11 05:31:07 +00002203 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002204 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002205 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002206 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002207 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002208
Douglas Gregora16548e2009-08-11 05:31:07 +00002209 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002210 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002211 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002212 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002213
Douglas Gregora16548e2009-08-11 05:31:07 +00002214 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002215 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002216 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002217 }
Mike Stump11289f42009-09-09 15:08:12 +00002218
Douglas Gregora16548e2009-08-11 05:31:07 +00002219 /// \brief Build a new C++ static_cast expression.
2220 ///
2221 /// By default, performs semantic analysis to build the new expression.
2222 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002223 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002224 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002225 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002226 SourceLocation RAngleLoc,
2227 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002228 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002229 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002230 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002231 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002232 SourceRange(LAngleLoc, RAngleLoc),
2233 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002234 }
2235
2236 /// \brief Build a new C++ dynamic_cast expression.
2237 ///
2238 /// By default, performs semantic analysis to build the new expression.
2239 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002240 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002241 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002242 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002243 SourceLocation RAngleLoc,
2244 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002245 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002246 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002247 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002248 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002249 SourceRange(LAngleLoc, RAngleLoc),
2250 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002251 }
2252
2253 /// \brief Build a new C++ reinterpret_cast expression.
2254 ///
2255 /// By default, performs semantic analysis to build the new expression.
2256 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002257 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002258 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002259 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002260 SourceLocation RAngleLoc,
2261 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002262 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002263 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002264 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002265 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002266 SourceRange(LAngleLoc, RAngleLoc),
2267 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002268 }
2269
2270 /// \brief Build a new C++ const_cast expression.
2271 ///
2272 /// By default, performs semantic analysis to build the new expression.
2273 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002274 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002275 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002276 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002277 SourceLocation RAngleLoc,
2278 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002279 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002280 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002281 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002282 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002283 SourceRange(LAngleLoc, RAngleLoc),
2284 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002285 }
Mike Stump11289f42009-09-09 15:08:12 +00002286
Douglas Gregora16548e2009-08-11 05:31:07 +00002287 /// \brief Build a new C++ functional-style cast expression.
2288 ///
2289 /// By default, performs semantic analysis to build the new expression.
2290 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002291 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2292 SourceLocation LParenLoc,
2293 Expr *Sub,
2294 SourceLocation RParenLoc) {
2295 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002296 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002297 RParenLoc);
2298 }
Mike Stump11289f42009-09-09 15:08:12 +00002299
Douglas Gregora16548e2009-08-11 05:31:07 +00002300 /// \brief Build a new C++ typeid(type) expression.
2301 ///
2302 /// By default, performs semantic analysis to build the new expression.
2303 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002304 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002305 SourceLocation TypeidLoc,
2306 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002307 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002308 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002309 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002310 }
Mike Stump11289f42009-09-09 15:08:12 +00002311
Francois Pichet9f4f2072010-09-08 12:20:18 +00002312
Douglas Gregora16548e2009-08-11 05:31:07 +00002313 /// \brief Build a new C++ typeid(expr) expression.
2314 ///
2315 /// By default, performs semantic analysis to build the new expression.
2316 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002317 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002318 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002319 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002320 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002321 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002322 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002323 }
2324
Francois Pichet9f4f2072010-09-08 12:20:18 +00002325 /// \brief Build a new C++ __uuidof(type) expression.
2326 ///
2327 /// By default, performs semantic analysis to build the new expression.
2328 /// Subclasses may override this routine to provide different behavior.
2329 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2330 SourceLocation TypeidLoc,
2331 TypeSourceInfo *Operand,
2332 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002333 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002334 RParenLoc);
2335 }
2336
2337 /// \brief Build a new C++ __uuidof(expr) expression.
2338 ///
2339 /// By default, performs semantic analysis to build the new expression.
2340 /// Subclasses may override this routine to provide different behavior.
2341 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2342 SourceLocation TypeidLoc,
2343 Expr *Operand,
2344 SourceLocation RParenLoc) {
2345 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2346 RParenLoc);
2347 }
2348
Douglas Gregora16548e2009-08-11 05:31:07 +00002349 /// \brief Build a new C++ "this" expression.
2350 ///
2351 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002352 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002353 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002354 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002355 QualType ThisType,
2356 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002357 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002358 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002359 }
2360
2361 /// \brief Build a new C++ throw expression.
2362 ///
2363 /// By default, performs semantic analysis to build the new expression.
2364 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002365 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2366 bool IsThrownVariableInScope) {
2367 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002368 }
2369
2370 /// \brief Build a new C++ default-argument expression.
2371 ///
2372 /// By default, builds a new default-argument expression, which does not
2373 /// require any semantic analysis. Subclasses may override this routine to
2374 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002375 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002376 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002377 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002378 }
2379
Richard Smith852c9db2013-04-20 22:23:05 +00002380 /// \brief Build a new C++11 default-initialization expression.
2381 ///
2382 /// By default, builds a new default field initialization expression, which
2383 /// does not require any semantic analysis. Subclasses may override this
2384 /// routine to provide different behavior.
2385 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2386 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002387 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002388 }
2389
Douglas Gregora16548e2009-08-11 05:31:07 +00002390 /// \brief Build a new C++ zero-initialization expression.
2391 ///
2392 /// By default, performs semantic analysis to build the new expression.
2393 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002394 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2395 SourceLocation LParenLoc,
2396 SourceLocation RParenLoc) {
2397 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002398 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002399 }
Mike Stump11289f42009-09-09 15:08:12 +00002400
Douglas Gregora16548e2009-08-11 05:31:07 +00002401 /// \brief Build a new C++ "new" expression.
2402 ///
2403 /// By default, performs semantic analysis to build the new expression.
2404 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002405 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002406 bool UseGlobal,
2407 SourceLocation PlacementLParen,
2408 MultiExprArg PlacementArgs,
2409 SourceLocation PlacementRParen,
2410 SourceRange TypeIdParens,
2411 QualType AllocatedType,
2412 TypeSourceInfo *AllocatedTypeInfo,
2413 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002414 SourceRange DirectInitRange,
2415 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002416 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002417 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002418 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002419 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002420 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002421 AllocatedType,
2422 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002423 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002424 DirectInitRange,
2425 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002426 }
Mike Stump11289f42009-09-09 15:08:12 +00002427
Douglas Gregora16548e2009-08-11 05:31:07 +00002428 /// \brief Build a new C++ "delete" expression.
2429 ///
2430 /// By default, performs semantic analysis to build the new expression.
2431 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002432 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002433 bool IsGlobalDelete,
2434 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002435 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002436 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002437 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002438 }
Mike Stump11289f42009-09-09 15:08:12 +00002439
Douglas Gregor29c42f22012-02-24 07:38:34 +00002440 /// \brief Build a new type trait expression.
2441 ///
2442 /// By default, performs semantic analysis to build the new expression.
2443 /// Subclasses may override this routine to provide different behavior.
2444 ExprResult RebuildTypeTrait(TypeTrait Trait,
2445 SourceLocation StartLoc,
2446 ArrayRef<TypeSourceInfo *> Args,
2447 SourceLocation RParenLoc) {
2448 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2449 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002450
John Wiegley6242b6a2011-04-28 00:16:57 +00002451 /// \brief Build a new array type trait expression.
2452 ///
2453 /// By default, performs semantic analysis to build the new expression.
2454 /// Subclasses may override this routine to provide different behavior.
2455 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2456 SourceLocation StartLoc,
2457 TypeSourceInfo *TSInfo,
2458 Expr *DimExpr,
2459 SourceLocation RParenLoc) {
2460 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2461 }
2462
John Wiegleyf9f65842011-04-25 06:54:41 +00002463 /// \brief Build a new expression trait expression.
2464 ///
2465 /// By default, performs semantic analysis to build the new expression.
2466 /// Subclasses may override this routine to provide different behavior.
2467 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2468 SourceLocation StartLoc,
2469 Expr *Queried,
2470 SourceLocation RParenLoc) {
2471 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2472 }
2473
Mike Stump11289f42009-09-09 15:08:12 +00002474 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002475 /// expression.
2476 ///
2477 /// By default, performs semantic analysis to build the new expression.
2478 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002479 ExprResult RebuildDependentScopeDeclRefExpr(
2480 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002481 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002482 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002483 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002484 bool IsAddressOfOperand,
2485 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002486 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002487 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002488
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002489 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002490 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2491 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002492
Reid Kleckner32506ed2014-06-12 23:03:48 +00002493 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002494 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002495 }
2496
2497 /// \brief Build a new template-id expression.
2498 ///
2499 /// By default, performs semantic analysis to build the new expression.
2500 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002501 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002502 SourceLocation TemplateKWLoc,
2503 LookupResult &R,
2504 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002505 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002506 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2507 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002508 }
2509
2510 /// \brief Build a new object-construction expression.
2511 ///
2512 /// By default, performs semantic analysis to build the new expression.
2513 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002514 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002515 SourceLocation Loc,
2516 CXXConstructorDecl *Constructor,
2517 bool IsElidable,
2518 MultiExprArg Args,
2519 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002520 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002521 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002522 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002523 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002524 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002525 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002526 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002527 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002528 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002529
Douglas Gregordb121ba2009-12-14 16:27:04 +00002530 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002531 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002532 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002533 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002534 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002535 RequiresZeroInit, ConstructKind,
2536 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002537 }
2538
2539 /// \brief Build a new object-construction expression.
2540 ///
2541 /// By default, performs semantic analysis to build the new expression.
2542 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002543 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2544 SourceLocation LParenLoc,
2545 MultiExprArg Args,
2546 SourceLocation RParenLoc) {
2547 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002548 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002549 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002550 RParenLoc);
2551 }
2552
2553 /// \brief Build a new object-construction expression.
2554 ///
2555 /// By default, performs semantic analysis to build the new expression.
2556 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002557 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2558 SourceLocation LParenLoc,
2559 MultiExprArg Args,
2560 SourceLocation RParenLoc) {
2561 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002562 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002563 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002564 RParenLoc);
2565 }
Mike Stump11289f42009-09-09 15:08:12 +00002566
Douglas Gregora16548e2009-08-11 05:31:07 +00002567 /// \brief Build a new member reference expression.
2568 ///
2569 /// By default, performs semantic analysis to build the new expression.
2570 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002571 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002572 QualType BaseType,
2573 bool IsArrow,
2574 SourceLocation OperatorLoc,
2575 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002576 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002577 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002578 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002579 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002580 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002581 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002582
John McCallb268a282010-08-23 23:25:46 +00002583 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002584 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002585 SS, TemplateKWLoc,
2586 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002587 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002588 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002589 }
2590
John McCall10eae182009-11-30 22:42:35 +00002591 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002592 ///
2593 /// By default, performs semantic analysis to build the new expression.
2594 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002595 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2596 SourceLocation OperatorLoc,
2597 bool IsArrow,
2598 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002599 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002600 NamedDecl *FirstQualifierInScope,
2601 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002602 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002603 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002604 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002605
John McCallb268a282010-08-23 23:25:46 +00002606 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002607 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002608 SS, TemplateKWLoc,
2609 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002610 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002611 }
Mike Stump11289f42009-09-09 15:08:12 +00002612
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002613 /// \brief Build a new noexcept expression.
2614 ///
2615 /// By default, performs semantic analysis to build the new expression.
2616 /// Subclasses may override this routine to provide different behavior.
2617 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2618 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2619 }
2620
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002621 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002622 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2623 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002624 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002625 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002626 Optional<unsigned> Length,
2627 ArrayRef<TemplateArgument> PartialArgs) {
2628 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2629 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002630 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002631
Patrick Beard0caa3942012-04-19 00:25:12 +00002632 /// \brief Build a new Objective-C boxed expression.
2633 ///
2634 /// By default, performs semantic analysis to build the new expression.
2635 /// Subclasses may override this routine to provide different behavior.
2636 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2637 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2638 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002639
Ted Kremeneke65b0862012-03-06 20:05:56 +00002640 /// \brief Build a new Objective-C array literal.
2641 ///
2642 /// By default, performs semantic analysis to build the new expression.
2643 /// Subclasses may override this routine to provide different behavior.
2644 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2645 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002646 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002647 MultiExprArg(Elements, NumElements));
2648 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002649
2650 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002651 Expr *Base, Expr *Key,
2652 ObjCMethodDecl *getterMethod,
2653 ObjCMethodDecl *setterMethod) {
2654 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2655 getterMethod, setterMethod);
2656 }
2657
2658 /// \brief Build a new Objective-C dictionary literal.
2659 ///
2660 /// By default, performs semantic analysis to build the new expression.
2661 /// Subclasses may override this routine to provide different behavior.
2662 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2663 ObjCDictionaryElement *Elements,
2664 unsigned NumElements) {
2665 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2666 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002667
James Dennett2a4d13c2012-06-15 07:13:21 +00002668 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002669 ///
2670 /// By default, performs semantic analysis to build the new expression.
2671 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002672 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002673 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002674 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002675 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002676 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002677
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002678 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002679 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002680 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002681 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002682 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002683 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002684 MultiExprArg Args,
2685 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002686 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2687 ReceiverTypeInfo->getType(),
2688 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002689 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002690 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002691 }
2692
2693 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002694 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002695 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002696 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002697 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002698 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002699 MultiExprArg Args,
2700 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002701 return SemaRef.BuildInstanceMessage(Receiver,
2702 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002703 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002704 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002705 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002706 }
2707
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002708 /// \brief Build a new Objective-C instance/class message to 'super'.
2709 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2710 Selector Sel,
2711 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002712 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002713 ObjCMethodDecl *Method,
2714 SourceLocation LBracLoc,
2715 MultiExprArg Args,
2716 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002717 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002718 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002719 SuperLoc,
2720 Sel, Method, LBracLoc, SelectorLocs,
2721 RBracLoc, Args)
2722 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002723 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002724 SuperLoc,
2725 Sel, Method, LBracLoc, SelectorLocs,
2726 RBracLoc, Args);
2727
2728
2729 }
2730
Douglas Gregord51d90d2010-04-26 20:11:03 +00002731 /// \brief Build a new Objective-C ivar reference expression.
2732 ///
2733 /// By default, performs semantic analysis to build the new expression.
2734 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002735 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002736 SourceLocation IvarLoc,
2737 bool IsArrow, bool IsFreeIvar) {
2738 // FIXME: We lose track of the IsFreeIvar bit.
2739 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002740 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2741 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002742 /*FIXME:*/IvarLoc, IsArrow,
2743 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002744 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002745 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002746 /*TemplateArgs=*/nullptr,
2747 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002748 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002749
2750 /// \brief Build a new Objective-C property reference expression.
2751 ///
2752 /// By default, performs semantic analysis to build the new expression.
2753 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002754 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002755 ObjCPropertyDecl *Property,
2756 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002757 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002758 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2759 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2760 /*FIXME:*/PropertyLoc,
2761 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002762 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002763 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002764 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002765 /*TemplateArgs=*/nullptr,
2766 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002767 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002768
John McCallb7bd14f2010-12-02 01:19:52 +00002769 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002770 ///
2771 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002772 /// Subclasses may override this routine to provide different behavior.
2773 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2774 ObjCMethodDecl *Getter,
2775 ObjCMethodDecl *Setter,
2776 SourceLocation PropertyLoc) {
2777 // Since these expressions can only be value-dependent, we do not
2778 // need to perform semantic analysis again.
2779 return Owned(
2780 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2781 VK_LValue, OK_ObjCProperty,
2782 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002783 }
2784
Douglas Gregord51d90d2010-04-26 20:11:03 +00002785 /// \brief Build a new Objective-C "isa" expression.
2786 ///
2787 /// By default, performs semantic analysis to build the new expression.
2788 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002789 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002790 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002791 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002792 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2793 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002794 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002795 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002796 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002797 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002798 /*TemplateArgs=*/nullptr,
2799 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002800 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002801
Douglas Gregora16548e2009-08-11 05:31:07 +00002802 /// \brief Build a new shuffle vector expression.
2803 ///
2804 /// By default, performs semantic analysis to build the new expression.
2805 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002806 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002807 MultiExprArg SubExprs,
2808 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002809 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002810 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002811 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2812 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2813 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002814 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002815
Douglas Gregora16548e2009-08-11 05:31:07 +00002816 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002817 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002818 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2819 SemaRef.Context.BuiltinFnTy,
2820 VK_RValue, BuiltinLoc);
2821 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2822 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002823 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002824
2825 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002826 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002827 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002828 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002829
Douglas Gregora16548e2009-08-11 05:31:07 +00002830 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002831 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002832 }
John McCall31f82722010-11-12 08:19:04 +00002833
Hal Finkelc4d7c822013-09-18 03:29:45 +00002834 /// \brief Build a new convert vector expression.
2835 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2836 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2837 SourceLocation RParenLoc) {
2838 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2839 BuiltinLoc, RParenLoc);
2840 }
2841
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002842 /// \brief Build a new template argument pack expansion.
2843 ///
2844 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002845 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002846 /// different behavior.
2847 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002848 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002849 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002850 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002851 case TemplateArgument::Expression: {
2852 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002853 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2854 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002855 if (Result.isInvalid())
2856 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002857
Douglas Gregor98318c22011-01-03 21:37:45 +00002858 return TemplateArgumentLoc(Result.get(), Result.get());
2859 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002860
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002861 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002862 return TemplateArgumentLoc(TemplateArgument(
2863 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002864 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002865 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002866 Pattern.getTemplateNameLoc(),
2867 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002868
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002869 case TemplateArgument::Null:
2870 case TemplateArgument::Integral:
2871 case TemplateArgument::Declaration:
2872 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002873 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002874 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002875 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002876
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002877 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002878 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002879 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002880 EllipsisLoc,
2881 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002882 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2883 Expansion);
2884 break;
2885 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002886
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002887 return TemplateArgumentLoc();
2888 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002889
Douglas Gregor968f23a2011-01-03 19:31:53 +00002890 /// \brief Build a new expression pack expansion.
2891 ///
2892 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002893 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002894 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002895 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002896 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002897 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002898 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002899
Richard Smith0f0af192014-11-08 05:07:16 +00002900 /// \brief Build a new C++1z fold-expression.
2901 ///
2902 /// By default, performs semantic analysis in order to build a new fold
2903 /// expression.
2904 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
2905 BinaryOperatorKind Operator,
2906 SourceLocation EllipsisLoc, Expr *RHS,
2907 SourceLocation RParenLoc) {
2908 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
2909 RHS, RParenLoc);
2910 }
2911
2912 /// \brief Build an empty C++1z fold-expression with the given operator.
2913 ///
2914 /// By default, produces the fallback value for the fold-expression, or
2915 /// produce an error if there is no fallback value.
2916 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
2917 BinaryOperatorKind Operator) {
2918 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
2919 }
2920
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002921 /// \brief Build a new atomic operation expression.
2922 ///
2923 /// By default, performs semantic analysis to build the new expression.
2924 /// Subclasses may override this routine to provide different behavior.
2925 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2926 MultiExprArg SubExprs,
2927 QualType RetTy,
2928 AtomicExpr::AtomicOp Op,
2929 SourceLocation RParenLoc) {
2930 // Just create the expression; there is not any interesting semantic
2931 // analysis here because we can't actually build an AtomicExpr until
2932 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002933 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002934 RParenLoc);
2935 }
2936
John McCall31f82722010-11-12 08:19:04 +00002937private:
Douglas Gregor14454802011-02-25 02:25:35 +00002938 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2939 QualType ObjectType,
2940 NamedDecl *FirstQualifierInScope,
2941 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002942
2943 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2944 QualType ObjectType,
2945 NamedDecl *FirstQualifierInScope,
2946 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002947
2948 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2949 NamedDecl *FirstQualifierInScope,
2950 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002951};
Douglas Gregora16548e2009-08-11 05:31:07 +00002952
Douglas Gregorebe10102009-08-20 07:17:43 +00002953template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002954StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002955 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002956 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002957
Douglas Gregorebe10102009-08-20 07:17:43 +00002958 switch (S->getStmtClass()) {
2959 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002960
Douglas Gregorebe10102009-08-20 07:17:43 +00002961 // Transform individual statement nodes
2962#define STMT(Node, Parent) \
2963 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002964#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002965#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002966#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002967
Douglas Gregorebe10102009-08-20 07:17:43 +00002968 // Transform expressions by calling TransformExpr.
2969#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002970#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002971#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002972#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002973 {
John McCalldadc5752010-08-24 06:29:42 +00002974 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002975 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002976 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002977
Richard Smith945f8d32013-01-14 22:39:08 +00002978 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002979 }
Mike Stump11289f42009-09-09 15:08:12 +00002980 }
2981
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002982 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002983}
Mike Stump11289f42009-09-09 15:08:12 +00002984
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002985template<typename Derived>
2986OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2987 if (!S)
2988 return S;
2989
2990 switch (S->getClauseKind()) {
2991 default: break;
2992 // Transform individual clause nodes
2993#define OPENMP_CLAUSE(Name, Class) \
2994 case OMPC_ ## Name : \
2995 return getDerived().Transform ## Class(cast<Class>(S));
2996#include "clang/Basic/OpenMPKinds.def"
2997 }
2998
2999 return S;
3000}
3001
Mike Stump11289f42009-09-09 15:08:12 +00003002
Douglas Gregore922c772009-08-04 22:27:00 +00003003template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003004ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003005 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003006 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003007
3008 switch (E->getStmtClass()) {
3009 case Stmt::NoStmtClass: break;
3010#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003011#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003012#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003013 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003014#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003015 }
3016
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003017 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003018}
3019
3020template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003021ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003022 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003023 // Initializers are instantiated like expressions, except that various outer
3024 // layers are stripped.
3025 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003026 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003027
3028 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3029 Init = ExprTemp->getSubExpr();
3030
Richard Smithe6ca4752013-05-30 22:40:16 +00003031 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3032 Init = MTE->GetTemporaryExpr();
3033
Richard Smithd59b8322012-12-19 01:39:02 +00003034 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3035 Init = Binder->getSubExpr();
3036
3037 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3038 Init = ICE->getSubExprAsWritten();
3039
Richard Smithcc1b96d2013-06-12 22:31:48 +00003040 if (CXXStdInitializerListExpr *ILE =
3041 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003042 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003043
Richard Smithc6abd962014-07-25 01:12:44 +00003044 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003045 // InitListExprs. Other forms of copy-initialization will be a no-op if
3046 // the initializer is already the right type.
3047 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003048 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003049 return getDerived().TransformExpr(Init);
3050
3051 // Revert value-initialization back to empty parens.
3052 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3053 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003054 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003055 Parens.getEnd());
3056 }
3057
3058 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3059 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003060 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003061 SourceLocation());
3062
3063 // Revert initialization by constructor back to a parenthesized or braced list
3064 // of expressions. Any other form of initializer can just be reused directly.
3065 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003066 return getDerived().TransformExpr(Init);
3067
Richard Smithf8adcdc2014-07-17 05:12:35 +00003068 // If the initialization implicitly converted an initializer list to a
3069 // std::initializer_list object, unwrap the std::initializer_list too.
3070 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003071 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003072
Richard Smithd59b8322012-12-19 01:39:02 +00003073 SmallVector<Expr*, 8> NewArgs;
3074 bool ArgChanged = false;
3075 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003076 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003077 return ExprError();
3078
3079 // If this was list initialization, revert to list form.
3080 if (Construct->isListInitialization())
3081 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3082 Construct->getLocEnd(),
3083 Construct->getType());
3084
Richard Smithd59b8322012-12-19 01:39:02 +00003085 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003086 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003087 if (Parens.isInvalid()) {
3088 // This was a variable declaration's initialization for which no initializer
3089 // was specified.
3090 assert(NewArgs.empty() &&
3091 "no parens or braces but have direct init with arguments?");
3092 return ExprEmpty();
3093 }
Richard Smithd59b8322012-12-19 01:39:02 +00003094 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3095 Parens.getEnd());
3096}
3097
3098template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00003099bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
3100 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003101 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003102 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003103 bool *ArgChanged) {
3104 for (unsigned I = 0; I != NumInputs; ++I) {
3105 // If requested, drop call arguments that need to be dropped.
3106 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3107 if (ArgChanged)
3108 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003109
Douglas Gregora3efea12011-01-03 19:04:46 +00003110 break;
3111 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003112
Douglas Gregor968f23a2011-01-03 19:31:53 +00003113 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3114 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003115
Chris Lattner01cf8db2011-07-20 06:58:45 +00003116 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003117 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3118 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003119
Douglas Gregor968f23a2011-01-03 19:31:53 +00003120 // Determine whether the set of unexpanded parameter packs can and should
3121 // be expanded.
3122 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003123 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003124 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3125 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003126 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3127 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003128 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003129 Expand, RetainExpansion,
3130 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003131 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003132
Douglas Gregor968f23a2011-01-03 19:31:53 +00003133 if (!Expand) {
3134 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003135 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003136 // expansion.
3137 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3138 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3139 if (OutPattern.isInvalid())
3140 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003141
3142 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003143 Expansion->getEllipsisLoc(),
3144 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003145 if (Out.isInvalid())
3146 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003147
Douglas Gregor968f23a2011-01-03 19:31:53 +00003148 if (ArgChanged)
3149 *ArgChanged = true;
3150 Outputs.push_back(Out.get());
3151 continue;
3152 }
John McCall542e7c62011-07-06 07:30:07 +00003153
3154 // Record right away that the argument was changed. This needs
3155 // to happen even if the array expands to nothing.
3156 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003157
Douglas Gregor968f23a2011-01-03 19:31:53 +00003158 // The transform has determined that we should perform an elementwise
3159 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003160 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003161 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3162 ExprResult Out = getDerived().TransformExpr(Pattern);
3163 if (Out.isInvalid())
3164 return true;
3165
Richard Smith9467be42014-06-06 17:33:35 +00003166 // FIXME: Can this happen? We should not try to expand the pack
3167 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003168 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003169 Out = getDerived().RebuildPackExpansion(
3170 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003171 if (Out.isInvalid())
3172 return true;
3173 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003174
Douglas Gregor968f23a2011-01-03 19:31:53 +00003175 Outputs.push_back(Out.get());
3176 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003177
Richard Smith9467be42014-06-06 17:33:35 +00003178 // If we're supposed to retain a pack expansion, do so by temporarily
3179 // forgetting the partially-substituted parameter pack.
3180 if (RetainExpansion) {
3181 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3182
3183 ExprResult Out = getDerived().TransformExpr(Pattern);
3184 if (Out.isInvalid())
3185 return true;
3186
3187 Out = getDerived().RebuildPackExpansion(
3188 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3189 if (Out.isInvalid())
3190 return true;
3191
3192 Outputs.push_back(Out.get());
3193 }
3194
Douglas Gregor968f23a2011-01-03 19:31:53 +00003195 continue;
3196 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003197
Richard Smithd59b8322012-12-19 01:39:02 +00003198 ExprResult Result =
3199 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3200 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003201 if (Result.isInvalid())
3202 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003203
Douglas Gregora3efea12011-01-03 19:04:46 +00003204 if (Result.get() != Inputs[I] && ArgChanged)
3205 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003206
3207 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003208 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003209
Douglas Gregora3efea12011-01-03 19:04:46 +00003210 return false;
3211}
3212
3213template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003214NestedNameSpecifierLoc
3215TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3216 NestedNameSpecifierLoc NNS,
3217 QualType ObjectType,
3218 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003219 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003220 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003221 Qualifier = Qualifier.getPrefix())
3222 Qualifiers.push_back(Qualifier);
3223
3224 CXXScopeSpec SS;
3225 while (!Qualifiers.empty()) {
3226 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3227 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003228
Douglas Gregor14454802011-02-25 02:25:35 +00003229 switch (QNNS->getKind()) {
3230 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003231 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003232 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003233 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003234 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003235 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003236 FirstQualifierInScope, false))
3237 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003238
Douglas Gregor14454802011-02-25 02:25:35 +00003239 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003240
Douglas Gregor14454802011-02-25 02:25:35 +00003241 case NestedNameSpecifier::Namespace: {
3242 NamespaceDecl *NS
3243 = cast_or_null<NamespaceDecl>(
3244 getDerived().TransformDecl(
3245 Q.getLocalBeginLoc(),
3246 QNNS->getAsNamespace()));
3247 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3248 break;
3249 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003250
Douglas Gregor14454802011-02-25 02:25:35 +00003251 case NestedNameSpecifier::NamespaceAlias: {
3252 NamespaceAliasDecl *Alias
3253 = cast_or_null<NamespaceAliasDecl>(
3254 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3255 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003256 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003257 Q.getLocalEndLoc());
3258 break;
3259 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003260
Douglas Gregor14454802011-02-25 02:25:35 +00003261 case NestedNameSpecifier::Global:
3262 // There is no meaningful transformation that one could perform on the
3263 // global scope.
3264 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3265 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003266
Nikola Smiljanic67860242014-09-26 00:28:20 +00003267 case NestedNameSpecifier::Super: {
3268 CXXRecordDecl *RD =
3269 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3270 SourceLocation(), QNNS->getAsRecordDecl()));
3271 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3272 break;
3273 }
3274
Douglas Gregor14454802011-02-25 02:25:35 +00003275 case NestedNameSpecifier::TypeSpecWithTemplate:
3276 case NestedNameSpecifier::TypeSpec: {
3277 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3278 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003279
Douglas Gregor14454802011-02-25 02:25:35 +00003280 if (!TL)
3281 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003282
Douglas Gregor14454802011-02-25 02:25:35 +00003283 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003284 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003285 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003286 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003287 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003288 if (TL.getType()->isEnumeralType())
3289 SemaRef.Diag(TL.getBeginLoc(),
3290 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003291 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3292 Q.getLocalEndLoc());
3293 break;
3294 }
Richard Trieude756fb2011-05-07 01:36:37 +00003295 // If the nested-name-specifier is an invalid type def, don't emit an
3296 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003297 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3298 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003299 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003300 << TL.getType() << SS.getRange();
3301 }
Douglas Gregor14454802011-02-25 02:25:35 +00003302 return NestedNameSpecifierLoc();
3303 }
Douglas Gregore16af532011-02-28 18:50:33 +00003304 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003305
Douglas Gregore16af532011-02-28 18:50:33 +00003306 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003307 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003308 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003309 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003310
Douglas Gregor14454802011-02-25 02:25:35 +00003311 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003312 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003313 !getDerived().AlwaysRebuild())
3314 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003315
3316 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003317 // nested-name-specifier, do so.
3318 if (SS.location_size() == NNS.getDataLength() &&
3319 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3320 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3321
3322 // Allocate new nested-name-specifier location information.
3323 return SS.getWithLocInContext(SemaRef.Context);
3324}
3325
3326template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003327DeclarationNameInfo
3328TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003329::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003330 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003331 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003332 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003333
3334 switch (Name.getNameKind()) {
3335 case DeclarationName::Identifier:
3336 case DeclarationName::ObjCZeroArgSelector:
3337 case DeclarationName::ObjCOneArgSelector:
3338 case DeclarationName::ObjCMultiArgSelector:
3339 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003340 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003341 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003342 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003343
Douglas Gregorf816bd72009-09-03 22:13:48 +00003344 case DeclarationName::CXXConstructorName:
3345 case DeclarationName::CXXDestructorName:
3346 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003347 TypeSourceInfo *NewTInfo;
3348 CanQualType NewCanTy;
3349 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003350 NewTInfo = getDerived().TransformType(OldTInfo);
3351 if (!NewTInfo)
3352 return DeclarationNameInfo();
3353 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003354 }
3355 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003356 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003357 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003358 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003359 if (NewT.isNull())
3360 return DeclarationNameInfo();
3361 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3362 }
Mike Stump11289f42009-09-09 15:08:12 +00003363
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003364 DeclarationName NewName
3365 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3366 NewCanTy);
3367 DeclarationNameInfo NewNameInfo(NameInfo);
3368 NewNameInfo.setName(NewName);
3369 NewNameInfo.setNamedTypeInfo(NewTInfo);
3370 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003371 }
Mike Stump11289f42009-09-09 15:08:12 +00003372 }
3373
David Blaikie83d382b2011-09-23 05:06:16 +00003374 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003375}
3376
3377template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003378TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003379TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3380 TemplateName Name,
3381 SourceLocation NameLoc,
3382 QualType ObjectType,
3383 NamedDecl *FirstQualifierInScope) {
3384 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3385 TemplateDecl *Template = QTN->getTemplateDecl();
3386 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003387
Douglas Gregor9db53502011-03-02 18:07:45 +00003388 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003389 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003390 Template));
3391 if (!TransTemplate)
3392 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003393
Douglas Gregor9db53502011-03-02 18:07:45 +00003394 if (!getDerived().AlwaysRebuild() &&
3395 SS.getScopeRep() == QTN->getQualifier() &&
3396 TransTemplate == Template)
3397 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003398
Douglas Gregor9db53502011-03-02 18:07:45 +00003399 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3400 TransTemplate);
3401 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003402
Douglas Gregor9db53502011-03-02 18:07:45 +00003403 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3404 if (SS.getScopeRep()) {
3405 // These apply to the scope specifier, not the template.
3406 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003407 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003408 }
3409
Douglas Gregor9db53502011-03-02 18:07:45 +00003410 if (!getDerived().AlwaysRebuild() &&
3411 SS.getScopeRep() == DTN->getQualifier() &&
3412 ObjectType.isNull())
3413 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003414
Douglas Gregor9db53502011-03-02 18:07:45 +00003415 if (DTN->isIdentifier()) {
3416 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003417 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003418 NameLoc,
3419 ObjectType,
3420 FirstQualifierInScope);
3421 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003422
Douglas Gregor9db53502011-03-02 18:07:45 +00003423 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3424 ObjectType);
3425 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003426
Douglas Gregor9db53502011-03-02 18:07:45 +00003427 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3428 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003429 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003430 Template));
3431 if (!TransTemplate)
3432 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003433
Douglas Gregor9db53502011-03-02 18:07:45 +00003434 if (!getDerived().AlwaysRebuild() &&
3435 TransTemplate == Template)
3436 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003437
Douglas Gregor9db53502011-03-02 18:07:45 +00003438 return TemplateName(TransTemplate);
3439 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003440
Douglas Gregor9db53502011-03-02 18:07:45 +00003441 if (SubstTemplateTemplateParmPackStorage *SubstPack
3442 = Name.getAsSubstTemplateTemplateParmPack()) {
3443 TemplateTemplateParmDecl *TransParam
3444 = cast_or_null<TemplateTemplateParmDecl>(
3445 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3446 if (!TransParam)
3447 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003448
Douglas Gregor9db53502011-03-02 18:07:45 +00003449 if (!getDerived().AlwaysRebuild() &&
3450 TransParam == SubstPack->getParameterPack())
3451 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003452
3453 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003454 SubstPack->getArgumentPack());
3455 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003456
Douglas Gregor9db53502011-03-02 18:07:45 +00003457 // These should be getting filtered out before they reach the AST.
3458 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003459}
3460
3461template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003462void TreeTransform<Derived>::InventTemplateArgumentLoc(
3463 const TemplateArgument &Arg,
3464 TemplateArgumentLoc &Output) {
3465 SourceLocation Loc = getDerived().getBaseLocation();
3466 switch (Arg.getKind()) {
3467 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003468 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003469 break;
3470
3471 case TemplateArgument::Type:
3472 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003473 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003474
John McCall0ad16662009-10-29 08:12:44 +00003475 break;
3476
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003477 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003478 case TemplateArgument::TemplateExpansion: {
3479 NestedNameSpecifierLocBuilder Builder;
3480 TemplateName Template = Arg.getAsTemplate();
3481 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3482 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3483 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3484 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003485
Douglas Gregor9d802122011-03-02 17:09:35 +00003486 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003487 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003488 Builder.getWithLocInContext(SemaRef.Context),
3489 Loc);
3490 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003491 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003492 Builder.getWithLocInContext(SemaRef.Context),
3493 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003494
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003495 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003496 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003497
John McCall0ad16662009-10-29 08:12:44 +00003498 case TemplateArgument::Expression:
3499 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3500 break;
3501
3502 case TemplateArgument::Declaration:
3503 case TemplateArgument::Integral:
3504 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003505 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003506 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003507 break;
3508 }
3509}
3510
3511template<typename Derived>
3512bool TreeTransform<Derived>::TransformTemplateArgument(
3513 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003514 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003515 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003516 switch (Arg.getKind()) {
3517 case TemplateArgument::Null:
3518 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003519 case TemplateArgument::Pack:
3520 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003521 case TemplateArgument::NullPtr:
3522 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003523
Douglas Gregore922c772009-08-04 22:27:00 +00003524 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003525 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003526 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003527 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003528
3529 DI = getDerived().TransformType(DI);
3530 if (!DI) return true;
3531
3532 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3533 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003534 }
Mike Stump11289f42009-09-09 15:08:12 +00003535
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003536 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003537 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3538 if (QualifierLoc) {
3539 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3540 if (!QualifierLoc)
3541 return true;
3542 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003543
Douglas Gregordf846d12011-03-02 18:46:51 +00003544 CXXScopeSpec SS;
3545 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003546 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003547 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3548 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003549 if (Template.isNull())
3550 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003551
Douglas Gregor9d802122011-03-02 17:09:35 +00003552 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003553 Input.getTemplateNameLoc());
3554 return false;
3555 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003556
3557 case TemplateArgument::TemplateExpansion:
3558 llvm_unreachable("Caller should expand pack expansions");
3559
Douglas Gregore922c772009-08-04 22:27:00 +00003560 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003561 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003562 EnterExpressionEvaluationContext Unevaluated(
3563 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003564
John McCall0ad16662009-10-29 08:12:44 +00003565 Expr *InputExpr = Input.getSourceExpression();
3566 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3567
Chris Lattnercdb591a2011-04-25 20:37:58 +00003568 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003569 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003570 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003571 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003572 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003573 }
Douglas Gregore922c772009-08-04 22:27:00 +00003574 }
Mike Stump11289f42009-09-09 15:08:12 +00003575
Douglas Gregore922c772009-08-04 22:27:00 +00003576 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003577 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003578}
3579
Douglas Gregorfe921a72010-12-20 23:36:19 +00003580/// \brief Iterator adaptor that invents template argument location information
3581/// for each of the template arguments in its underlying iterator.
3582template<typename Derived, typename InputIterator>
3583class TemplateArgumentLocInventIterator {
3584 TreeTransform<Derived> &Self;
3585 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003586
Douglas Gregorfe921a72010-12-20 23:36:19 +00003587public:
3588 typedef TemplateArgumentLoc value_type;
3589 typedef TemplateArgumentLoc reference;
3590 typedef typename std::iterator_traits<InputIterator>::difference_type
3591 difference_type;
3592 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003593
Douglas Gregorfe921a72010-12-20 23:36:19 +00003594 class pointer {
3595 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003596
Douglas Gregorfe921a72010-12-20 23:36:19 +00003597 public:
3598 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003599
Douglas Gregorfe921a72010-12-20 23:36:19 +00003600 const TemplateArgumentLoc *operator->() const { return &Arg; }
3601 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003602
Douglas Gregorfe921a72010-12-20 23:36:19 +00003603 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003604
Douglas Gregorfe921a72010-12-20 23:36:19 +00003605 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3606 InputIterator Iter)
3607 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003608
Douglas Gregorfe921a72010-12-20 23:36:19 +00003609 TemplateArgumentLocInventIterator &operator++() {
3610 ++Iter;
3611 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003612 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003613
Douglas Gregorfe921a72010-12-20 23:36:19 +00003614 TemplateArgumentLocInventIterator operator++(int) {
3615 TemplateArgumentLocInventIterator Old(*this);
3616 ++(*this);
3617 return Old;
3618 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003619
Douglas Gregorfe921a72010-12-20 23:36:19 +00003620 reference operator*() const {
3621 TemplateArgumentLoc Result;
3622 Self.InventTemplateArgumentLoc(*Iter, Result);
3623 return Result;
3624 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003625
Douglas Gregorfe921a72010-12-20 23:36:19 +00003626 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003627
Douglas Gregorfe921a72010-12-20 23:36:19 +00003628 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3629 const TemplateArgumentLocInventIterator &Y) {
3630 return X.Iter == Y.Iter;
3631 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003632
Douglas Gregorfe921a72010-12-20 23:36:19 +00003633 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3634 const TemplateArgumentLocInventIterator &Y) {
3635 return X.Iter != Y.Iter;
3636 }
3637};
Chad Rosier1dcde962012-08-08 18:46:20 +00003638
Douglas Gregor42cafa82010-12-20 17:42:22 +00003639template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003640template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003641bool TreeTransform<Derived>::TransformTemplateArguments(
3642 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3643 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003644 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003645 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003646 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003647
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003648 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3649 // Unpack argument packs, which we translate them into separate
3650 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003651 // FIXME: We could do much better if we could guarantee that the
3652 // TemplateArgumentLocInfo for the pack expansion would be usable for
3653 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003654 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003655 TemplateArgument::pack_iterator>
3656 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003657 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003658 In.getArgument().pack_begin()),
3659 PackLocIterator(*this,
3660 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003661 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003662 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003663
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003664 continue;
3665 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003666
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003667 if (In.getArgument().isPackExpansion()) {
3668 // We have a pack expansion, for which we will be substituting into
3669 // the pattern.
3670 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003671 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003672 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003673 = getSema().getTemplateArgumentPackExpansionPattern(
3674 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003675
Chris Lattner01cf8db2011-07-20 06:58:45 +00003676 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003677 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3678 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003679
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003680 // Determine whether the set of unexpanded parameter packs can and should
3681 // be expanded.
3682 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003683 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003684 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003685 if (getDerived().TryExpandParameterPacks(Ellipsis,
3686 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003687 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003688 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003689 RetainExpansion,
3690 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003691 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003692
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003693 if (!Expand) {
3694 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003695 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003696 // expansion.
3697 TemplateArgumentLoc OutPattern;
3698 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003699 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003700 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003701
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003702 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3703 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003704 if (Out.getArgument().isNull())
3705 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003706
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003707 Outputs.addArgument(Out);
3708 continue;
3709 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003710
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003711 // The transform has determined that we should perform an elementwise
3712 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003713 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003714 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3715
Richard Smithd784e682015-09-23 21:41:42 +00003716 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003717 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003718
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003719 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003720 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3721 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003722 if (Out.getArgument().isNull())
3723 return true;
3724 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003725
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003726 Outputs.addArgument(Out);
3727 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003728
Douglas Gregor48d24112011-01-10 20:53:55 +00003729 // If we're supposed to retain a pack expansion, do so by temporarily
3730 // forgetting the partially-substituted parameter pack.
3731 if (RetainExpansion) {
3732 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003733
Richard Smithd784e682015-09-23 21:41:42 +00003734 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00003735 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003736
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003737 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3738 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003739 if (Out.getArgument().isNull())
3740 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003741
Douglas Gregor48d24112011-01-10 20:53:55 +00003742 Outputs.addArgument(Out);
3743 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003744
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003745 continue;
3746 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003747
3748 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00003749 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003750 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003751
Douglas Gregor42cafa82010-12-20 17:42:22 +00003752 Outputs.addArgument(Out);
3753 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003754
Douglas Gregor42cafa82010-12-20 17:42:22 +00003755 return false;
3756
3757}
3758
Douglas Gregord6ff3322009-08-04 16:50:30 +00003759//===----------------------------------------------------------------------===//
3760// Type transformation
3761//===----------------------------------------------------------------------===//
3762
3763template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003764QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003765 if (getDerived().AlreadyTransformed(T))
3766 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003767
John McCall550e0c22009-10-21 00:40:46 +00003768 // Temporary workaround. All of these transformations should
3769 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003770 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3771 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003772
John McCall31f82722010-11-12 08:19:04 +00003773 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003774
John McCall550e0c22009-10-21 00:40:46 +00003775 if (!NewDI)
3776 return QualType();
3777
3778 return NewDI->getType();
3779}
3780
3781template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003782TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003783 // Refine the base location to the type's location.
3784 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3785 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003786 if (getDerived().AlreadyTransformed(DI->getType()))
3787 return DI;
3788
3789 TypeLocBuilder TLB;
3790
3791 TypeLoc TL = DI->getTypeLoc();
3792 TLB.reserve(TL.getFullDataSize());
3793
John McCall31f82722010-11-12 08:19:04 +00003794 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003795 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003796 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003797
John McCallbcd03502009-12-07 02:54:59 +00003798 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003799}
3800
3801template<typename Derived>
3802QualType
John McCall31f82722010-11-12 08:19:04 +00003803TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003804 switch (T.getTypeLocClass()) {
3805#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003806#define TYPELOC(CLASS, PARENT) \
3807 case TypeLoc::CLASS: \
3808 return getDerived().Transform##CLASS##Type(TLB, \
3809 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003810#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003811 }
Mike Stump11289f42009-09-09 15:08:12 +00003812
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003813 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003814}
3815
3816/// FIXME: By default, this routine adds type qualifiers only to types
3817/// that can have qualifiers, and silently suppresses those qualifiers
3818/// that are not permitted (e.g., qualifiers on reference or function
3819/// types). This is the right thing for template instantiation, but
3820/// probably not for other clients.
3821template<typename Derived>
3822QualType
3823TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003824 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003825 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003826
John McCall31f82722010-11-12 08:19:04 +00003827 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003828 if (Result.isNull())
3829 return QualType();
3830
3831 // Silently suppress qualifiers if the result type can't be qualified.
3832 // FIXME: this is the right thing for template instantiation, but
3833 // probably not for other clients.
3834 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003835 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003836
John McCall31168b02011-06-15 23:02:42 +00003837 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003838 // resulting type.
3839 if (Quals.hasObjCLifetime()) {
3840 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3841 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003842 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003843 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003844 // A lifetime qualifier applied to a substituted template parameter
3845 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003846 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003847 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003848 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3849 QualType Replacement = SubstTypeParam->getReplacementType();
3850 Qualifiers Qs = Replacement.getQualifiers();
3851 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003852 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003853 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3854 Qs);
3855 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003856 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003857 Replacement);
3858 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003859 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3860 // 'auto' types behave the same way as template parameters.
3861 QualType Deduced = AutoTy->getDeducedType();
3862 Qualifiers Qs = Deduced.getQualifiers();
3863 Qs.removeObjCLifetime();
3864 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3865 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003866 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3867 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003868 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003869 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003870 // Otherwise, complain about the addition of a qualifier to an
3871 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003872 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003873 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003874 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003875
Douglas Gregore46db902011-06-17 22:11:49 +00003876 Quals.removeObjCLifetime();
3877 }
3878 }
3879 }
John McCallcb0f89a2010-06-05 06:41:15 +00003880 if (!Quals.empty()) {
3881 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003882 // BuildQualifiedType might not add qualifiers if they are invalid.
3883 if (Result.hasLocalQualifiers())
3884 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003885 // No location information to preserve.
3886 }
John McCall550e0c22009-10-21 00:40:46 +00003887
3888 return Result;
3889}
3890
Douglas Gregor14454802011-02-25 02:25:35 +00003891template<typename Derived>
3892TypeLoc
3893TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3894 QualType ObjectType,
3895 NamedDecl *UnqualLookup,
3896 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003897 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003898 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003899
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003900 TypeSourceInfo *TSI =
3901 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3902 if (TSI)
3903 return TSI->getTypeLoc();
3904 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003905}
3906
Douglas Gregor579c15f2011-03-02 18:32:08 +00003907template<typename Derived>
3908TypeSourceInfo *
3909TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3910 QualType ObjectType,
3911 NamedDecl *UnqualLookup,
3912 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003913 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003914 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003915
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003916 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3917 UnqualLookup, SS);
3918}
3919
3920template <typename Derived>
3921TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3922 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3923 CXXScopeSpec &SS) {
3924 QualType T = TL.getType();
3925 assert(!getDerived().AlreadyTransformed(T));
3926
Douglas Gregor579c15f2011-03-02 18:32:08 +00003927 TypeLocBuilder TLB;
3928 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003929
Douglas Gregor579c15f2011-03-02 18:32:08 +00003930 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003931 TemplateSpecializationTypeLoc SpecTL =
3932 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003933
Douglas Gregor579c15f2011-03-02 18:32:08 +00003934 TemplateName Template
3935 = getDerived().TransformTemplateName(SS,
3936 SpecTL.getTypePtr()->getTemplateName(),
3937 SpecTL.getTemplateNameLoc(),
3938 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003939 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003940 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003941
3942 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003943 Template);
3944 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003945 DependentTemplateSpecializationTypeLoc SpecTL =
3946 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003947
Douglas Gregor579c15f2011-03-02 18:32:08 +00003948 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003949 = getDerived().RebuildTemplateName(SS,
3950 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003951 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003952 ObjectType, UnqualLookup);
3953 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003954 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003955
3956 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003957 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003958 Template,
3959 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003960 } else {
3961 // Nothing special needs to be done for these.
3962 Result = getDerived().TransformType(TLB, TL);
3963 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003964
3965 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003966 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003967
Douglas Gregor579c15f2011-03-02 18:32:08 +00003968 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3969}
3970
John McCall550e0c22009-10-21 00:40:46 +00003971template <class TyLoc> static inline
3972QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3973 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3974 NewT.setNameLoc(T.getNameLoc());
3975 return T.getType();
3976}
3977
John McCall550e0c22009-10-21 00:40:46 +00003978template<typename Derived>
3979QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003980 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003981 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3982 NewT.setBuiltinLoc(T.getBuiltinLoc());
3983 if (T.needsExtraLocalData())
3984 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3985 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003986}
Mike Stump11289f42009-09-09 15:08:12 +00003987
Douglas Gregord6ff3322009-08-04 16:50:30 +00003988template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003989QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003990 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003991 // FIXME: recurse?
3992 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003993}
Mike Stump11289f42009-09-09 15:08:12 +00003994
Reid Kleckner0503a872013-12-05 01:23:43 +00003995template <typename Derived>
3996QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3997 AdjustedTypeLoc TL) {
3998 // Adjustments applied during transformation are handled elsewhere.
3999 return getDerived().TransformType(TLB, TL.getOriginalLoc());
4000}
4001
Douglas Gregord6ff3322009-08-04 16:50:30 +00004002template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004003QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4004 DecayedTypeLoc TL) {
4005 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4006 if (OriginalType.isNull())
4007 return QualType();
4008
4009 QualType Result = TL.getType();
4010 if (getDerived().AlwaysRebuild() ||
4011 OriginalType != TL.getOriginalLoc().getType())
4012 Result = SemaRef.Context.getDecayedType(OriginalType);
4013 TLB.push<DecayedTypeLoc>(Result);
4014 // Nothing to set for DecayedTypeLoc.
4015 return Result;
4016}
4017
4018template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004019QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004020 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004021 QualType PointeeType
4022 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004023 if (PointeeType.isNull())
4024 return QualType();
4025
4026 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004027 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004028 // A dependent pointer type 'T *' has is being transformed such
4029 // that an Objective-C class type is being replaced for 'T'. The
4030 // resulting pointer type is an ObjCObjectPointerType, not a
4031 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004032 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004033
John McCall8b07ec22010-05-15 11:32:37 +00004034 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4035 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004036 return Result;
4037 }
John McCall31f82722010-11-12 08:19:04 +00004038
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004039 if (getDerived().AlwaysRebuild() ||
4040 PointeeType != TL.getPointeeLoc().getType()) {
4041 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4042 if (Result.isNull())
4043 return QualType();
4044 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004045
John McCall31168b02011-06-15 23:02:42 +00004046 // Objective-C ARC can add lifetime qualifiers to the type that we're
4047 // pointing to.
4048 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004049
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004050 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4051 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004052 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004053}
Mike Stump11289f42009-09-09 15:08:12 +00004054
4055template<typename Derived>
4056QualType
John McCall550e0c22009-10-21 00:40:46 +00004057TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004058 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004059 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004060 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4061 if (PointeeType.isNull())
4062 return QualType();
4063
4064 QualType Result = TL.getType();
4065 if (getDerived().AlwaysRebuild() ||
4066 PointeeType != TL.getPointeeLoc().getType()) {
4067 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004068 TL.getSigilLoc());
4069 if (Result.isNull())
4070 return QualType();
4071 }
4072
Douglas Gregor049211a2010-04-22 16:50:51 +00004073 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004074 NewT.setSigilLoc(TL.getSigilLoc());
4075 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004076}
4077
John McCall70dd5f62009-10-30 00:06:24 +00004078/// Transforms a reference type. Note that somewhat paradoxically we
4079/// don't care whether the type itself is an l-value type or an r-value
4080/// type; we only care if the type was *written* as an l-value type
4081/// or an r-value type.
4082template<typename Derived>
4083QualType
4084TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004085 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004086 const ReferenceType *T = TL.getTypePtr();
4087
4088 // Note that this works with the pointee-as-written.
4089 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4090 if (PointeeType.isNull())
4091 return QualType();
4092
4093 QualType Result = TL.getType();
4094 if (getDerived().AlwaysRebuild() ||
4095 PointeeType != T->getPointeeTypeAsWritten()) {
4096 Result = getDerived().RebuildReferenceType(PointeeType,
4097 T->isSpelledAsLValue(),
4098 TL.getSigilLoc());
4099 if (Result.isNull())
4100 return QualType();
4101 }
4102
John McCall31168b02011-06-15 23:02:42 +00004103 // Objective-C ARC can add lifetime qualifiers to the type that we're
4104 // referring to.
4105 TLB.TypeWasModifiedSafely(
4106 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4107
John McCall70dd5f62009-10-30 00:06:24 +00004108 // r-value references can be rebuilt as l-value references.
4109 ReferenceTypeLoc NewTL;
4110 if (isa<LValueReferenceType>(Result))
4111 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4112 else
4113 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4114 NewTL.setSigilLoc(TL.getSigilLoc());
4115
4116 return Result;
4117}
4118
Mike Stump11289f42009-09-09 15:08:12 +00004119template<typename Derived>
4120QualType
John McCall550e0c22009-10-21 00:40:46 +00004121TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004122 LValueReferenceTypeLoc TL) {
4123 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004124}
4125
Mike Stump11289f42009-09-09 15:08:12 +00004126template<typename Derived>
4127QualType
John McCall550e0c22009-10-21 00:40:46 +00004128TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004129 RValueReferenceTypeLoc TL) {
4130 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004131}
Mike Stump11289f42009-09-09 15:08:12 +00004132
Douglas Gregord6ff3322009-08-04 16:50:30 +00004133template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004134QualType
John McCall550e0c22009-10-21 00:40:46 +00004135TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004136 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004137 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004138 if (PointeeType.isNull())
4139 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004140
Abramo Bagnara509357842011-03-05 14:42:21 +00004141 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004142 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004143 if (OldClsTInfo) {
4144 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4145 if (!NewClsTInfo)
4146 return QualType();
4147 }
4148
4149 const MemberPointerType *T = TL.getTypePtr();
4150 QualType OldClsType = QualType(T->getClass(), 0);
4151 QualType NewClsType;
4152 if (NewClsTInfo)
4153 NewClsType = NewClsTInfo->getType();
4154 else {
4155 NewClsType = getDerived().TransformType(OldClsType);
4156 if (NewClsType.isNull())
4157 return QualType();
4158 }
Mike Stump11289f42009-09-09 15:08:12 +00004159
John McCall550e0c22009-10-21 00:40:46 +00004160 QualType Result = TL.getType();
4161 if (getDerived().AlwaysRebuild() ||
4162 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004163 NewClsType != OldClsType) {
4164 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004165 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004166 if (Result.isNull())
4167 return QualType();
4168 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004169
Reid Kleckner0503a872013-12-05 01:23:43 +00004170 // If we had to adjust the pointee type when building a member pointer, make
4171 // sure to push TypeLoc info for it.
4172 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4173 if (MPT && PointeeType != MPT->getPointeeType()) {
4174 assert(isa<AdjustedType>(MPT->getPointeeType()));
4175 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4176 }
4177
John McCall550e0c22009-10-21 00:40:46 +00004178 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4179 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004180 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004181
4182 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004183}
4184
Mike Stump11289f42009-09-09 15:08:12 +00004185template<typename Derived>
4186QualType
John McCall550e0c22009-10-21 00:40:46 +00004187TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004188 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004189 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004190 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004191 if (ElementType.isNull())
4192 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004193
John McCall550e0c22009-10-21 00:40:46 +00004194 QualType Result = TL.getType();
4195 if (getDerived().AlwaysRebuild() ||
4196 ElementType != T->getElementType()) {
4197 Result = getDerived().RebuildConstantArrayType(ElementType,
4198 T->getSizeModifier(),
4199 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004200 T->getIndexTypeCVRQualifiers(),
4201 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004202 if (Result.isNull())
4203 return QualType();
4204 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004205
4206 // We might have either a ConstantArrayType or a VariableArrayType now:
4207 // a ConstantArrayType is allowed to have an element type which is a
4208 // VariableArrayType if the type is dependent. Fortunately, all array
4209 // types have the same location layout.
4210 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004211 NewTL.setLBracketLoc(TL.getLBracketLoc());
4212 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004213
John McCall550e0c22009-10-21 00:40:46 +00004214 Expr *Size = TL.getSizeExpr();
4215 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004216 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4217 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004218 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4219 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004220 }
4221 NewTL.setSizeExpr(Size);
4222
4223 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004224}
Mike Stump11289f42009-09-09 15:08:12 +00004225
Douglas Gregord6ff3322009-08-04 16:50:30 +00004226template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004227QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004228 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004229 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004230 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004231 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004232 if (ElementType.isNull())
4233 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004234
John McCall550e0c22009-10-21 00:40:46 +00004235 QualType Result = TL.getType();
4236 if (getDerived().AlwaysRebuild() ||
4237 ElementType != T->getElementType()) {
4238 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004239 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004240 T->getIndexTypeCVRQualifiers(),
4241 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004242 if (Result.isNull())
4243 return QualType();
4244 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004245
John McCall550e0c22009-10-21 00:40:46 +00004246 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4247 NewTL.setLBracketLoc(TL.getLBracketLoc());
4248 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004249 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004250
4251 return Result;
4252}
4253
4254template<typename Derived>
4255QualType
4256TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004257 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004258 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004259 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4260 if (ElementType.isNull())
4261 return QualType();
4262
John McCalldadc5752010-08-24 06:29:42 +00004263 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004264 = getDerived().TransformExpr(T->getSizeExpr());
4265 if (SizeResult.isInvalid())
4266 return QualType();
4267
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004268 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004269
4270 QualType Result = TL.getType();
4271 if (getDerived().AlwaysRebuild() ||
4272 ElementType != T->getElementType() ||
4273 Size != T->getSizeExpr()) {
4274 Result = getDerived().RebuildVariableArrayType(ElementType,
4275 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004276 Size,
John McCall550e0c22009-10-21 00:40:46 +00004277 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004278 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004279 if (Result.isNull())
4280 return QualType();
4281 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004282
Serge Pavlov774c6d02014-02-06 03:49:11 +00004283 // We might have constant size array now, but fortunately it has the same
4284 // location layout.
4285 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004286 NewTL.setLBracketLoc(TL.getLBracketLoc());
4287 NewTL.setRBracketLoc(TL.getRBracketLoc());
4288 NewTL.setSizeExpr(Size);
4289
4290 return Result;
4291}
4292
4293template<typename Derived>
4294QualType
4295TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004296 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004297 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004298 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4299 if (ElementType.isNull())
4300 return QualType();
4301
Richard Smith764d2fe2011-12-20 02:08:33 +00004302 // Array bounds are constant expressions.
4303 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4304 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004305
John McCall33ddac02011-01-19 10:06:00 +00004306 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4307 Expr *origSize = TL.getSizeExpr();
4308 if (!origSize) origSize = T->getSizeExpr();
4309
4310 ExprResult sizeResult
4311 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004312 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004313 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004314 return QualType();
4315
John McCall33ddac02011-01-19 10:06:00 +00004316 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004317
4318 QualType Result = TL.getType();
4319 if (getDerived().AlwaysRebuild() ||
4320 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004321 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004322 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4323 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004324 size,
John McCall550e0c22009-10-21 00:40:46 +00004325 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004326 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004327 if (Result.isNull())
4328 return QualType();
4329 }
John McCall550e0c22009-10-21 00:40:46 +00004330
4331 // We might have any sort of array type now, but fortunately they
4332 // all have the same location layout.
4333 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4334 NewTL.setLBracketLoc(TL.getLBracketLoc());
4335 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004336 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004337
4338 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004339}
Mike Stump11289f42009-09-09 15:08:12 +00004340
4341template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004342QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004343 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004344 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004345 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004346
4347 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004348 QualType ElementType = getDerived().TransformType(T->getElementType());
4349 if (ElementType.isNull())
4350 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004351
Richard Smith764d2fe2011-12-20 02:08:33 +00004352 // Vector sizes are constant expressions.
4353 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4354 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004355
John McCalldadc5752010-08-24 06:29:42 +00004356 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004357 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004358 if (Size.isInvalid())
4359 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004360
John McCall550e0c22009-10-21 00:40:46 +00004361 QualType Result = TL.getType();
4362 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004363 ElementType != T->getElementType() ||
4364 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004365 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004366 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004367 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004368 if (Result.isNull())
4369 return QualType();
4370 }
John McCall550e0c22009-10-21 00:40:46 +00004371
4372 // Result might be dependent or not.
4373 if (isa<DependentSizedExtVectorType>(Result)) {
4374 DependentSizedExtVectorTypeLoc NewTL
4375 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4376 NewTL.setNameLoc(TL.getNameLoc());
4377 } else {
4378 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4379 NewTL.setNameLoc(TL.getNameLoc());
4380 }
4381
4382 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004383}
Mike Stump11289f42009-09-09 15:08:12 +00004384
4385template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004386QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004387 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004388 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004389 QualType ElementType = getDerived().TransformType(T->getElementType());
4390 if (ElementType.isNull())
4391 return QualType();
4392
John McCall550e0c22009-10-21 00:40:46 +00004393 QualType Result = TL.getType();
4394 if (getDerived().AlwaysRebuild() ||
4395 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004396 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004397 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004398 if (Result.isNull())
4399 return QualType();
4400 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004401
John McCall550e0c22009-10-21 00:40:46 +00004402 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4403 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004404
John McCall550e0c22009-10-21 00:40:46 +00004405 return Result;
4406}
4407
4408template<typename Derived>
4409QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004410 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004411 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004412 QualType ElementType = getDerived().TransformType(T->getElementType());
4413 if (ElementType.isNull())
4414 return QualType();
4415
4416 QualType Result = TL.getType();
4417 if (getDerived().AlwaysRebuild() ||
4418 ElementType != T->getElementType()) {
4419 Result = getDerived().RebuildExtVectorType(ElementType,
4420 T->getNumElements(),
4421 /*FIXME*/ SourceLocation());
4422 if (Result.isNull())
4423 return QualType();
4424 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004425
John McCall550e0c22009-10-21 00:40:46 +00004426 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4427 NewTL.setNameLoc(TL.getNameLoc());
4428
4429 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004430}
Mike Stump11289f42009-09-09 15:08:12 +00004431
David Blaikie05785d12013-02-20 22:23:23 +00004432template <typename Derived>
4433ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4434 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4435 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004436 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004437 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004438
Douglas Gregor715e4612011-01-14 22:40:04 +00004439 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004440 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004441 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004442 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004443 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004444
Douglas Gregor715e4612011-01-14 22:40:04 +00004445 TypeLocBuilder TLB;
4446 TypeLoc NewTL = OldDI->getTypeLoc();
4447 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004448
4449 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004450 OldExpansionTL.getPatternLoc());
4451 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004452 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004453
4454 Result = RebuildPackExpansionType(Result,
4455 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004456 OldExpansionTL.getEllipsisLoc(),
4457 NumExpansions);
4458 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004459 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004460
Douglas Gregor715e4612011-01-14 22:40:04 +00004461 PackExpansionTypeLoc NewExpansionTL
4462 = TLB.push<PackExpansionTypeLoc>(Result);
4463 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4464 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4465 } else
4466 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004467 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004468 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004469
John McCall8fb0d9d2011-05-01 22:35:37 +00004470 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004471 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004472
4473 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4474 OldParm->getDeclContext(),
4475 OldParm->getInnerLocStart(),
4476 OldParm->getLocation(),
4477 OldParm->getIdentifier(),
4478 NewDI->getType(),
4479 NewDI,
4480 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004481 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004482 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4483 OldParm->getFunctionScopeIndex() + indexAdjustment);
4484 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004485}
4486
4487template<typename Derived>
4488bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004489 TransformFunctionTypeParams(SourceLocation Loc,
4490 ParmVarDecl **Params, unsigned NumParams,
4491 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004492 SmallVectorImpl<QualType> &OutParamTypes,
4493 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004494 int indexAdjustment = 0;
4495
Douglas Gregordd472162011-01-07 00:20:55 +00004496 for (unsigned i = 0; i != NumParams; ++i) {
4497 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004498 assert(OldParm->getFunctionScopeIndex() == i);
4499
David Blaikie05785d12013-02-20 22:23:23 +00004500 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004501 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004502 if (OldParm->isParameterPack()) {
4503 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004504 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004505
Douglas Gregor5499af42011-01-05 23:12:31 +00004506 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004507 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004508 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004509 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4510 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004511 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4512
Douglas Gregor5499af42011-01-05 23:12:31 +00004513 // Determine whether we should expand the parameter packs.
4514 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004515 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004516 Optional<unsigned> OrigNumExpansions =
4517 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004518 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004519 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4520 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004521 Unexpanded,
4522 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004523 RetainExpansion,
4524 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004525 return true;
4526 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004527
Douglas Gregor5499af42011-01-05 23:12:31 +00004528 if (ShouldExpand) {
4529 // Expand the function parameter pack into multiple, separate
4530 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004531 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004532 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004533 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004534 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004535 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004536 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004537 OrigNumExpansions,
4538 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004539 if (!NewParm)
4540 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004541
Douglas Gregordd472162011-01-07 00:20:55 +00004542 OutParamTypes.push_back(NewParm->getType());
4543 if (PVars)
4544 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004545 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004546
4547 // If we're supposed to retain a pack expansion, do so by temporarily
4548 // forgetting the partially-substituted parameter pack.
4549 if (RetainExpansion) {
4550 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004551 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004552 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004553 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004554 OrigNumExpansions,
4555 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004556 if (!NewParm)
4557 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004558
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004559 OutParamTypes.push_back(NewParm->getType());
4560 if (PVars)
4561 PVars->push_back(NewParm);
4562 }
4563
John McCall8fb0d9d2011-05-01 22:35:37 +00004564 // The next parameter should have the same adjustment as the
4565 // last thing we pushed, but we post-incremented indexAdjustment
4566 // on every push. Also, if we push nothing, the adjustment should
4567 // go down by one.
4568 indexAdjustment--;
4569
Douglas Gregor5499af42011-01-05 23:12:31 +00004570 // We're done with the pack expansion.
4571 continue;
4572 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004573
4574 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004575 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004576 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4577 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004578 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004579 NumExpansions,
4580 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004581 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004582 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004583 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004584 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004585
John McCall58f10c32010-03-11 09:03:00 +00004586 if (!NewParm)
4587 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004588
Douglas Gregordd472162011-01-07 00:20:55 +00004589 OutParamTypes.push_back(NewParm->getType());
4590 if (PVars)
4591 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004592 continue;
4593 }
John McCall58f10c32010-03-11 09:03:00 +00004594
4595 // Deal with the possibility that we don't have a parameter
4596 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004597 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004598 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004599 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004600 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004601 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004602 = dyn_cast<PackExpansionType>(OldType)) {
4603 // We have a function parameter pack that may need to be expanded.
4604 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004605 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004606 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004607
Douglas Gregor5499af42011-01-05 23:12:31 +00004608 // Determine whether we should expand the parameter packs.
4609 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004610 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004611 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004612 Unexpanded,
4613 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004614 RetainExpansion,
4615 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004616 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004617 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004618
Douglas Gregor5499af42011-01-05 23:12:31 +00004619 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004620 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004621 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004622 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004623 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4624 QualType NewType = getDerived().TransformType(Pattern);
4625 if (NewType.isNull())
4626 return true;
John McCall58f10c32010-03-11 09:03:00 +00004627
Douglas Gregordd472162011-01-07 00:20:55 +00004628 OutParamTypes.push_back(NewType);
4629 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004630 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004631 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004632
Douglas Gregor5499af42011-01-05 23:12:31 +00004633 // We're done with the pack expansion.
4634 continue;
4635 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004636
Douglas Gregor48d24112011-01-10 20:53:55 +00004637 // If we're supposed to retain a pack expansion, do so by temporarily
4638 // forgetting the partially-substituted parameter pack.
4639 if (RetainExpansion) {
4640 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4641 QualType NewType = getDerived().TransformType(Pattern);
4642 if (NewType.isNull())
4643 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004644
Douglas Gregor48d24112011-01-10 20:53:55 +00004645 OutParamTypes.push_back(NewType);
4646 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004647 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004648 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004649
Chad Rosier1dcde962012-08-08 18:46:20 +00004650 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004651 // expansion.
4652 OldType = Expansion->getPattern();
4653 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004654 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4655 NewType = getDerived().TransformType(OldType);
4656 } else {
4657 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004658 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004659
Douglas Gregor5499af42011-01-05 23:12:31 +00004660 if (NewType.isNull())
4661 return true;
4662
4663 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004664 NewType = getSema().Context.getPackExpansionType(NewType,
4665 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004666
Douglas Gregordd472162011-01-07 00:20:55 +00004667 OutParamTypes.push_back(NewType);
4668 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004669 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004670 }
4671
John McCall8fb0d9d2011-05-01 22:35:37 +00004672#ifndef NDEBUG
4673 if (PVars) {
4674 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4675 if (ParmVarDecl *parm = (*PVars)[i])
4676 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004677 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004678#endif
4679
4680 return false;
4681}
John McCall58f10c32010-03-11 09:03:00 +00004682
4683template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004684QualType
John McCall550e0c22009-10-21 00:40:46 +00004685TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004686 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004687 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004688 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004689 return getDerived().TransformFunctionProtoType(
4690 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004691 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4692 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4693 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004694 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004695}
4696
Richard Smith2e321552014-11-12 02:00:47 +00004697template<typename Derived> template<typename Fn>
4698QualType TreeTransform<Derived>::TransformFunctionProtoType(
4699 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4700 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004701 // Transform the parameters and return type.
4702 //
Richard Smithf623c962012-04-17 00:58:00 +00004703 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004704 // When the function has a trailing return type, we instantiate the
4705 // parameters before the return type, since the return type can then refer
4706 // to the parameters themselves (via decltype, sizeof, etc.).
4707 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004708 SmallVector<QualType, 4> ParamTypes;
4709 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004710 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004711
Douglas Gregor7fb25412010-10-01 18:44:50 +00004712 QualType ResultType;
4713
Richard Smith1226c602012-08-14 22:51:13 +00004714 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004715 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004716 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004717 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004718 return QualType();
4719
Douglas Gregor3024f072012-04-16 07:05:22 +00004720 {
4721 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004722 // If a declaration declares a member function or member function
4723 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004724 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004725 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004726 // declarator.
4727 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004728
Alp Toker42a16a62014-01-25 23:51:36 +00004729 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004730 if (ResultType.isNull())
4731 return QualType();
4732 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004733 }
4734 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004735 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004736 if (ResultType.isNull())
4737 return QualType();
4738
Alp Toker9cacbab2014-01-20 20:26:09 +00004739 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004740 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004741 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004742 return QualType();
4743 }
4744
Richard Smith2e321552014-11-12 02:00:47 +00004745 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4746
4747 bool EPIChanged = false;
4748 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4749 return QualType();
4750
4751 // FIXME: Need to transform ConsumedParameters for variadic template
4752 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004753
John McCall550e0c22009-10-21 00:40:46 +00004754 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004755 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00004756 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00004757 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004758 if (Result.isNull())
4759 return QualType();
4760 }
Mike Stump11289f42009-09-09 15:08:12 +00004761
John McCall550e0c22009-10-21 00:40:46 +00004762 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004763 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004764 NewTL.setLParenLoc(TL.getLParenLoc());
4765 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004766 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004767 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4768 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004769
4770 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004771}
Mike Stump11289f42009-09-09 15:08:12 +00004772
Douglas Gregord6ff3322009-08-04 16:50:30 +00004773template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004774bool TreeTransform<Derived>::TransformExceptionSpec(
4775 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4776 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4777 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4778
4779 // Instantiate a dynamic noexcept expression, if any.
4780 if (ESI.Type == EST_ComputedNoexcept) {
4781 EnterExpressionEvaluationContext Unevaluated(getSema(),
4782 Sema::ConstantEvaluated);
4783 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4784 if (NoexceptExpr.isInvalid())
4785 return true;
4786
4787 NoexceptExpr = getSema().CheckBooleanCondition(
4788 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4789 if (NoexceptExpr.isInvalid())
4790 return true;
4791
4792 if (!NoexceptExpr.get()->isValueDependent()) {
4793 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4794 NoexceptExpr.get(), nullptr,
4795 diag::err_noexcept_needs_constant_expression,
4796 /*AllowFold*/false);
4797 if (NoexceptExpr.isInvalid())
4798 return true;
4799 }
4800
4801 if (ESI.NoexceptExpr != NoexceptExpr.get())
4802 Changed = true;
4803 ESI.NoexceptExpr = NoexceptExpr.get();
4804 }
4805
4806 if (ESI.Type != EST_Dynamic)
4807 return false;
4808
4809 // Instantiate a dynamic exception specification's type.
4810 for (QualType T : ESI.Exceptions) {
4811 if (const PackExpansionType *PackExpansion =
4812 T->getAs<PackExpansionType>()) {
4813 Changed = true;
4814
4815 // We have a pack expansion. Instantiate it.
4816 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4817 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4818 Unexpanded);
4819 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4820
4821 // Determine whether the set of unexpanded parameter packs can and
4822 // should
4823 // be expanded.
4824 bool Expand = false;
4825 bool RetainExpansion = false;
4826 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4827 // FIXME: Track the location of the ellipsis (and track source location
4828 // information for the types in the exception specification in general).
4829 if (getDerived().TryExpandParameterPacks(
4830 Loc, SourceRange(), Unexpanded, Expand,
4831 RetainExpansion, NumExpansions))
4832 return true;
4833
4834 if (!Expand) {
4835 // We can't expand this pack expansion into separate arguments yet;
4836 // just substitute into the pattern and create a new pack expansion
4837 // type.
4838 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4839 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4840 if (U.isNull())
4841 return true;
4842
4843 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4844 Exceptions.push_back(U);
4845 continue;
4846 }
4847
4848 // Substitute into the pack expansion pattern for each slice of the
4849 // pack.
4850 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4851 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4852
4853 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4854 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4855 return true;
4856
4857 Exceptions.push_back(U);
4858 }
4859 } else {
4860 QualType U = getDerived().TransformType(T);
4861 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4862 return true;
4863 if (T != U)
4864 Changed = true;
4865
4866 Exceptions.push_back(U);
4867 }
4868 }
4869
4870 ESI.Exceptions = Exceptions;
4871 return false;
4872}
4873
4874template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004875QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004876 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004877 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004878 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004879 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004880 if (ResultType.isNull())
4881 return QualType();
4882
4883 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004884 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004885 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4886
4887 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004888 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004889 NewTL.setLParenLoc(TL.getLParenLoc());
4890 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004891 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004892
4893 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004894}
Mike Stump11289f42009-09-09 15:08:12 +00004895
John McCallb96ec562009-12-04 22:46:56 +00004896template<typename Derived> QualType
4897TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004898 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004899 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004900 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004901 if (!D)
4902 return QualType();
4903
4904 QualType Result = TL.getType();
4905 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4906 Result = getDerived().RebuildUnresolvedUsingType(D);
4907 if (Result.isNull())
4908 return QualType();
4909 }
4910
4911 // We might get an arbitrary type spec type back. We should at
4912 // least always get a type spec type, though.
4913 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4914 NewTL.setNameLoc(TL.getNameLoc());
4915
4916 return Result;
4917}
4918
Douglas Gregord6ff3322009-08-04 16:50:30 +00004919template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004920QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004921 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004922 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004923 TypedefNameDecl *Typedef
4924 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4925 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004926 if (!Typedef)
4927 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004928
John McCall550e0c22009-10-21 00:40:46 +00004929 QualType Result = TL.getType();
4930 if (getDerived().AlwaysRebuild() ||
4931 Typedef != T->getDecl()) {
4932 Result = getDerived().RebuildTypedefType(Typedef);
4933 if (Result.isNull())
4934 return QualType();
4935 }
Mike Stump11289f42009-09-09 15:08:12 +00004936
John McCall550e0c22009-10-21 00:40:46 +00004937 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4938 NewTL.setNameLoc(TL.getNameLoc());
4939
4940 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004941}
Mike Stump11289f42009-09-09 15:08:12 +00004942
Douglas Gregord6ff3322009-08-04 16:50:30 +00004943template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004944QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004945 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004946 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004947 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4948 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004949
John McCalldadc5752010-08-24 06:29:42 +00004950 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004951 if (E.isInvalid())
4952 return QualType();
4953
Eli Friedmane4f22df2012-02-29 04:03:55 +00004954 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4955 if (E.isInvalid())
4956 return QualType();
4957
John McCall550e0c22009-10-21 00:40:46 +00004958 QualType Result = TL.getType();
4959 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004960 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004961 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004962 if (Result.isNull())
4963 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004964 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004965 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004966
John McCall550e0c22009-10-21 00:40:46 +00004967 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004968 NewTL.setTypeofLoc(TL.getTypeofLoc());
4969 NewTL.setLParenLoc(TL.getLParenLoc());
4970 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004971
4972 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004973}
Mike Stump11289f42009-09-09 15:08:12 +00004974
4975template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004976QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004977 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004978 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4979 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4980 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004981 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004982
John McCall550e0c22009-10-21 00:40:46 +00004983 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004984 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4985 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004986 if (Result.isNull())
4987 return QualType();
4988 }
Mike Stump11289f42009-09-09 15:08:12 +00004989
John McCall550e0c22009-10-21 00:40:46 +00004990 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004991 NewTL.setTypeofLoc(TL.getTypeofLoc());
4992 NewTL.setLParenLoc(TL.getLParenLoc());
4993 NewTL.setRParenLoc(TL.getRParenLoc());
4994 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004995
4996 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004997}
Mike Stump11289f42009-09-09 15:08:12 +00004998
4999template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005000QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005001 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005002 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005003
Douglas Gregore922c772009-08-04 22:27:00 +00005004 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005005 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5006 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005007
John McCalldadc5752010-08-24 06:29:42 +00005008 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005009 if (E.isInvalid())
5010 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005011
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005012 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005013 if (E.isInvalid())
5014 return QualType();
5015
John McCall550e0c22009-10-21 00:40:46 +00005016 QualType Result = TL.getType();
5017 if (getDerived().AlwaysRebuild() ||
5018 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005019 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005020 if (Result.isNull())
5021 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005022 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005023 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005024
John McCall550e0c22009-10-21 00:40:46 +00005025 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5026 NewTL.setNameLoc(TL.getNameLoc());
5027
5028 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005029}
5030
5031template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005032QualType TreeTransform<Derived>::TransformUnaryTransformType(
5033 TypeLocBuilder &TLB,
5034 UnaryTransformTypeLoc TL) {
5035 QualType Result = TL.getType();
5036 if (Result->isDependentType()) {
5037 const UnaryTransformType *T = TL.getTypePtr();
5038 QualType NewBase =
5039 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5040 Result = getDerived().RebuildUnaryTransformType(NewBase,
5041 T->getUTTKind(),
5042 TL.getKWLoc());
5043 if (Result.isNull())
5044 return QualType();
5045 }
5046
5047 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5048 NewTL.setKWLoc(TL.getKWLoc());
5049 NewTL.setParensRange(TL.getParensRange());
5050 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5051 return Result;
5052}
5053
5054template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005055QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5056 AutoTypeLoc TL) {
5057 const AutoType *T = TL.getTypePtr();
5058 QualType OldDeduced = T->getDeducedType();
5059 QualType NewDeduced;
5060 if (!OldDeduced.isNull()) {
5061 NewDeduced = getDerived().TransformType(OldDeduced);
5062 if (NewDeduced.isNull())
5063 return QualType();
5064 }
5065
5066 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005067 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5068 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00005069 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00005070 if (Result.isNull())
5071 return QualType();
5072 }
5073
5074 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5075 NewTL.setNameLoc(TL.getNameLoc());
5076
5077 return Result;
5078}
5079
5080template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005081QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005082 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005083 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005084 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005085 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5086 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005087 if (!Record)
5088 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005089
John McCall550e0c22009-10-21 00:40:46 +00005090 QualType Result = TL.getType();
5091 if (getDerived().AlwaysRebuild() ||
5092 Record != T->getDecl()) {
5093 Result = getDerived().RebuildRecordType(Record);
5094 if (Result.isNull())
5095 return QualType();
5096 }
Mike Stump11289f42009-09-09 15:08:12 +00005097
John McCall550e0c22009-10-21 00:40:46 +00005098 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5099 NewTL.setNameLoc(TL.getNameLoc());
5100
5101 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005102}
Mike Stump11289f42009-09-09 15:08:12 +00005103
5104template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005105QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005106 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005107 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005108 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005109 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5110 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005111 if (!Enum)
5112 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005113
John McCall550e0c22009-10-21 00:40:46 +00005114 QualType Result = TL.getType();
5115 if (getDerived().AlwaysRebuild() ||
5116 Enum != T->getDecl()) {
5117 Result = getDerived().RebuildEnumType(Enum);
5118 if (Result.isNull())
5119 return QualType();
5120 }
Mike Stump11289f42009-09-09 15:08:12 +00005121
John McCall550e0c22009-10-21 00:40:46 +00005122 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5123 NewTL.setNameLoc(TL.getNameLoc());
5124
5125 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005126}
John McCallfcc33b02009-09-05 00:15:47 +00005127
John McCalle78aac42010-03-10 03:28:59 +00005128template<typename Derived>
5129QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5130 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005131 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005132 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5133 TL.getTypePtr()->getDecl());
5134 if (!D) return QualType();
5135
5136 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5137 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5138 return T;
5139}
5140
Douglas Gregord6ff3322009-08-04 16:50:30 +00005141template<typename Derived>
5142QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005143 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005144 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005145 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005146}
5147
Mike Stump11289f42009-09-09 15:08:12 +00005148template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005149QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005150 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005151 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005152 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005153
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005154 // Substitute into the replacement type, which itself might involve something
5155 // that needs to be transformed. This only tends to occur with default
5156 // template arguments of template template parameters.
5157 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5158 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5159 if (Replacement.isNull())
5160 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005161
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005162 // Always canonicalize the replacement type.
5163 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5164 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005165 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005166 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005167
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005168 // Propagate type-source information.
5169 SubstTemplateTypeParmTypeLoc NewTL
5170 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5171 NewTL.setNameLoc(TL.getNameLoc());
5172 return Result;
5173
John McCallcebee162009-10-18 09:09:24 +00005174}
5175
5176template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005177QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5178 TypeLocBuilder &TLB,
5179 SubstTemplateTypeParmPackTypeLoc TL) {
5180 return TransformTypeSpecType(TLB, TL);
5181}
5182
5183template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005184QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005185 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005186 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005187 const TemplateSpecializationType *T = TL.getTypePtr();
5188
Douglas Gregordf846d12011-03-02 18:46:51 +00005189 // The nested-name-specifier never matters in a TemplateSpecializationType,
5190 // because we can't have a dependent nested-name-specifier anyway.
5191 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005192 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005193 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5194 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005195 if (Template.isNull())
5196 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005197
John McCall31f82722010-11-12 08:19:04 +00005198 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5199}
5200
Eli Friedman0dfb8892011-10-06 23:00:33 +00005201template<typename Derived>
5202QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5203 AtomicTypeLoc TL) {
5204 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5205 if (ValueType.isNull())
5206 return QualType();
5207
5208 QualType Result = TL.getType();
5209 if (getDerived().AlwaysRebuild() ||
5210 ValueType != TL.getValueLoc().getType()) {
5211 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5212 if (Result.isNull())
5213 return QualType();
5214 }
5215
5216 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5217 NewTL.setKWLoc(TL.getKWLoc());
5218 NewTL.setLParenLoc(TL.getLParenLoc());
5219 NewTL.setRParenLoc(TL.getRParenLoc());
5220
5221 return Result;
5222}
5223
Chad Rosier1dcde962012-08-08 18:46:20 +00005224 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005225 /// container that provides a \c getArgLoc() member function.
5226 ///
5227 /// This iterator is intended to be used with the iterator form of
5228 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5229 template<typename ArgLocContainer>
5230 class TemplateArgumentLocContainerIterator {
5231 ArgLocContainer *Container;
5232 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005233
Douglas Gregorfe921a72010-12-20 23:36:19 +00005234 public:
5235 typedef TemplateArgumentLoc value_type;
5236 typedef TemplateArgumentLoc reference;
5237 typedef int difference_type;
5238 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005239
Douglas Gregorfe921a72010-12-20 23:36:19 +00005240 class pointer {
5241 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005242
Douglas Gregorfe921a72010-12-20 23:36:19 +00005243 public:
5244 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005245
Douglas Gregorfe921a72010-12-20 23:36:19 +00005246 const TemplateArgumentLoc *operator->() const {
5247 return &Arg;
5248 }
5249 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005250
5251
Douglas Gregorfe921a72010-12-20 23:36:19 +00005252 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005253
Douglas Gregorfe921a72010-12-20 23:36:19 +00005254 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5255 unsigned Index)
5256 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005257
Douglas Gregorfe921a72010-12-20 23:36:19 +00005258 TemplateArgumentLocContainerIterator &operator++() {
5259 ++Index;
5260 return *this;
5261 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005262
Douglas Gregorfe921a72010-12-20 23:36:19 +00005263 TemplateArgumentLocContainerIterator operator++(int) {
5264 TemplateArgumentLocContainerIterator Old(*this);
5265 ++(*this);
5266 return Old;
5267 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005268
Douglas Gregorfe921a72010-12-20 23:36:19 +00005269 TemplateArgumentLoc operator*() const {
5270 return Container->getArgLoc(Index);
5271 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005272
Douglas Gregorfe921a72010-12-20 23:36:19 +00005273 pointer operator->() const {
5274 return pointer(Container->getArgLoc(Index));
5275 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005276
Douglas Gregorfe921a72010-12-20 23:36:19 +00005277 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005278 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005279 return X.Container == Y.Container && X.Index == Y.Index;
5280 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005281
Douglas Gregorfe921a72010-12-20 23:36:19 +00005282 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005283 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005284 return !(X == Y);
5285 }
5286 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005287
5288
John McCall31f82722010-11-12 08:19:04 +00005289template <typename Derived>
5290QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5291 TypeLocBuilder &TLB,
5292 TemplateSpecializationTypeLoc TL,
5293 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005294 TemplateArgumentListInfo NewTemplateArgs;
5295 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5296 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005297 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5298 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005299 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005300 ArgIterator(TL, TL.getNumArgs()),
5301 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005302 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005303
John McCall0ad16662009-10-29 08:12:44 +00005304 // FIXME: maybe don't rebuild if all the template arguments are the same.
5305
5306 QualType Result =
5307 getDerived().RebuildTemplateSpecializationType(Template,
5308 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005309 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005310
5311 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005312 // Specializations of template template parameters are represented as
5313 // TemplateSpecializationTypes, and substitution of type alias templates
5314 // within a dependent context can transform them into
5315 // DependentTemplateSpecializationTypes.
5316 if (isa<DependentTemplateSpecializationType>(Result)) {
5317 DependentTemplateSpecializationTypeLoc NewTL
5318 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005319 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005320 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005321 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005322 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005323 NewTL.setLAngleLoc(TL.getLAngleLoc());
5324 NewTL.setRAngleLoc(TL.getRAngleLoc());
5325 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5326 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5327 return Result;
5328 }
5329
John McCall0ad16662009-10-29 08:12:44 +00005330 TemplateSpecializationTypeLoc NewTL
5331 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005332 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005333 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5334 NewTL.setLAngleLoc(TL.getLAngleLoc());
5335 NewTL.setRAngleLoc(TL.getRAngleLoc());
5336 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5337 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005338 }
Mike Stump11289f42009-09-09 15:08:12 +00005339
John McCall0ad16662009-10-29 08:12:44 +00005340 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005341}
Mike Stump11289f42009-09-09 15:08:12 +00005342
Douglas Gregor5a064722011-02-28 17:23:35 +00005343template <typename Derived>
5344QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5345 TypeLocBuilder &TLB,
5346 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005347 TemplateName Template,
5348 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005349 TemplateArgumentListInfo NewTemplateArgs;
5350 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5351 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5352 typedef TemplateArgumentLocContainerIterator<
5353 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005354 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005355 ArgIterator(TL, TL.getNumArgs()),
5356 NewTemplateArgs))
5357 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005358
Douglas Gregor5a064722011-02-28 17:23:35 +00005359 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005360
Douglas Gregor5a064722011-02-28 17:23:35 +00005361 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5362 QualType Result
5363 = getSema().Context.getDependentTemplateSpecializationType(
5364 TL.getTypePtr()->getKeyword(),
5365 DTN->getQualifier(),
5366 DTN->getIdentifier(),
5367 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005368
Douglas Gregor5a064722011-02-28 17:23:35 +00005369 DependentTemplateSpecializationTypeLoc NewTL
5370 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005371 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005372 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005373 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005374 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005375 NewTL.setLAngleLoc(TL.getLAngleLoc());
5376 NewTL.setRAngleLoc(TL.getRAngleLoc());
5377 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5378 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5379 return Result;
5380 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005381
5382 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005383 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005384 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005385 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005386
Douglas Gregor5a064722011-02-28 17:23:35 +00005387 if (!Result.isNull()) {
5388 /// FIXME: Wrap this in an elaborated-type-specifier?
5389 TemplateSpecializationTypeLoc NewTL
5390 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005391 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005392 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005393 NewTL.setLAngleLoc(TL.getLAngleLoc());
5394 NewTL.setRAngleLoc(TL.getRAngleLoc());
5395 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5396 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5397 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005398
Douglas Gregor5a064722011-02-28 17:23:35 +00005399 return Result;
5400}
5401
Mike Stump11289f42009-09-09 15:08:12 +00005402template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005403QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005404TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005405 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005406 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005407
Douglas Gregor844cb502011-03-01 18:12:44 +00005408 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005409 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005410 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005411 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005412 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5413 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005414 return QualType();
5415 }
Mike Stump11289f42009-09-09 15:08:12 +00005416
John McCall31f82722010-11-12 08:19:04 +00005417 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5418 if (NamedT.isNull())
5419 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005420
Richard Smith3f1b5d02011-05-05 21:57:07 +00005421 // C++0x [dcl.type.elab]p2:
5422 // If the identifier resolves to a typedef-name or the simple-template-id
5423 // resolves to an alias template specialization, the
5424 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005425 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5426 if (const TemplateSpecializationType *TST =
5427 NamedT->getAs<TemplateSpecializationType>()) {
5428 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005429 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5430 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005431 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5432 diag::err_tag_reference_non_tag) << 4;
5433 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5434 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005435 }
5436 }
5437
John McCall550e0c22009-10-21 00:40:46 +00005438 QualType Result = TL.getType();
5439 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005440 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005441 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005442 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005443 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005444 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005445 if (Result.isNull())
5446 return QualType();
5447 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005448
Abramo Bagnara6150c882010-05-11 21:36:43 +00005449 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005450 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005451 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005452 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005453}
Mike Stump11289f42009-09-09 15:08:12 +00005454
5455template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005456QualType TreeTransform<Derived>::TransformAttributedType(
5457 TypeLocBuilder &TLB,
5458 AttributedTypeLoc TL) {
5459 const AttributedType *oldType = TL.getTypePtr();
5460 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5461 if (modifiedType.isNull())
5462 return QualType();
5463
5464 QualType result = TL.getType();
5465
5466 // FIXME: dependent operand expressions?
5467 if (getDerived().AlwaysRebuild() ||
5468 modifiedType != oldType->getModifiedType()) {
5469 // TODO: this is really lame; we should really be rebuilding the
5470 // equivalent type from first principles.
5471 QualType equivalentType
5472 = getDerived().TransformType(oldType->getEquivalentType());
5473 if (equivalentType.isNull())
5474 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005475
5476 // Check whether we can add nullability; it is only represented as
5477 // type sugar, and therefore cannot be diagnosed in any other way.
5478 if (auto nullability = oldType->getImmediateNullability()) {
5479 if (!modifiedType->canHaveNullability()) {
5480 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005481 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005482 return QualType();
5483 }
5484 }
5485
John McCall81904512011-01-06 01:58:22 +00005486 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5487 modifiedType,
5488 equivalentType);
5489 }
5490
5491 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5492 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5493 if (TL.hasAttrOperand())
5494 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5495 if (TL.hasAttrExprOperand())
5496 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5497 else if (TL.hasAttrEnumOperand())
5498 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5499
5500 return result;
5501}
5502
5503template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005504QualType
5505TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5506 ParenTypeLoc TL) {
5507 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5508 if (Inner.isNull())
5509 return QualType();
5510
5511 QualType Result = TL.getType();
5512 if (getDerived().AlwaysRebuild() ||
5513 Inner != TL.getInnerLoc().getType()) {
5514 Result = getDerived().RebuildParenType(Inner);
5515 if (Result.isNull())
5516 return QualType();
5517 }
5518
5519 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5520 NewTL.setLParenLoc(TL.getLParenLoc());
5521 NewTL.setRParenLoc(TL.getRParenLoc());
5522 return Result;
5523}
5524
5525template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005526QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005527 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005528 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005529
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005530 NestedNameSpecifierLoc QualifierLoc
5531 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5532 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005533 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005534
John McCallc392f372010-06-11 00:33:02 +00005535 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005536 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005537 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005538 QualifierLoc,
5539 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005540 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005541 if (Result.isNull())
5542 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005543
Abramo Bagnarad7548482010-05-19 21:37:53 +00005544 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5545 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005546 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5547
Abramo Bagnarad7548482010-05-19 21:37:53 +00005548 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005549 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005550 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005551 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005552 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005553 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005554 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005555 NewTL.setNameLoc(TL.getNameLoc());
5556 }
John McCall550e0c22009-10-21 00:40:46 +00005557 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005558}
Mike Stump11289f42009-09-09 15:08:12 +00005559
Douglas Gregord6ff3322009-08-04 16:50:30 +00005560template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005561QualType TreeTransform<Derived>::
5562 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005563 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005564 NestedNameSpecifierLoc QualifierLoc;
5565 if (TL.getQualifierLoc()) {
5566 QualifierLoc
5567 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5568 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005569 return QualType();
5570 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005571
John McCall31f82722010-11-12 08:19:04 +00005572 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005573 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005574}
5575
5576template<typename Derived>
5577QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005578TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5579 DependentTemplateSpecializationTypeLoc TL,
5580 NestedNameSpecifierLoc QualifierLoc) {
5581 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005582
Douglas Gregora7a795b2011-03-01 20:11:18 +00005583 TemplateArgumentListInfo NewTemplateArgs;
5584 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5585 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005586
Douglas Gregora7a795b2011-03-01 20:11:18 +00005587 typedef TemplateArgumentLocContainerIterator<
5588 DependentTemplateSpecializationTypeLoc> ArgIterator;
5589 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5590 ArgIterator(TL, TL.getNumArgs()),
5591 NewTemplateArgs))
5592 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005593
Douglas Gregora7a795b2011-03-01 20:11:18 +00005594 QualType Result
5595 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5596 QualifierLoc,
5597 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005598 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005599 NewTemplateArgs);
5600 if (Result.isNull())
5601 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005602
Douglas Gregora7a795b2011-03-01 20:11:18 +00005603 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5604 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005605
Douglas Gregora7a795b2011-03-01 20:11:18 +00005606 // Copy information relevant to the template specialization.
5607 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005608 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005609 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005610 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005611 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5612 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005613 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005614 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005615
Douglas Gregora7a795b2011-03-01 20:11:18 +00005616 // Copy information relevant to the elaborated type.
5617 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005618 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005619 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005620 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5621 DependentTemplateSpecializationTypeLoc SpecTL
5622 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005623 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005624 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005625 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005626 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005627 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5628 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005629 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005630 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005631 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005632 TemplateSpecializationTypeLoc SpecTL
5633 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005634 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005635 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005636 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5637 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005638 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005639 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005640 }
5641 return Result;
5642}
5643
5644template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005645QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5646 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005647 QualType Pattern
5648 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005649 if (Pattern.isNull())
5650 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005651
5652 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005653 if (getDerived().AlwaysRebuild() ||
5654 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005655 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005656 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005657 TL.getEllipsisLoc(),
5658 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005659 if (Result.isNull())
5660 return QualType();
5661 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005662
Douglas Gregor822d0302011-01-12 17:07:58 +00005663 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5664 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5665 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005666}
5667
5668template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005669QualType
5670TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005671 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005672 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005673 TLB.pushFullCopy(TL);
5674 return TL.getType();
5675}
5676
5677template<typename Derived>
5678QualType
5679TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005680 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005681 // Transform base type.
5682 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5683 if (BaseType.isNull())
5684 return QualType();
5685
5686 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5687
5688 // Transform type arguments.
5689 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5690 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5691 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5692 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5693 QualType TypeArg = TypeArgInfo->getType();
5694 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5695 AnyChanged = true;
5696
5697 // We have a pack expansion. Instantiate it.
5698 const auto *PackExpansion = PackExpansionLoc.getType()
5699 ->castAs<PackExpansionType>();
5700 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5701 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5702 Unexpanded);
5703 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5704
5705 // Determine whether the set of unexpanded parameter packs can
5706 // and should be expanded.
5707 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5708 bool Expand = false;
5709 bool RetainExpansion = false;
5710 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5711 if (getDerived().TryExpandParameterPacks(
5712 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5713 Unexpanded, Expand, RetainExpansion, NumExpansions))
5714 return QualType();
5715
5716 if (!Expand) {
5717 // We can't expand this pack expansion into separate arguments yet;
5718 // just substitute into the pattern and create a new pack expansion
5719 // type.
5720 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5721
5722 TypeLocBuilder TypeArgBuilder;
5723 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5724 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5725 PatternLoc);
5726 if (NewPatternType.isNull())
5727 return QualType();
5728
5729 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5730 NewPatternType, NumExpansions);
5731 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5732 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5733 NewTypeArgInfos.push_back(
5734 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5735 continue;
5736 }
5737
5738 // Substitute into the pack expansion pattern for each slice of the
5739 // pack.
5740 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5741 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5742
5743 TypeLocBuilder TypeArgBuilder;
5744 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5745
5746 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5747 PatternLoc);
5748 if (NewTypeArg.isNull())
5749 return QualType();
5750
5751 NewTypeArgInfos.push_back(
5752 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5753 }
5754
5755 continue;
5756 }
5757
5758 TypeLocBuilder TypeArgBuilder;
5759 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
5760 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
5761 if (NewTypeArg.isNull())
5762 return QualType();
5763
5764 // If nothing changed, just keep the old TypeSourceInfo.
5765 if (NewTypeArg == TypeArg) {
5766 NewTypeArgInfos.push_back(TypeArgInfo);
5767 continue;
5768 }
5769
5770 NewTypeArgInfos.push_back(
5771 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5772 AnyChanged = true;
5773 }
5774
5775 QualType Result = TL.getType();
5776 if (getDerived().AlwaysRebuild() || AnyChanged) {
5777 // Rebuild the type.
5778 Result = getDerived().RebuildObjCObjectType(
5779 BaseType,
5780 TL.getLocStart(),
5781 TL.getTypeArgsLAngleLoc(),
5782 NewTypeArgInfos,
5783 TL.getTypeArgsRAngleLoc(),
5784 TL.getProtocolLAngleLoc(),
5785 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5786 TL.getNumProtocols()),
5787 TL.getProtocolLocs(),
5788 TL.getProtocolRAngleLoc());
5789
5790 if (Result.isNull())
5791 return QualType();
5792 }
5793
5794 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
5795 assert(TL.hasBaseTypeAsWritten() && "Can't be dependent");
5796 NewT.setHasBaseTypeAsWritten(true);
5797 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
5798 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
5799 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
5800 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
5801 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5802 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5803 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
5804 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5805 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005806}
Mike Stump11289f42009-09-09 15:08:12 +00005807
5808template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005809QualType
5810TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005811 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005812 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5813 if (PointeeType.isNull())
5814 return QualType();
5815
5816 QualType Result = TL.getType();
5817 if (getDerived().AlwaysRebuild() ||
5818 PointeeType != TL.getPointeeLoc().getType()) {
5819 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
5820 TL.getStarLoc());
5821 if (Result.isNull())
5822 return QualType();
5823 }
5824
5825 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5826 NewT.setStarLoc(TL.getStarLoc());
5827 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005828}
5829
Douglas Gregord6ff3322009-08-04 16:50:30 +00005830//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005831// Statement transformation
5832//===----------------------------------------------------------------------===//
5833template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005834StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005835TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005836 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005837}
5838
5839template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005840StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005841TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5842 return getDerived().TransformCompoundStmt(S, false);
5843}
5844
5845template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005846StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005847TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005848 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005849 Sema::CompoundScopeRAII CompoundScope(getSema());
5850
John McCall1ababa62010-08-27 19:56:05 +00005851 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005852 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005853 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005854 for (auto *B : S->body()) {
5855 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005856 if (Result.isInvalid()) {
5857 // Immediately fail if this was a DeclStmt, since it's very
5858 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005859 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005860 return StmtError();
5861
5862 // Otherwise, just keep processing substatements and fail later.
5863 SubStmtInvalid = true;
5864 continue;
5865 }
Mike Stump11289f42009-09-09 15:08:12 +00005866
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005867 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005868 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005869 }
Mike Stump11289f42009-09-09 15:08:12 +00005870
John McCall1ababa62010-08-27 19:56:05 +00005871 if (SubStmtInvalid)
5872 return StmtError();
5873
Douglas Gregorebe10102009-08-20 07:17:43 +00005874 if (!getDerived().AlwaysRebuild() &&
5875 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005876 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005877
5878 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005879 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005880 S->getRBracLoc(),
5881 IsStmtExpr);
5882}
Mike Stump11289f42009-09-09 15:08:12 +00005883
Douglas Gregorebe10102009-08-20 07:17:43 +00005884template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005885StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005886TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005887 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005888 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005889 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5890 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005891
Eli Friedman06577382009-11-19 03:14:00 +00005892 // Transform the left-hand case value.
5893 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005894 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005895 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005896 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005897
Eli Friedman06577382009-11-19 03:14:00 +00005898 // Transform the right-hand case value (for the GNU case-range extension).
5899 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005900 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005901 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005902 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005903 }
Mike Stump11289f42009-09-09 15:08:12 +00005904
Douglas Gregorebe10102009-08-20 07:17:43 +00005905 // Build the case statement.
5906 // Case statements are always rebuilt so that they will attached to their
5907 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005908 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005909 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005910 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005911 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005912 S->getColonLoc());
5913 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005914 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005915
Douglas Gregorebe10102009-08-20 07:17:43 +00005916 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005917 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005918 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005919 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005920
Douglas Gregorebe10102009-08-20 07:17:43 +00005921 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005922 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005923}
5924
5925template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005926StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005927TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005928 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005929 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005930 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005931 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005932
Douglas Gregorebe10102009-08-20 07:17:43 +00005933 // Default statements are always rebuilt
5934 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005935 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005936}
Mike Stump11289f42009-09-09 15:08:12 +00005937
Douglas Gregorebe10102009-08-20 07:17:43 +00005938template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005939StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005940TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005941 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005942 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005943 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005944
Chris Lattnercab02a62011-02-17 20:34:02 +00005945 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5946 S->getDecl());
5947 if (!LD)
5948 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005949
5950
Douglas Gregorebe10102009-08-20 07:17:43 +00005951 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005952 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005953 cast<LabelDecl>(LD), SourceLocation(),
5954 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005955}
Mike Stump11289f42009-09-09 15:08:12 +00005956
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005957template <typename Derived>
5958const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
5959 if (!R)
5960 return R;
5961
5962 switch (R->getKind()) {
5963// Transform attributes with a pragma spelling by calling TransformXXXAttr.
5964#define ATTR(X)
5965#define PRAGMA_SPELLING_ATTR(X) \
5966 case attr::X: \
5967 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
5968#include "clang/Basic/AttrList.inc"
5969 default:
5970 return R;
5971 }
5972}
5973
5974template <typename Derived>
5975StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5976 bool AttrsChanged = false;
5977 SmallVector<const Attr *, 1> Attrs;
5978
5979 // Visit attributes and keep track if any are transformed.
5980 for (const auto *I : S->getAttrs()) {
5981 const Attr *R = getDerived().TransformAttr(I);
5982 AttrsChanged |= (I != R);
5983 Attrs.push_back(R);
5984 }
5985
Richard Smithc202b282012-04-14 00:33:13 +00005986 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5987 if (SubStmt.isInvalid())
5988 return StmtError();
5989
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005990 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00005991 return S;
5992
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005993 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00005994 SubStmt.get());
5995}
5996
5997template<typename Derived>
5998StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005999TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006000 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006001 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006002 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00006003 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006004 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00006005 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006006 getDerived().TransformDefinition(
6007 S->getConditionVariable()->getLocation(),
6008 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00006009 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006010 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006011 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00006012 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006013
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006014 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006015 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006016
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006017 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00006018 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006019 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006020 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006021 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006022 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006023
John McCallb268a282010-08-23 23:25:46 +00006024 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006025 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006026 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006027
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006028 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006029 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006030 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006031
Douglas Gregorebe10102009-08-20 07:17:43 +00006032 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00006033 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00006034 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006035 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006036
Douglas Gregorebe10102009-08-20 07:17:43 +00006037 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00006038 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00006039 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006040 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006041
Douglas Gregorebe10102009-08-20 07:17:43 +00006042 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006043 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006044 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006045 Then.get() == S->getThen() &&
6046 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006047 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006048
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006049 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00006050 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00006051 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006052}
6053
6054template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006055StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006056TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006057 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00006058 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006059 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00006060 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006061 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00006062 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006063 getDerived().TransformDefinition(
6064 S->getConditionVariable()->getLocation(),
6065 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00006066 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006067 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006068 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00006069 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006070
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006071 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006072 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006073 }
Mike Stump11289f42009-09-09 15:08:12 +00006074
Douglas Gregorebe10102009-08-20 07:17:43 +00006075 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006076 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00006077 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00006078 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00006079 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006080 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006081
Douglas Gregorebe10102009-08-20 07:17:43 +00006082 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006083 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006084 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006085 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006086
Douglas Gregorebe10102009-08-20 07:17:43 +00006087 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006088 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6089 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006090}
Mike Stump11289f42009-09-09 15:08:12 +00006091
Douglas Gregorebe10102009-08-20 07:17:43 +00006092template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006093StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006094TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006095 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006096 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006097 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00006098 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006099 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00006100 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006101 getDerived().TransformDefinition(
6102 S->getConditionVariable()->getLocation(),
6103 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00006104 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006105 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006106 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00006107 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006108
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006109 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006110 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006111
6112 if (S->getCond()) {
6113 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006114 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6115 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006116 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006117 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006118 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00006119 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00006120 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006121 }
Mike Stump11289f42009-09-09 15:08:12 +00006122
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006123 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006124 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006125 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006126
Douglas Gregorebe10102009-08-20 07:17:43 +00006127 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006128 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006129 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006130 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006131
Douglas Gregorebe10102009-08-20 07:17:43 +00006132 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006133 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006134 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006135 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006136 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006137
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006138 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00006139 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006140}
Mike Stump11289f42009-09-09 15:08:12 +00006141
Douglas Gregorebe10102009-08-20 07:17:43 +00006142template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006143StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006144TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006145 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006146 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006147 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006148 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006149
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006150 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006151 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006152 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006153 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006154
Douglas Gregorebe10102009-08-20 07:17:43 +00006155 if (!getDerived().AlwaysRebuild() &&
6156 Cond.get() == S->getCond() &&
6157 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006158 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006159
John McCallb268a282010-08-23 23:25:46 +00006160 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6161 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006162 S->getRParenLoc());
6163}
Mike Stump11289f42009-09-09 15:08:12 +00006164
Douglas Gregorebe10102009-08-20 07:17:43 +00006165template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006166StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006167TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006168 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006169 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006170 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006171 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006172
Douglas Gregorebe10102009-08-20 07:17:43 +00006173 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006174 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006175 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006176 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006177 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006178 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006179 getDerived().TransformDefinition(
6180 S->getConditionVariable()->getLocation(),
6181 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006182 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006183 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006184 } else {
6185 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006186
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006187 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006188 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006189
6190 if (S->getCond()) {
6191 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006192 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6193 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006194 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006195 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006196 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006197
John McCallb268a282010-08-23 23:25:46 +00006198 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006199 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006200 }
Mike Stump11289f42009-09-09 15:08:12 +00006201
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006202 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006203 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006204 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006205
Douglas Gregorebe10102009-08-20 07:17:43 +00006206 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006207 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006208 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006209 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006210
Richard Smith945f8d32013-01-14 22:39:08 +00006211 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006212 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006213 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006214
Douglas Gregorebe10102009-08-20 07:17:43 +00006215 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006216 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006217 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006218 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006219
Douglas Gregorebe10102009-08-20 07:17:43 +00006220 if (!getDerived().AlwaysRebuild() &&
6221 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00006222 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006223 Inc.get() == S->getInc() &&
6224 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006225 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006226
Douglas Gregorebe10102009-08-20 07:17:43 +00006227 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006228 Init.get(), FullCond, ConditionVar,
6229 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006230}
6231
6232template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006233StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006234TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006235 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6236 S->getLabel());
6237 if (!LD)
6238 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006239
Douglas Gregorebe10102009-08-20 07:17:43 +00006240 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006241 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006242 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006243}
6244
6245template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006246StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006247TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006248 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006249 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006250 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006251 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006252
Douglas Gregorebe10102009-08-20 07:17:43 +00006253 if (!getDerived().AlwaysRebuild() &&
6254 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006255 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006256
6257 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006258 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006259}
6260
6261template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006262StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006263TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006264 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006265}
Mike Stump11289f42009-09-09 15:08:12 +00006266
Douglas Gregorebe10102009-08-20 07:17:43 +00006267template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006268StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006269TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006270 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006271}
Mike Stump11289f42009-09-09 15:08:12 +00006272
Douglas Gregorebe10102009-08-20 07:17:43 +00006273template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006274StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006275TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006276 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6277 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006278 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006279 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006280
Mike Stump11289f42009-09-09 15:08:12 +00006281 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006282 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006283 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006284}
Mike Stump11289f42009-09-09 15:08:12 +00006285
Douglas Gregorebe10102009-08-20 07:17:43 +00006286template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006287StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006288TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006289 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006290 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006291 for (auto *D : S->decls()) {
6292 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006293 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006294 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006295
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006296 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006297 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006298
Douglas Gregorebe10102009-08-20 07:17:43 +00006299 Decls.push_back(Transformed);
6300 }
Mike Stump11289f42009-09-09 15:08:12 +00006301
Douglas Gregorebe10102009-08-20 07:17:43 +00006302 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006303 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006304
Rafael Espindolaab417692013-07-09 12:05:01 +00006305 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006306}
Mike Stump11289f42009-09-09 15:08:12 +00006307
Douglas Gregorebe10102009-08-20 07:17:43 +00006308template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006309StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006310TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006311
Benjamin Kramerf0623432012-08-23 22:51:59 +00006312 SmallVector<Expr*, 8> Constraints;
6313 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006314 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006315
John McCalldadc5752010-08-24 06:29:42 +00006316 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006317 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006318
6319 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006320
Anders Carlssonaaeef072010-01-24 05:50:09 +00006321 // Go through the outputs.
6322 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006323 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006324
Anders Carlssonaaeef072010-01-24 05:50:09 +00006325 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006326 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006327
Anders Carlssonaaeef072010-01-24 05:50:09 +00006328 // Transform the output expr.
6329 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006330 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006331 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006332 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006333
Anders Carlssonaaeef072010-01-24 05:50:09 +00006334 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006335
John McCallb268a282010-08-23 23:25:46 +00006336 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006337 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006338
Anders Carlssonaaeef072010-01-24 05:50:09 +00006339 // Go through the inputs.
6340 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006341 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006342
Anders Carlssonaaeef072010-01-24 05:50:09 +00006343 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006344 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006345
Anders Carlssonaaeef072010-01-24 05:50:09 +00006346 // Transform the input expr.
6347 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006348 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006349 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006350 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006351
Anders Carlssonaaeef072010-01-24 05:50:09 +00006352 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006353
John McCallb268a282010-08-23 23:25:46 +00006354 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006355 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006356
Anders Carlssonaaeef072010-01-24 05:50:09 +00006357 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006358 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006359
6360 // Go through the clobbers.
6361 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006362 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006363
6364 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006365 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006366 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6367 S->isVolatile(), S->getNumOutputs(),
6368 S->getNumInputs(), Names.data(),
6369 Constraints, Exprs, AsmString.get(),
6370 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006371}
6372
Chad Rosier32503022012-06-11 20:47:18 +00006373template<typename Derived>
6374StmtResult
6375TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006376 ArrayRef<Token> AsmToks =
6377 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006378
John McCallf413f5e2013-05-03 00:10:13 +00006379 bool HadError = false, HadChange = false;
6380
6381 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6382 SmallVector<Expr*, 8> TransformedExprs;
6383 TransformedExprs.reserve(SrcExprs.size());
6384 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6385 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6386 if (!Result.isUsable()) {
6387 HadError = true;
6388 } else {
6389 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006390 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006391 }
6392 }
6393
6394 if (HadError) return StmtError();
6395 if (!HadChange && !getDerived().AlwaysRebuild())
6396 return Owned(S);
6397
Chad Rosierb6f46c12012-08-15 16:53:30 +00006398 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006399 AsmToks, S->getAsmString(),
6400 S->getNumOutputs(), S->getNumInputs(),
6401 S->getAllConstraints(), S->getClobbers(),
6402 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006403}
Douglas Gregorebe10102009-08-20 07:17:43 +00006404
6405template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006406StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006407TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006408 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006409 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006410 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006411 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006412
Douglas Gregor96c79492010-04-23 22:50:49 +00006413 // Transform the @catch statements (if present).
6414 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006415 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006416 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006417 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006418 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006419 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006420 if (Catch.get() != S->getCatchStmt(I))
6421 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006422 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006423 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006424
Douglas Gregor306de2f2010-04-22 23:59:56 +00006425 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006426 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006427 if (S->getFinallyStmt()) {
6428 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6429 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006430 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006431 }
6432
6433 // If nothing changed, just retain this statement.
6434 if (!getDerived().AlwaysRebuild() &&
6435 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006436 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006437 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006438 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006439
Douglas Gregor306de2f2010-04-22 23:59:56 +00006440 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006441 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006442 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006443}
Mike Stump11289f42009-09-09 15:08:12 +00006444
Douglas Gregorebe10102009-08-20 07:17:43 +00006445template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006446StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006447TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006448 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006449 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006450 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006451 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006452 if (FromVar->getTypeSourceInfo()) {
6453 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6454 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006455 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006456 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006457
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006458 QualType T;
6459 if (TSInfo)
6460 T = TSInfo->getType();
6461 else {
6462 T = getDerived().TransformType(FromVar->getType());
6463 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006464 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006465 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006466
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006467 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6468 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006469 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006470 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006471
John McCalldadc5752010-08-24 06:29:42 +00006472 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006473 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006474 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006475
6476 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006477 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006478 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006479}
Mike Stump11289f42009-09-09 15:08:12 +00006480
Douglas Gregorebe10102009-08-20 07:17:43 +00006481template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006482StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006483TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006484 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006485 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006486 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006487 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006488
Douglas Gregor306de2f2010-04-22 23:59:56 +00006489 // If nothing changed, just retain this statement.
6490 if (!getDerived().AlwaysRebuild() &&
6491 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006492 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006493
6494 // Build a new statement.
6495 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006496 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006497}
Mike Stump11289f42009-09-09 15:08:12 +00006498
Douglas Gregorebe10102009-08-20 07:17:43 +00006499template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006500StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006501TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006502 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006503 if (S->getThrowExpr()) {
6504 Operand = getDerived().TransformExpr(S->getThrowExpr());
6505 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006506 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006507 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006508
Douglas Gregor2900c162010-04-22 21:44:01 +00006509 if (!getDerived().AlwaysRebuild() &&
6510 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006511 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006512
John McCallb268a282010-08-23 23:25:46 +00006513 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006514}
Mike Stump11289f42009-09-09 15:08:12 +00006515
Douglas Gregorebe10102009-08-20 07:17:43 +00006516template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006517StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006518TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006519 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006520 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006521 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006522 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006523 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006524 Object =
6525 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6526 Object.get());
6527 if (Object.isInvalid())
6528 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006529
Douglas Gregor6148de72010-04-22 22:01:21 +00006530 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006531 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006532 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006533 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006534
Douglas Gregor6148de72010-04-22 22:01:21 +00006535 // If nothing change, just retain the current statement.
6536 if (!getDerived().AlwaysRebuild() &&
6537 Object.get() == S->getSynchExpr() &&
6538 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006539 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006540
6541 // Build a new statement.
6542 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006543 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006544}
6545
6546template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006547StmtResult
John McCall31168b02011-06-15 23:02:42 +00006548TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6549 ObjCAutoreleasePoolStmt *S) {
6550 // Transform the body.
6551 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6552 if (Body.isInvalid())
6553 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006554
John McCall31168b02011-06-15 23:02:42 +00006555 // If nothing changed, just retain this statement.
6556 if (!getDerived().AlwaysRebuild() &&
6557 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006558 return S;
John McCall31168b02011-06-15 23:02:42 +00006559
6560 // Build a new statement.
6561 return getDerived().RebuildObjCAutoreleasePoolStmt(
6562 S->getAtLoc(), Body.get());
6563}
6564
6565template<typename Derived>
6566StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006567TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006568 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006569 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006570 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006571 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006572 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006573
Douglas Gregorf68a5082010-04-22 23:10:45 +00006574 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006575 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006576 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006577 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006578
Douglas Gregorf68a5082010-04-22 23:10:45 +00006579 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006580 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006581 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006582 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006583
Douglas Gregorf68a5082010-04-22 23:10:45 +00006584 // If nothing changed, just retain this statement.
6585 if (!getDerived().AlwaysRebuild() &&
6586 Element.get() == S->getElement() &&
6587 Collection.get() == S->getCollection() &&
6588 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006589 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006590
Douglas Gregorf68a5082010-04-22 23:10:45 +00006591 // Build a new statement.
6592 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006593 Element.get(),
6594 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006595 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006596 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006597}
6598
David Majnemer5f7efef2013-10-15 09:50:08 +00006599template <typename Derived>
6600StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006601 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006602 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006603 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6604 TypeSourceInfo *T =
6605 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006606 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006607 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006608
David Majnemer5f7efef2013-10-15 09:50:08 +00006609 Var = getDerived().RebuildExceptionDecl(
6610 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6611 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006612 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006613 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006614 }
Mike Stump11289f42009-09-09 15:08:12 +00006615
Douglas Gregorebe10102009-08-20 07:17:43 +00006616 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006617 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006618 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006619 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006620
David Majnemer5f7efef2013-10-15 09:50:08 +00006621 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006622 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006623 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006624
David Majnemer5f7efef2013-10-15 09:50:08 +00006625 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006626}
Mike Stump11289f42009-09-09 15:08:12 +00006627
David Majnemer5f7efef2013-10-15 09:50:08 +00006628template <typename Derived>
6629StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006630 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006631 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006632 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006633 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006634
Douglas Gregorebe10102009-08-20 07:17:43 +00006635 // Transform the handlers.
6636 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006637 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006638 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006639 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006640 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006641 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006642
Douglas Gregorebe10102009-08-20 07:17:43 +00006643 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006644 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006645 }
Mike Stump11289f42009-09-09 15:08:12 +00006646
David Majnemer5f7efef2013-10-15 09:50:08 +00006647 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006648 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006649 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006650
John McCallb268a282010-08-23 23:25:46 +00006651 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006652 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006653}
Mike Stump11289f42009-09-09 15:08:12 +00006654
Richard Smith02e85f32011-04-14 22:09:26 +00006655template<typename Derived>
6656StmtResult
6657TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6658 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6659 if (Range.isInvalid())
6660 return StmtError();
6661
6662 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6663 if (BeginEnd.isInvalid())
6664 return StmtError();
6665
6666 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6667 if (Cond.isInvalid())
6668 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006669 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006670 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006671 if (Cond.isInvalid())
6672 return StmtError();
6673 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006674 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006675
6676 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6677 if (Inc.isInvalid())
6678 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006679 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006680 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006681
6682 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6683 if (LoopVar.isInvalid())
6684 return StmtError();
6685
6686 StmtResult NewStmt = S;
6687 if (getDerived().AlwaysRebuild() ||
6688 Range.get() != S->getRangeStmt() ||
6689 BeginEnd.get() != S->getBeginEndStmt() ||
6690 Cond.get() != S->getCond() ||
6691 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006692 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006693 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6694 S->getColonLoc(), Range.get(),
6695 BeginEnd.get(), Cond.get(),
6696 Inc.get(), LoopVar.get(),
6697 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006698 if (NewStmt.isInvalid())
6699 return StmtError();
6700 }
Richard Smith02e85f32011-04-14 22:09:26 +00006701
6702 StmtResult Body = getDerived().TransformStmt(S->getBody());
6703 if (Body.isInvalid())
6704 return StmtError();
6705
6706 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6707 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006708 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006709 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6710 S->getColonLoc(), Range.get(),
6711 BeginEnd.get(), Cond.get(),
6712 Inc.get(), LoopVar.get(),
6713 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006714 if (NewStmt.isInvalid())
6715 return StmtError();
6716 }
Richard Smith02e85f32011-04-14 22:09:26 +00006717
6718 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006719 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006720
6721 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6722}
6723
John Wiegley1c0675e2011-04-28 01:08:34 +00006724template<typename Derived>
6725StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006726TreeTransform<Derived>::TransformMSDependentExistsStmt(
6727 MSDependentExistsStmt *S) {
6728 // Transform the nested-name-specifier, if any.
6729 NestedNameSpecifierLoc QualifierLoc;
6730 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006731 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006732 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6733 if (!QualifierLoc)
6734 return StmtError();
6735 }
6736
6737 // Transform the declaration name.
6738 DeclarationNameInfo NameInfo = S->getNameInfo();
6739 if (NameInfo.getName()) {
6740 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6741 if (!NameInfo.getName())
6742 return StmtError();
6743 }
6744
6745 // Check whether anything changed.
6746 if (!getDerived().AlwaysRebuild() &&
6747 QualifierLoc == S->getQualifierLoc() &&
6748 NameInfo.getName() == S->getNameInfo().getName())
6749 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006750
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006751 // Determine whether this name exists, if we can.
6752 CXXScopeSpec SS;
6753 SS.Adopt(QualifierLoc);
6754 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006755 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006756 case Sema::IER_Exists:
6757 if (S->isIfExists())
6758 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006759
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006760 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6761
6762 case Sema::IER_DoesNotExist:
6763 if (S->isIfNotExists())
6764 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006765
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006766 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006767
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006768 case Sema::IER_Dependent:
6769 Dependent = true;
6770 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006771
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006772 case Sema::IER_Error:
6773 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006774 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006775
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006776 // We need to continue with the instantiation, so do so now.
6777 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6778 if (SubStmt.isInvalid())
6779 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006780
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006781 // If we have resolved the name, just transform to the substatement.
6782 if (!Dependent)
6783 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006784
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006785 // The name is still dependent, so build a dependent expression again.
6786 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6787 S->isIfExists(),
6788 QualifierLoc,
6789 NameInfo,
6790 SubStmt.get());
6791}
6792
6793template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006794ExprResult
6795TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6796 NestedNameSpecifierLoc QualifierLoc;
6797 if (E->getQualifierLoc()) {
6798 QualifierLoc
6799 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6800 if (!QualifierLoc)
6801 return ExprError();
6802 }
6803
6804 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6805 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6806 if (!PD)
6807 return ExprError();
6808
6809 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6810 if (Base.isInvalid())
6811 return ExprError();
6812
6813 return new (SemaRef.getASTContext())
6814 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6815 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6816 QualifierLoc, E->getMemberLoc());
6817}
6818
David Majnemerfad8f482013-10-15 09:33:02 +00006819template <typename Derived>
6820StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006821 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006822 if (TryBlock.isInvalid())
6823 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006824
6825 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006826 if (Handler.isInvalid())
6827 return StmtError();
6828
David Majnemerfad8f482013-10-15 09:33:02 +00006829 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6830 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006831 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006832
Warren Huntf6be4cb2014-07-25 20:52:51 +00006833 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6834 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006835}
6836
David Majnemerfad8f482013-10-15 09:33:02 +00006837template <typename Derived>
6838StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006839 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006840 if (Block.isInvalid())
6841 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006842
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006843 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006844}
6845
David Majnemerfad8f482013-10-15 09:33:02 +00006846template <typename Derived>
6847StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006848 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006849 if (FilterExpr.isInvalid())
6850 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006851
David Majnemer7e755502013-10-15 09:30:14 +00006852 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006853 if (Block.isInvalid())
6854 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006855
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006856 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6857 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006858}
6859
David Majnemerfad8f482013-10-15 09:33:02 +00006860template <typename Derived>
6861StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6862 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006863 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6864 else
6865 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6866}
6867
Nico Weber9b982072014-07-07 00:12:30 +00006868template<typename Derived>
6869StmtResult
6870TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6871 return S;
6872}
6873
Alexander Musman64d33f12014-06-04 07:53:32 +00006874//===----------------------------------------------------------------------===//
6875// OpenMP directive transformation
6876//===----------------------------------------------------------------------===//
6877template <typename Derived>
6878StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6879 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006880
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006881 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006882 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006883 ArrayRef<OMPClause *> Clauses = D->clauses();
6884 TClauses.reserve(Clauses.size());
6885 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6886 I != E; ++I) {
6887 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00006888 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006889 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00006890 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00006891 if (Clause)
6892 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006893 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006894 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006895 }
6896 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006897 StmtResult AssociatedStmt;
6898 if (D->hasAssociatedStmt()) {
6899 if (!D->getAssociatedStmt()) {
6900 return StmtError();
6901 }
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00006902 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
6903 /*CurScope=*/nullptr);
6904 StmtResult Body;
6905 {
6906 Sema::CompoundScopeRAII CompoundScope(getSema());
6907 Body = getDerived().TransformStmt(
6908 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
6909 }
6910 AssociatedStmt =
6911 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00006912 if (AssociatedStmt.isInvalid()) {
6913 return StmtError();
6914 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006915 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006916 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006917 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006918 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006919
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006920 // Transform directive name for 'omp critical' directive.
6921 DeclarationNameInfo DirName;
6922 if (D->getDirectiveKind() == OMPD_critical) {
6923 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6924 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6925 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006926 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
6927 if (D->getDirectiveKind() == OMPD_cancellation_point) {
6928 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00006929 } else if (D->getDirectiveKind() == OMPD_cancel) {
6930 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006931 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006932
Alexander Musman64d33f12014-06-04 07:53:32 +00006933 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006934 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
6935 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006936}
6937
Alexander Musman64d33f12014-06-04 07:53:32 +00006938template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006939StmtResult
6940TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6941 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006942 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6943 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006944 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6945 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6946 return Res;
6947}
6948
Alexander Musman64d33f12014-06-04 07:53:32 +00006949template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006950StmtResult
6951TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6952 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006953 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6954 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006955 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6956 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006957 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006958}
6959
Alexey Bataevf29276e2014-06-18 04:14:57 +00006960template <typename Derived>
6961StmtResult
6962TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6963 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006964 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6965 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006966 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6967 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6968 return Res;
6969}
6970
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006971template <typename Derived>
6972StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00006973TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
6974 DeclarationNameInfo DirName;
6975 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
6976 D->getLocStart());
6977 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6978 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6979 return Res;
6980}
6981
6982template <typename Derived>
6983StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006984TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6985 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006986 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6987 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006988 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6989 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6990 return Res;
6991}
6992
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006993template <typename Derived>
6994StmtResult
6995TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6996 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006997 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6998 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006999 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7000 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7001 return Res;
7002}
7003
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007004template <typename Derived>
7005StmtResult
7006TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7007 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007008 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7009 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007010 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7011 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7012 return Res;
7013}
7014
Alexey Bataev4acb8592014-07-07 13:01:15 +00007015template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007016StmtResult
7017TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7018 DeclarationNameInfo DirName;
7019 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7020 D->getLocStart());
7021 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7022 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7023 return Res;
7024}
7025
7026template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007027StmtResult
7028TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7029 getDerived().getSema().StartOpenMPDSABlock(
7030 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7031 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7032 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7033 return Res;
7034}
7035
7036template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007037StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7038 OMPParallelForDirective *D) {
7039 DeclarationNameInfo DirName;
7040 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7041 nullptr, D->getLocStart());
7042 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7043 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7044 return Res;
7045}
7046
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007047template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007048StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7049 OMPParallelForSimdDirective *D) {
7050 DeclarationNameInfo DirName;
7051 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7052 nullptr, D->getLocStart());
7053 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7054 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7055 return Res;
7056}
7057
7058template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007059StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7060 OMPParallelSectionsDirective *D) {
7061 DeclarationNameInfo DirName;
7062 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7063 nullptr, D->getLocStart());
7064 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7065 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7066 return Res;
7067}
7068
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007069template <typename Derived>
7070StmtResult
7071TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7072 DeclarationNameInfo DirName;
7073 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7074 D->getLocStart());
7075 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7076 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7077 return Res;
7078}
7079
Alexey Bataev68446b72014-07-18 07:47:19 +00007080template <typename Derived>
7081StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7082 OMPTaskyieldDirective *D) {
7083 DeclarationNameInfo DirName;
7084 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7085 D->getLocStart());
7086 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7087 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7088 return Res;
7089}
7090
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007091template <typename Derived>
7092StmtResult
7093TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7094 DeclarationNameInfo DirName;
7095 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7096 D->getLocStart());
7097 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7098 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7099 return Res;
7100}
7101
Alexey Bataev2df347a2014-07-18 10:17:07 +00007102template <typename Derived>
7103StmtResult
7104TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7105 DeclarationNameInfo DirName;
7106 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7107 D->getLocStart());
7108 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7109 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7110 return Res;
7111}
7112
Alexey Bataev6125da92014-07-21 11:26:11 +00007113template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007114StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7115 OMPTaskgroupDirective *D) {
7116 DeclarationNameInfo DirName;
7117 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7118 D->getLocStart());
7119 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7120 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7121 return Res;
7122}
7123
7124template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007125StmtResult
7126TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7127 DeclarationNameInfo DirName;
7128 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7129 D->getLocStart());
7130 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7131 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7132 return Res;
7133}
7134
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007135template <typename Derived>
7136StmtResult
7137TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7138 DeclarationNameInfo DirName;
7139 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7140 D->getLocStart());
7141 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7142 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7143 return Res;
7144}
7145
Alexey Bataev0162e452014-07-22 10:10:35 +00007146template <typename Derived>
7147StmtResult
7148TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7149 DeclarationNameInfo DirName;
7150 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7151 D->getLocStart());
7152 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7153 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7154 return Res;
7155}
7156
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007157template <typename Derived>
7158StmtResult
7159TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7160 DeclarationNameInfo DirName;
7161 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7162 D->getLocStart());
7163 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7164 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7165 return Res;
7166}
7167
Alexey Bataev13314bf2014-10-09 04:18:56 +00007168template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007169StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7170 OMPTargetDataDirective *D) {
7171 DeclarationNameInfo DirName;
7172 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7173 D->getLocStart());
7174 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7175 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7176 return Res;
7177}
7178
7179template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007180StmtResult
7181TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7182 DeclarationNameInfo DirName;
7183 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7184 D->getLocStart());
7185 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7186 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7187 return Res;
7188}
7189
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007190template <typename Derived>
7191StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7192 OMPCancellationPointDirective *D) {
7193 DeclarationNameInfo DirName;
7194 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7195 nullptr, D->getLocStart());
7196 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7197 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7198 return Res;
7199}
7200
Alexey Bataev80909872015-07-02 11:25:17 +00007201template <typename Derived>
7202StmtResult
7203TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7204 DeclarationNameInfo DirName;
7205 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7206 D->getLocStart());
7207 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7208 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7209 return Res;
7210}
7211
Alexander Musman64d33f12014-06-04 07:53:32 +00007212//===----------------------------------------------------------------------===//
7213// OpenMP clause transformation
7214//===----------------------------------------------------------------------===//
7215template <typename Derived>
7216OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007217 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7218 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007219 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007220 return getDerived().RebuildOMPIfClause(
7221 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7222 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007223}
7224
Alexander Musman64d33f12014-06-04 07:53:32 +00007225template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007226OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7227 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7228 if (Cond.isInvalid())
7229 return nullptr;
7230 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7231 C->getLParenLoc(), C->getLocEnd());
7232}
7233
7234template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007235OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007236TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7237 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7238 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007239 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007240 return getDerived().RebuildOMPNumThreadsClause(
7241 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007242}
7243
Alexey Bataev62c87d22014-03-21 04:51:18 +00007244template <typename Derived>
7245OMPClause *
7246TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7247 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7248 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007249 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007250 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007251 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007252}
7253
Alexander Musman8bd31e62014-05-27 15:12:19 +00007254template <typename Derived>
7255OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007256TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7257 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7258 if (E.isInvalid())
7259 return nullptr;
7260 return getDerived().RebuildOMPSimdlenClause(
7261 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7262}
7263
7264template <typename Derived>
7265OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007266TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7267 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7268 if (E.isInvalid())
7269 return 0;
7270 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007271 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007272}
7273
Alexander Musman64d33f12014-06-04 07:53:32 +00007274template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007275OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007276TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007277 return getDerived().RebuildOMPDefaultClause(
7278 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7279 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007280}
7281
Alexander Musman64d33f12014-06-04 07:53:32 +00007282template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007283OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007284TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007285 return getDerived().RebuildOMPProcBindClause(
7286 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7287 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007288}
7289
Alexander Musman64d33f12014-06-04 07:53:32 +00007290template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007291OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007292TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7293 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7294 if (E.isInvalid())
7295 return nullptr;
7296 return getDerived().RebuildOMPScheduleClause(
7297 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7298 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7299}
7300
7301template <typename Derived>
7302OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007303TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007304 ExprResult E;
7305 if (auto *Num = C->getNumForLoops()) {
7306 E = getDerived().TransformExpr(Num);
7307 if (E.isInvalid())
7308 return nullptr;
7309 }
7310 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7311 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007312}
7313
7314template <typename Derived>
7315OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007316TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7317 // No need to rebuild this clause, no template-dependent parameters.
7318 return C;
7319}
7320
7321template <typename Derived>
7322OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007323TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7324 // No need to rebuild this clause, no template-dependent parameters.
7325 return C;
7326}
7327
7328template <typename Derived>
7329OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007330TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7331 // No need to rebuild this clause, no template-dependent parameters.
7332 return C;
7333}
7334
7335template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007336OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7337 // No need to rebuild this clause, no template-dependent parameters.
7338 return C;
7339}
7340
7341template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007342OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7343 // No need to rebuild this clause, no template-dependent parameters.
7344 return C;
7345}
7346
7347template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007348OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007349TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7350 // No need to rebuild this clause, no template-dependent parameters.
7351 return C;
7352}
7353
7354template <typename Derived>
7355OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007356TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7357 // No need to rebuild this clause, no template-dependent parameters.
7358 return C;
7359}
7360
7361template <typename Derived>
7362OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007363TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7364 // No need to rebuild this clause, no template-dependent parameters.
7365 return C;
7366}
7367
7368template <typename Derived>
7369OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007370TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7371 // No need to rebuild this clause, no template-dependent parameters.
7372 return C;
7373}
7374
7375template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007376OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7377 // No need to rebuild this clause, no template-dependent parameters.
7378 return C;
7379}
7380
7381template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007382OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007383TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007384 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007385 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007386 for (auto *VE : C->varlists()) {
7387 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007388 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007389 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007390 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007391 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007392 return getDerived().RebuildOMPPrivateClause(
7393 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007394}
7395
Alexander Musman64d33f12014-06-04 07:53:32 +00007396template <typename Derived>
7397OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7398 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007399 llvm::SmallVector<Expr *, 16> Vars;
7400 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007401 for (auto *VE : C->varlists()) {
7402 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007403 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007404 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007405 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007406 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007407 return getDerived().RebuildOMPFirstprivateClause(
7408 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007409}
7410
Alexander Musman64d33f12014-06-04 07:53:32 +00007411template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007412OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007413TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7414 llvm::SmallVector<Expr *, 16> Vars;
7415 Vars.reserve(C->varlist_size());
7416 for (auto *VE : C->varlists()) {
7417 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7418 if (EVar.isInvalid())
7419 return nullptr;
7420 Vars.push_back(EVar.get());
7421 }
7422 return getDerived().RebuildOMPLastprivateClause(
7423 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7424}
7425
7426template <typename Derived>
7427OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007428TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7429 llvm::SmallVector<Expr *, 16> Vars;
7430 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007431 for (auto *VE : C->varlists()) {
7432 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007433 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007434 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007435 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007436 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007437 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7438 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007439}
7440
Alexander Musman64d33f12014-06-04 07:53:32 +00007441template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007442OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007443TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7444 llvm::SmallVector<Expr *, 16> Vars;
7445 Vars.reserve(C->varlist_size());
7446 for (auto *VE : C->varlists()) {
7447 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7448 if (EVar.isInvalid())
7449 return nullptr;
7450 Vars.push_back(EVar.get());
7451 }
7452 CXXScopeSpec ReductionIdScopeSpec;
7453 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7454
7455 DeclarationNameInfo NameInfo = C->getNameInfo();
7456 if (NameInfo.getName()) {
7457 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7458 if (!NameInfo.getName())
7459 return nullptr;
7460 }
7461 return getDerived().RebuildOMPReductionClause(
7462 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7463 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7464}
7465
7466template <typename Derived>
7467OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007468TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7469 llvm::SmallVector<Expr *, 16> Vars;
7470 Vars.reserve(C->varlist_size());
7471 for (auto *VE : C->varlists()) {
7472 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7473 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007474 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007475 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007476 }
7477 ExprResult Step = getDerived().TransformExpr(C->getStep());
7478 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007479 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007480 return getDerived().RebuildOMPLinearClause(
7481 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7482 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007483}
7484
Alexander Musman64d33f12014-06-04 07:53:32 +00007485template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007486OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007487TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7488 llvm::SmallVector<Expr *, 16> Vars;
7489 Vars.reserve(C->varlist_size());
7490 for (auto *VE : C->varlists()) {
7491 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7492 if (EVar.isInvalid())
7493 return nullptr;
7494 Vars.push_back(EVar.get());
7495 }
7496 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7497 if (Alignment.isInvalid())
7498 return nullptr;
7499 return getDerived().RebuildOMPAlignedClause(
7500 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7501 C->getColonLoc(), C->getLocEnd());
7502}
7503
Alexander Musman64d33f12014-06-04 07:53:32 +00007504template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007505OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007506TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7507 llvm::SmallVector<Expr *, 16> Vars;
7508 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007509 for (auto *VE : C->varlists()) {
7510 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007511 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007512 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007513 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007514 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007515 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7516 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007517}
7518
Alexey Bataevbae9a792014-06-27 10:37:06 +00007519template <typename Derived>
7520OMPClause *
7521TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7522 llvm::SmallVector<Expr *, 16> Vars;
7523 Vars.reserve(C->varlist_size());
7524 for (auto *VE : C->varlists()) {
7525 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7526 if (EVar.isInvalid())
7527 return nullptr;
7528 Vars.push_back(EVar.get());
7529 }
7530 return getDerived().RebuildOMPCopyprivateClause(
7531 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7532}
7533
Alexey Bataev6125da92014-07-21 11:26:11 +00007534template <typename Derived>
7535OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7536 llvm::SmallVector<Expr *, 16> Vars;
7537 Vars.reserve(C->varlist_size());
7538 for (auto *VE : C->varlists()) {
7539 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7540 if (EVar.isInvalid())
7541 return nullptr;
7542 Vars.push_back(EVar.get());
7543 }
7544 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7545 C->getLParenLoc(), C->getLocEnd());
7546}
7547
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007548template <typename Derived>
7549OMPClause *
7550TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7551 llvm::SmallVector<Expr *, 16> Vars;
7552 Vars.reserve(C->varlist_size());
7553 for (auto *VE : C->varlists()) {
7554 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7555 if (EVar.isInvalid())
7556 return nullptr;
7557 Vars.push_back(EVar.get());
7558 }
7559 return getDerived().RebuildOMPDependClause(
7560 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7561 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7562}
7563
Michael Wonge710d542015-08-07 16:16:36 +00007564template <typename Derived>
7565OMPClause *
7566TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7567 ExprResult E = getDerived().TransformExpr(C->getDevice());
7568 if (E.isInvalid())
7569 return nullptr;
7570 return getDerived().RebuildOMPDeviceClause(
7571 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7572}
7573
Douglas Gregorebe10102009-08-20 07:17:43 +00007574//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007575// Expression transformation
7576//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007577template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007578ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007579TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007580 if (!E->isTypeDependent())
7581 return E;
7582
7583 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7584 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007585}
Mike Stump11289f42009-09-09 15:08:12 +00007586
7587template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007588ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007589TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007590 NestedNameSpecifierLoc QualifierLoc;
7591 if (E->getQualifierLoc()) {
7592 QualifierLoc
7593 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7594 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007595 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007596 }
John McCallce546572009-12-08 09:08:17 +00007597
7598 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007599 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7600 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007601 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007602 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007603
John McCall815039a2010-08-17 21:27:17 +00007604 DeclarationNameInfo NameInfo = E->getNameInfo();
7605 if (NameInfo.getName()) {
7606 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7607 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007608 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007609 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007610
7611 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007612 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007613 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007614 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007615 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007616
7617 // Mark it referenced in the new context regardless.
7618 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007619 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007620
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007621 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007622 }
John McCallce546572009-12-08 09:08:17 +00007623
Craig Topperc3ec1492014-05-26 06:22:03 +00007624 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007625 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007626 TemplateArgs = &TransArgs;
7627 TransArgs.setLAngleLoc(E->getLAngleLoc());
7628 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007629 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7630 E->getNumTemplateArgs(),
7631 TransArgs))
7632 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007633 }
7634
Chad Rosier1dcde962012-08-08 18:46:20 +00007635 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007636 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007637}
Mike Stump11289f42009-09-09 15:08:12 +00007638
Douglas Gregora16548e2009-08-11 05:31:07 +00007639template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007640ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007641TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007642 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007643}
Mike Stump11289f42009-09-09 15:08:12 +00007644
Douglas Gregora16548e2009-08-11 05:31:07 +00007645template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007646ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007647TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007648 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007649}
Mike Stump11289f42009-09-09 15:08:12 +00007650
Douglas Gregora16548e2009-08-11 05:31:07 +00007651template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007652ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007653TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007654 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007655}
Mike Stump11289f42009-09-09 15:08:12 +00007656
Douglas Gregora16548e2009-08-11 05:31:07 +00007657template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007658ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007659TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007660 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007661}
Mike Stump11289f42009-09-09 15:08:12 +00007662
Douglas Gregora16548e2009-08-11 05:31:07 +00007663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007664ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007665TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007666 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007667}
7668
7669template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007670ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007671TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007672 if (FunctionDecl *FD = E->getDirectCallee())
7673 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007674 return SemaRef.MaybeBindToTemporary(E);
7675}
7676
7677template<typename Derived>
7678ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007679TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7680 ExprResult ControllingExpr =
7681 getDerived().TransformExpr(E->getControllingExpr());
7682 if (ControllingExpr.isInvalid())
7683 return ExprError();
7684
Chris Lattner01cf8db2011-07-20 06:58:45 +00007685 SmallVector<Expr *, 4> AssocExprs;
7686 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007687 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7688 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7689 if (TS) {
7690 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7691 if (!AssocType)
7692 return ExprError();
7693 AssocTypes.push_back(AssocType);
7694 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007695 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007696 }
7697
7698 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7699 if (AssocExpr.isInvalid())
7700 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007701 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007702 }
7703
7704 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7705 E->getDefaultLoc(),
7706 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007707 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007708 AssocTypes,
7709 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007710}
7711
7712template<typename Derived>
7713ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007714TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007715 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007716 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007717 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007718
Douglas Gregora16548e2009-08-11 05:31:07 +00007719 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007720 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007721
John McCallb268a282010-08-23 23:25:46 +00007722 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007723 E->getRParen());
7724}
7725
Richard Smithdb2630f2012-10-21 03:28:35 +00007726/// \brief The operand of a unary address-of operator has special rules: it's
7727/// allowed to refer to a non-static member of a class even if there's no 'this'
7728/// object available.
7729template<typename Derived>
7730ExprResult
7731TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7732 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007733 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007734 else
7735 return getDerived().TransformExpr(E);
7736}
7737
Mike Stump11289f42009-09-09 15:08:12 +00007738template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007739ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007740TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007741 ExprResult SubExpr;
7742 if (E->getOpcode() == UO_AddrOf)
7743 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7744 else
7745 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007746 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007747 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007748
Douglas Gregora16548e2009-08-11 05:31:07 +00007749 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007750 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007751
Douglas Gregora16548e2009-08-11 05:31:07 +00007752 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7753 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007754 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007755}
Mike Stump11289f42009-09-09 15:08:12 +00007756
Douglas Gregora16548e2009-08-11 05:31:07 +00007757template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007758ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007759TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7760 // Transform the type.
7761 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7762 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007763 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007764
Douglas Gregor882211c2010-04-28 22:16:22 +00007765 // Transform all of the components into components similar to what the
7766 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007767 // FIXME: It would be slightly more efficient in the non-dependent case to
7768 // just map FieldDecls, rather than requiring the rebuilder to look for
7769 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007770 // template code that we don't care.
7771 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007772 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007773 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007774 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007775 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7776 const Node &ON = E->getComponent(I);
7777 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007778 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007779 Comp.LocStart = ON.getSourceRange().getBegin();
7780 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007781 switch (ON.getKind()) {
7782 case Node::Array: {
7783 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007784 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007785 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007786 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007787
Douglas Gregor882211c2010-04-28 22:16:22 +00007788 ExprChanged = ExprChanged || Index.get() != FromIndex;
7789 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007790 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007791 break;
7792 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007793
Douglas Gregor882211c2010-04-28 22:16:22 +00007794 case Node::Field:
7795 case Node::Identifier:
7796 Comp.isBrackets = false;
7797 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007798 if (!Comp.U.IdentInfo)
7799 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007800
Douglas Gregor882211c2010-04-28 22:16:22 +00007801 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007802
Douglas Gregord1702062010-04-29 00:18:15 +00007803 case Node::Base:
7804 // Will be recomputed during the rebuild.
7805 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007806 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007807
Douglas Gregor882211c2010-04-28 22:16:22 +00007808 Components.push_back(Comp);
7809 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007810
Douglas Gregor882211c2010-04-28 22:16:22 +00007811 // If nothing changed, retain the existing expression.
7812 if (!getDerived().AlwaysRebuild() &&
7813 Type == E->getTypeSourceInfo() &&
7814 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007815 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007816
Douglas Gregor882211c2010-04-28 22:16:22 +00007817 // Build a new offsetof expression.
7818 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7819 Components.data(), Components.size(),
7820 E->getRParenLoc());
7821}
7822
7823template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007824ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007825TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00007826 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00007827 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007828 return E;
John McCall8d69a212010-11-15 23:31:06 +00007829}
7830
7831template<typename Derived>
7832ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00007833TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
7834 return E;
7835}
7836
7837template<typename Derived>
7838ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007839TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007840 // Rebuild the syntactic form. The original syntactic form has
7841 // opaque-value expressions in it, so strip those away and rebuild
7842 // the result. This is a really awful way of doing this, but the
7843 // better solution (rebuilding the semantic expressions and
7844 // rebinding OVEs as necessary) doesn't work; we'd need
7845 // TreeTransform to not strip away implicit conversions.
7846 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7847 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007848 if (result.isInvalid()) return ExprError();
7849
7850 // If that gives us a pseudo-object result back, the pseudo-object
7851 // expression must have been an lvalue-to-rvalue conversion which we
7852 // should reapply.
7853 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007854 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007855
7856 return result;
7857}
7858
7859template<typename Derived>
7860ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007861TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7862 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007863 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007864 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007865
John McCallbcd03502009-12-07 02:54:59 +00007866 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007867 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007868 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007869
John McCall4c98fd82009-11-04 07:28:41 +00007870 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007871 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007872
Peter Collingbournee190dee2011-03-11 19:24:49 +00007873 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7874 E->getKind(),
7875 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007876 }
Mike Stump11289f42009-09-09 15:08:12 +00007877
Eli Friedmane4f22df2012-02-29 04:03:55 +00007878 // C++0x [expr.sizeof]p1:
7879 // The operand is either an expression, which is an unevaluated operand
7880 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007881 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7882 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007883
Reid Kleckner32506ed2014-06-12 23:03:48 +00007884 // Try to recover if we have something like sizeof(T::X) where X is a type.
7885 // Notably, there must be *exactly* one set of parens if X is a type.
7886 TypeSourceInfo *RecoveryTSI = nullptr;
7887 ExprResult SubExpr;
7888 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7889 if (auto *DRE =
7890 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7891 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7892 PE, DRE, false, &RecoveryTSI);
7893 else
7894 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7895
7896 if (RecoveryTSI) {
7897 return getDerived().RebuildUnaryExprOrTypeTrait(
7898 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7899 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007900 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007901
Eli Friedmane4f22df2012-02-29 04:03:55 +00007902 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007903 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007904
Peter Collingbournee190dee2011-03-11 19:24:49 +00007905 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7906 E->getOperatorLoc(),
7907 E->getKind(),
7908 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007909}
Mike Stump11289f42009-09-09 15:08:12 +00007910
Douglas Gregora16548e2009-08-11 05:31:07 +00007911template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007912ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007913TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007914 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007915 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007916 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007917
John McCalldadc5752010-08-24 06:29:42 +00007918 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007919 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007920 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007921
7922
Douglas Gregora16548e2009-08-11 05:31:07 +00007923 if (!getDerived().AlwaysRebuild() &&
7924 LHS.get() == E->getLHS() &&
7925 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007926 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007927
John McCallb268a282010-08-23 23:25:46 +00007928 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007929 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007930 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007931 E->getRBracketLoc());
7932}
Mike Stump11289f42009-09-09 15:08:12 +00007933
Alexey Bataev1a3320e2015-08-25 14:24:04 +00007934template <typename Derived>
7935ExprResult
7936TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
7937 ExprResult Base = getDerived().TransformExpr(E->getBase());
7938 if (Base.isInvalid())
7939 return ExprError();
7940
7941 ExprResult LowerBound;
7942 if (E->getLowerBound()) {
7943 LowerBound = getDerived().TransformExpr(E->getLowerBound());
7944 if (LowerBound.isInvalid())
7945 return ExprError();
7946 }
7947
7948 ExprResult Length;
7949 if (E->getLength()) {
7950 Length = getDerived().TransformExpr(E->getLength());
7951 if (Length.isInvalid())
7952 return ExprError();
7953 }
7954
7955 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
7956 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
7957 return E;
7958
7959 return getDerived().RebuildOMPArraySectionExpr(
7960 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
7961 Length.get(), E->getRBracketLoc());
7962}
7963
Mike Stump11289f42009-09-09 15:08:12 +00007964template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007965ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007966TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007967 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007968 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007969 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007970 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007971
7972 // Transform arguments.
7973 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007974 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007975 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007976 &ArgChanged))
7977 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007978
Douglas Gregora16548e2009-08-11 05:31:07 +00007979 if (!getDerived().AlwaysRebuild() &&
7980 Callee.get() == E->getCallee() &&
7981 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007982 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007983
Douglas Gregora16548e2009-08-11 05:31:07 +00007984 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007985 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007986 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007987 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007988 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007989 E->getRParenLoc());
7990}
Mike Stump11289f42009-09-09 15:08:12 +00007991
7992template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007993ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007994TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007995 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007996 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007997 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007998
Douglas Gregorea972d32011-02-28 21:54:11 +00007999 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008000 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00008001 QualifierLoc
8002 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008003
Douglas Gregorea972d32011-02-28 21:54:11 +00008004 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008005 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008006 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008007 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008008
Eli Friedman2cfcef62009-12-04 06:40:45 +00008009 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008010 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8011 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008012 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008013 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008014
John McCall16df1e52010-03-30 21:47:33 +00008015 NamedDecl *FoundDecl = E->getFoundDecl();
8016 if (FoundDecl == E->getMemberDecl()) {
8017 FoundDecl = Member;
8018 } else {
8019 FoundDecl = cast_or_null<NamedDecl>(
8020 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8021 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008022 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008023 }
8024
Douglas Gregora16548e2009-08-11 05:31:07 +00008025 if (!getDerived().AlwaysRebuild() &&
8026 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008027 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008028 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008029 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008030 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008031
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008032 // Mark it referenced in the new context regardless.
8033 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008034 SemaRef.MarkMemberReferenced(E);
8035
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008036 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008037 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008038
John McCall6b51f282009-11-23 01:53:49 +00008039 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008040 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008041 TransArgs.setLAngleLoc(E->getLAngleLoc());
8042 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008043 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8044 E->getNumTemplateArgs(),
8045 TransArgs))
8046 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008047 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008048
Douglas Gregora16548e2009-08-11 05:31:07 +00008049 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008050 SourceLocation FakeOperatorLoc =
8051 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008052
John McCall38836f02010-01-15 08:34:02 +00008053 // FIXME: to do this check properly, we will need to preserve the
8054 // first-qualifier-in-scope here, just in case we had a dependent
8055 // base (and therefore couldn't do the check) and a
8056 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008057 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008058
John McCallb268a282010-08-23 23:25:46 +00008059 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008060 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008061 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008062 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008063 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008064 Member,
John McCall16df1e52010-03-30 21:47:33 +00008065 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008066 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008067 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008068 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008069}
Mike Stump11289f42009-09-09 15:08:12 +00008070
Douglas Gregora16548e2009-08-11 05:31:07 +00008071template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008072ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008073TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008074 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008075 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008076 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008077
John McCalldadc5752010-08-24 06:29:42 +00008078 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008079 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008080 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008081
Douglas Gregora16548e2009-08-11 05:31:07 +00008082 if (!getDerived().AlwaysRebuild() &&
8083 LHS.get() == E->getLHS() &&
8084 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008085 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008086
Lang Hames5de91cc2012-10-02 04:45:10 +00008087 Sema::FPContractStateRAII FPContractState(getSema());
8088 getSema().FPFeatures.fp_contract = E->isFPContractable();
8089
Douglas Gregora16548e2009-08-11 05:31:07 +00008090 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008091 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008092}
8093
Mike Stump11289f42009-09-09 15:08:12 +00008094template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008095ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008096TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008097 CompoundAssignOperator *E) {
8098 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008099}
Mike Stump11289f42009-09-09 15:08:12 +00008100
Douglas Gregora16548e2009-08-11 05:31:07 +00008101template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008102ExprResult TreeTransform<Derived>::
8103TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8104 // Just rebuild the common and RHS expressions and see whether we
8105 // get any changes.
8106
8107 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8108 if (commonExpr.isInvalid())
8109 return ExprError();
8110
8111 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8112 if (rhs.isInvalid())
8113 return ExprError();
8114
8115 if (!getDerived().AlwaysRebuild() &&
8116 commonExpr.get() == e->getCommon() &&
8117 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008118 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008119
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008120 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008121 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008122 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008123 e->getColonLoc(),
8124 rhs.get());
8125}
8126
8127template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008128ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008129TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008130 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008131 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008132 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008133
John McCalldadc5752010-08-24 06:29:42 +00008134 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008135 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008136 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008137
John McCalldadc5752010-08-24 06:29:42 +00008138 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008139 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008140 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008141
Douglas Gregora16548e2009-08-11 05:31:07 +00008142 if (!getDerived().AlwaysRebuild() &&
8143 Cond.get() == E->getCond() &&
8144 LHS.get() == E->getLHS() &&
8145 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008146 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008147
John McCallb268a282010-08-23 23:25:46 +00008148 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008149 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008150 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008151 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008152 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008153}
Mike Stump11289f42009-09-09 15:08:12 +00008154
8155template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008156ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008157TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008158 // Implicit casts are eliminated during transformation, since they
8159 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008160 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008161}
Mike Stump11289f42009-09-09 15:08:12 +00008162
Douglas Gregora16548e2009-08-11 05:31:07 +00008163template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008164ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008165TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008166 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8167 if (!Type)
8168 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008169
John McCalldadc5752010-08-24 06:29:42 +00008170 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008171 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008172 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008173 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008174
Douglas Gregora16548e2009-08-11 05:31:07 +00008175 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008176 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008177 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008178 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008179
John McCall97513962010-01-15 18:39:57 +00008180 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008181 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008182 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008183 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008184}
Mike Stump11289f42009-09-09 15:08:12 +00008185
Douglas Gregora16548e2009-08-11 05:31:07 +00008186template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008187ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008188TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008189 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8190 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8191 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008192 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008193
John McCalldadc5752010-08-24 06:29:42 +00008194 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008195 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008196 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008197
Douglas Gregora16548e2009-08-11 05:31:07 +00008198 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008199 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008200 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008201 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008202
John McCall5d7aa7f2010-01-19 22:33:45 +00008203 // Note: the expression type doesn't necessarily match the
8204 // type-as-written, but that's okay, because it should always be
8205 // derivable from the initializer.
8206
John McCalle15bbff2010-01-18 19:35:47 +00008207 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008208 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008209 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008210}
Mike Stump11289f42009-09-09 15:08:12 +00008211
Douglas Gregora16548e2009-08-11 05:31:07 +00008212template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008213ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008214TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008215 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008216 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008217 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008218
Douglas Gregora16548e2009-08-11 05:31:07 +00008219 if (!getDerived().AlwaysRebuild() &&
8220 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008221 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008222
Douglas Gregora16548e2009-08-11 05:31:07 +00008223 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008224 SourceLocation FakeOperatorLoc =
8225 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008226 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008227 E->getAccessorLoc(),
8228 E->getAccessor());
8229}
Mike Stump11289f42009-09-09 15:08:12 +00008230
Douglas Gregora16548e2009-08-11 05:31:07 +00008231template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008232ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008233TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008234 if (InitListExpr *Syntactic = E->getSyntacticForm())
8235 E = Syntactic;
8236
Douglas Gregora16548e2009-08-11 05:31:07 +00008237 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008238
Benjamin Kramerf0623432012-08-23 22:51:59 +00008239 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008240 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008241 Inits, &InitChanged))
8242 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008243
Richard Smith520449d2015-02-05 06:15:50 +00008244 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8245 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8246 // in some cases. We can't reuse it in general, because the syntactic and
8247 // semantic forms are linked, and we can't know that semantic form will
8248 // match even if the syntactic form does.
8249 }
Mike Stump11289f42009-09-09 15:08:12 +00008250
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008251 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008252 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008253}
Mike Stump11289f42009-09-09 15:08:12 +00008254
Douglas Gregora16548e2009-08-11 05:31:07 +00008255template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008256ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008257TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008258 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008259
Douglas Gregorebe10102009-08-20 07:17:43 +00008260 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008261 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008262 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008263 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008264
Douglas Gregorebe10102009-08-20 07:17:43 +00008265 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008266 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008267 bool ExprChanged = false;
8268 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
8269 DEnd = E->designators_end();
8270 D != DEnd; ++D) {
8271 if (D->isFieldDesignator()) {
8272 Desig.AddDesignator(Designator::getField(D->getFieldName(),
8273 D->getDotLoc(),
8274 D->getFieldLoc()));
8275 continue;
8276 }
Mike Stump11289f42009-09-09 15:08:12 +00008277
Douglas Gregora16548e2009-08-11 05:31:07 +00008278 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00008279 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008280 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008281 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008282
8283 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008284 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008285
Douglas Gregora16548e2009-08-11 05:31:07 +00008286 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008287 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008288 continue;
8289 }
Mike Stump11289f42009-09-09 15:08:12 +00008290
Douglas Gregora16548e2009-08-11 05:31:07 +00008291 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008292 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00008293 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
8294 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008295 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008296
John McCalldadc5752010-08-24 06:29:42 +00008297 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008298 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008299 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008300
8301 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008302 End.get(),
8303 D->getLBracketLoc(),
8304 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008305
Douglas Gregora16548e2009-08-11 05:31:07 +00008306 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
8307 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00008308
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008309 ArrayExprs.push_back(Start.get());
8310 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008311 }
Mike Stump11289f42009-09-09 15:08:12 +00008312
Douglas Gregora16548e2009-08-11 05:31:07 +00008313 if (!getDerived().AlwaysRebuild() &&
8314 Init.get() == E->getInit() &&
8315 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008316 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008317
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008318 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008319 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008320 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008321}
Mike Stump11289f42009-09-09 15:08:12 +00008322
Yunzhong Gaocb779302015-06-10 00:27:52 +00008323// Seems that if TransformInitListExpr() only works on the syntactic form of an
8324// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8325template<typename Derived>
8326ExprResult
8327TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8328 DesignatedInitUpdateExpr *E) {
8329 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8330 "initializer");
8331 return ExprError();
8332}
8333
8334template<typename Derived>
8335ExprResult
8336TreeTransform<Derived>::TransformNoInitExpr(
8337 NoInitExpr *E) {
8338 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8339 return ExprError();
8340}
8341
Douglas Gregora16548e2009-08-11 05:31:07 +00008342template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008343ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008344TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008345 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008346 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008347
Douglas Gregor3da3c062009-10-28 00:29:27 +00008348 // FIXME: Will we ever have proper type location here? Will we actually
8349 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008350 QualType T = getDerived().TransformType(E->getType());
8351 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008352 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008353
Douglas Gregora16548e2009-08-11 05:31:07 +00008354 if (!getDerived().AlwaysRebuild() &&
8355 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008356 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008357
Douglas Gregora16548e2009-08-11 05:31:07 +00008358 return getDerived().RebuildImplicitValueInitExpr(T);
8359}
Mike Stump11289f42009-09-09 15:08:12 +00008360
Douglas Gregora16548e2009-08-11 05:31:07 +00008361template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008362ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008363TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008364 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8365 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008366 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008367
John McCalldadc5752010-08-24 06:29:42 +00008368 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008369 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008370 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008371
Douglas Gregora16548e2009-08-11 05:31:07 +00008372 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008373 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008374 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008375 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008376
John McCallb268a282010-08-23 23:25:46 +00008377 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008378 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008379}
8380
8381template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008382ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008383TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008384 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008385 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008386 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8387 &ArgumentChanged))
8388 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008389
Douglas Gregora16548e2009-08-11 05:31:07 +00008390 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008391 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008392 E->getRParenLoc());
8393}
Mike Stump11289f42009-09-09 15:08:12 +00008394
Douglas Gregora16548e2009-08-11 05:31:07 +00008395/// \brief Transform an address-of-label expression.
8396///
8397/// By default, the transformation of an address-of-label expression always
8398/// rebuilds the expression, so that the label identifier can be resolved to
8399/// the corresponding label statement by semantic analysis.
8400template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008401ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008402TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008403 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8404 E->getLabel());
8405 if (!LD)
8406 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008407
Douglas Gregora16548e2009-08-11 05:31:07 +00008408 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008409 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008410}
Mike Stump11289f42009-09-09 15:08:12 +00008411
8412template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008413ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008414TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008415 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008416 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008417 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008418 if (SubStmt.isInvalid()) {
8419 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008420 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008421 }
Mike Stump11289f42009-09-09 15:08:12 +00008422
Douglas Gregora16548e2009-08-11 05:31:07 +00008423 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008424 SubStmt.get() == E->getSubStmt()) {
8425 // Calling this an 'error' is unintuitive, but it does the right thing.
8426 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008427 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008428 }
Mike Stump11289f42009-09-09 15:08:12 +00008429
8430 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008431 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008432 E->getRParenLoc());
8433}
Mike Stump11289f42009-09-09 15:08:12 +00008434
Douglas Gregora16548e2009-08-11 05:31:07 +00008435template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008436ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008437TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008438 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008439 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008440 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008441
John McCalldadc5752010-08-24 06:29:42 +00008442 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008443 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008444 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008445
John McCalldadc5752010-08-24 06:29:42 +00008446 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008447 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008448 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008449
Douglas Gregora16548e2009-08-11 05:31:07 +00008450 if (!getDerived().AlwaysRebuild() &&
8451 Cond.get() == E->getCond() &&
8452 LHS.get() == E->getLHS() &&
8453 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008454 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008455
Douglas Gregora16548e2009-08-11 05:31:07 +00008456 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008457 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008458 E->getRParenLoc());
8459}
Mike Stump11289f42009-09-09 15:08:12 +00008460
Douglas Gregora16548e2009-08-11 05:31:07 +00008461template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008462ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008463TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008464 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008465}
8466
8467template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008468ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008469TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008470 switch (E->getOperator()) {
8471 case OO_New:
8472 case OO_Delete:
8473 case OO_Array_New:
8474 case OO_Array_Delete:
8475 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008476
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008477 case OO_Call: {
8478 // This is a call to an object's operator().
8479 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8480
8481 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008482 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008483 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008484 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008485
8486 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008487 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8488 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008489
8490 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008491 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008492 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008493 Args))
8494 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008495
John McCallb268a282010-08-23 23:25:46 +00008496 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008497 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008498 E->getLocEnd());
8499 }
8500
8501#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8502 case OO_##Name:
8503#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8504#include "clang/Basic/OperatorKinds.def"
8505 case OO_Subscript:
8506 // Handled below.
8507 break;
8508
8509 case OO_Conditional:
8510 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008511
8512 case OO_None:
8513 case NUM_OVERLOADED_OPERATORS:
8514 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008515 }
8516
John McCalldadc5752010-08-24 06:29:42 +00008517 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008518 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008519 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008520
Richard Smithdb2630f2012-10-21 03:28:35 +00008521 ExprResult First;
8522 if (E->getOperator() == OO_Amp)
8523 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8524 else
8525 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008526 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008527 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008528
John McCalldadc5752010-08-24 06:29:42 +00008529 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008530 if (E->getNumArgs() == 2) {
8531 Second = getDerived().TransformExpr(E->getArg(1));
8532 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008533 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008534 }
Mike Stump11289f42009-09-09 15:08:12 +00008535
Douglas Gregora16548e2009-08-11 05:31:07 +00008536 if (!getDerived().AlwaysRebuild() &&
8537 Callee.get() == E->getCallee() &&
8538 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008539 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008540 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008541
Lang Hames5de91cc2012-10-02 04:45:10 +00008542 Sema::FPContractStateRAII FPContractState(getSema());
8543 getSema().FPFeatures.fp_contract = E->isFPContractable();
8544
Douglas Gregora16548e2009-08-11 05:31:07 +00008545 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8546 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008547 Callee.get(),
8548 First.get(),
8549 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008550}
Mike Stump11289f42009-09-09 15:08:12 +00008551
Douglas Gregora16548e2009-08-11 05:31:07 +00008552template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008553ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008554TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8555 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008556}
Mike Stump11289f42009-09-09 15:08:12 +00008557
Douglas Gregora16548e2009-08-11 05:31:07 +00008558template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008559ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008560TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8561 // Transform the callee.
8562 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8563 if (Callee.isInvalid())
8564 return ExprError();
8565
8566 // Transform exec config.
8567 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8568 if (EC.isInvalid())
8569 return ExprError();
8570
8571 // Transform arguments.
8572 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008573 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008574 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008575 &ArgChanged))
8576 return ExprError();
8577
8578 if (!getDerived().AlwaysRebuild() &&
8579 Callee.get() == E->getCallee() &&
8580 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008581 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008582
8583 // FIXME: Wrong source location information for the '('.
8584 SourceLocation FakeLParenLoc
8585 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8586 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008587 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008588 E->getRParenLoc(), EC.get());
8589}
8590
8591template<typename Derived>
8592ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008593TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008594 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8595 if (!Type)
8596 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008597
John McCalldadc5752010-08-24 06:29:42 +00008598 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008599 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008600 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008601 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008602
Douglas Gregora16548e2009-08-11 05:31:07 +00008603 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008604 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008605 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008606 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008607 return getDerived().RebuildCXXNamedCastExpr(
8608 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8609 Type, E->getAngleBrackets().getEnd(),
8610 // FIXME. this should be '(' location
8611 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008612}
Mike Stump11289f42009-09-09 15:08:12 +00008613
Douglas Gregora16548e2009-08-11 05:31:07 +00008614template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008615ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008616TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8617 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008618}
Mike Stump11289f42009-09-09 15:08:12 +00008619
8620template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008621ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008622TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8623 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008624}
8625
Douglas Gregora16548e2009-08-11 05:31:07 +00008626template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008627ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008628TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008629 CXXReinterpretCastExpr *E) {
8630 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008631}
Mike Stump11289f42009-09-09 15:08:12 +00008632
Douglas Gregora16548e2009-08-11 05:31:07 +00008633template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008634ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008635TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8636 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008637}
Mike Stump11289f42009-09-09 15:08:12 +00008638
Douglas Gregora16548e2009-08-11 05:31:07 +00008639template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008640ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008641TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008642 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008643 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8644 if (!Type)
8645 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008646
John McCalldadc5752010-08-24 06:29:42 +00008647 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008648 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008649 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008650 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008651
Douglas Gregora16548e2009-08-11 05:31:07 +00008652 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008653 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008654 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008655 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008656
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008657 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008658 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008659 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008660 E->getRParenLoc());
8661}
Mike Stump11289f42009-09-09 15:08:12 +00008662
Douglas Gregora16548e2009-08-11 05:31:07 +00008663template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008664ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008665TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008666 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008667 TypeSourceInfo *TInfo
8668 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8669 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008670 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008671
Douglas Gregora16548e2009-08-11 05:31:07 +00008672 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008673 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008674 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008675
Douglas Gregor9da64192010-04-26 22:37:10 +00008676 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8677 E->getLocStart(),
8678 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008679 E->getLocEnd());
8680 }
Mike Stump11289f42009-09-09 15:08:12 +00008681
Eli Friedman456f0182012-01-20 01:26:23 +00008682 // We don't know whether the subexpression is potentially evaluated until
8683 // after we perform semantic analysis. We speculatively assume it is
8684 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008685 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008686 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8687 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008688
John McCalldadc5752010-08-24 06:29:42 +00008689 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008690 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008691 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008692
Douglas Gregora16548e2009-08-11 05:31:07 +00008693 if (!getDerived().AlwaysRebuild() &&
8694 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008695 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008696
Douglas Gregor9da64192010-04-26 22:37:10 +00008697 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8698 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008699 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008700 E->getLocEnd());
8701}
8702
8703template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008704ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008705TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8706 if (E->isTypeOperand()) {
8707 TypeSourceInfo *TInfo
8708 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8709 if (!TInfo)
8710 return ExprError();
8711
8712 if (!getDerived().AlwaysRebuild() &&
8713 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008714 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008715
Douglas Gregor69735112011-03-06 17:40:41 +00008716 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008717 E->getLocStart(),
8718 TInfo,
8719 E->getLocEnd());
8720 }
8721
Francois Pichet9f4f2072010-09-08 12:20:18 +00008722 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8723
8724 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8725 if (SubExpr.isInvalid())
8726 return ExprError();
8727
8728 if (!getDerived().AlwaysRebuild() &&
8729 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008730 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008731
8732 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8733 E->getLocStart(),
8734 SubExpr.get(),
8735 E->getLocEnd());
8736}
8737
8738template<typename Derived>
8739ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008740TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008741 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008742}
Mike Stump11289f42009-09-09 15:08:12 +00008743
Douglas Gregora16548e2009-08-11 05:31:07 +00008744template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008745ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008746TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008747 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008748 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008749}
Mike Stump11289f42009-09-09 15:08:12 +00008750
Douglas Gregora16548e2009-08-11 05:31:07 +00008751template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008752ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008753TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008754 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008755
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008756 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8757 // Make sure that we capture 'this'.
8758 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008759 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008760 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008761
Douglas Gregorb15af892010-01-07 23:12:05 +00008762 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008763}
Mike Stump11289f42009-09-09 15:08:12 +00008764
Douglas Gregora16548e2009-08-11 05:31:07 +00008765template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008766ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008767TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008768 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008769 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008770 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008771
Douglas Gregora16548e2009-08-11 05:31:07 +00008772 if (!getDerived().AlwaysRebuild() &&
8773 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008774 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008775
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008776 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8777 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008778}
Mike Stump11289f42009-09-09 15:08:12 +00008779
Douglas Gregora16548e2009-08-11 05:31:07 +00008780template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008781ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008782TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008783 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008784 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8785 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008786 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008787 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008788
Chandler Carruth794da4c2010-02-08 06:42:49 +00008789 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008790 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008791 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008792
Douglas Gregor033f6752009-12-23 23:03:06 +00008793 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008794}
Mike Stump11289f42009-09-09 15:08:12 +00008795
Douglas Gregora16548e2009-08-11 05:31:07 +00008796template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008797ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008798TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8799 FieldDecl *Field
8800 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8801 E->getField()));
8802 if (!Field)
8803 return ExprError();
8804
8805 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008806 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008807
8808 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8809}
8810
8811template<typename Derived>
8812ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008813TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8814 CXXScalarValueInitExpr *E) {
8815 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8816 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008817 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008818
Douglas Gregora16548e2009-08-11 05:31:07 +00008819 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008820 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008821 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008822
Chad Rosier1dcde962012-08-08 18:46:20 +00008823 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008824 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008825 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008826}
Mike Stump11289f42009-09-09 15:08:12 +00008827
Douglas Gregora16548e2009-08-11 05:31:07 +00008828template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008829ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008830TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008831 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008832 TypeSourceInfo *AllocTypeInfo
8833 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8834 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008835 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008836
Douglas Gregora16548e2009-08-11 05:31:07 +00008837 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008838 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008839 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008840 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008841
Douglas Gregora16548e2009-08-11 05:31:07 +00008842 // Transform the placement arguments (if any).
8843 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008844 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008845 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008846 E->getNumPlacementArgs(), true,
8847 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008848 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008849
Sebastian Redl6047f072012-02-16 12:22:20 +00008850 // Transform the initializer (if any).
8851 Expr *OldInit = E->getInitializer();
8852 ExprResult NewInit;
8853 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008854 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008855 if (NewInit.isInvalid())
8856 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008857
Sebastian Redl6047f072012-02-16 12:22:20 +00008858 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008859 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008860 if (E->getOperatorNew()) {
8861 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008862 getDerived().TransformDecl(E->getLocStart(),
8863 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008864 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008865 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008866 }
8867
Craig Topperc3ec1492014-05-26 06:22:03 +00008868 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008869 if (E->getOperatorDelete()) {
8870 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008871 getDerived().TransformDecl(E->getLocStart(),
8872 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008873 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008874 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008875 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008876
Douglas Gregora16548e2009-08-11 05:31:07 +00008877 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008878 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008879 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008880 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008881 OperatorNew == E->getOperatorNew() &&
8882 OperatorDelete == E->getOperatorDelete() &&
8883 !ArgumentChanged) {
8884 // Mark any declarations we need as referenced.
8885 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008886 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008887 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008888 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008889 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008890
Sebastian Redl6047f072012-02-16 12:22:20 +00008891 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008892 QualType ElementType
8893 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8894 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8895 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8896 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008897 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008898 }
8899 }
8900 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008901
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008902 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008903 }
Mike Stump11289f42009-09-09 15:08:12 +00008904
Douglas Gregor0744ef62010-09-07 21:49:58 +00008905 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008906 if (!ArraySize.get()) {
8907 // If no array size was specified, but the new expression was
8908 // instantiated with an array type (e.g., "new T" where T is
8909 // instantiated with "int[4]"), extract the outer bound from the
8910 // array type as our array size. We do this with constant and
8911 // dependently-sized array types.
8912 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8913 if (!ArrayT) {
8914 // Do nothing
8915 } else if (const ConstantArrayType *ConsArrayT
8916 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008917 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8918 SemaRef.Context.getSizeType(),
8919 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008920 AllocType = ConsArrayT->getElementType();
8921 } else if (const DependentSizedArrayType *DepArrayT
8922 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8923 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008924 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008925 AllocType = DepArrayT->getElementType();
8926 }
8927 }
8928 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008929
Douglas Gregora16548e2009-08-11 05:31:07 +00008930 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8931 E->isGlobalNew(),
8932 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008933 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008934 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008935 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008936 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008937 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008938 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008939 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008940 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008941}
Mike Stump11289f42009-09-09 15:08:12 +00008942
Douglas Gregora16548e2009-08-11 05:31:07 +00008943template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008944ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008945TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008946 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008947 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008948 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008949
Douglas Gregord2d9da02010-02-26 00:38:10 +00008950 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008951 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008952 if (E->getOperatorDelete()) {
8953 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008954 getDerived().TransformDecl(E->getLocStart(),
8955 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008956 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008957 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008958 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008959
Douglas Gregora16548e2009-08-11 05:31:07 +00008960 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008961 Operand.get() == E->getArgument() &&
8962 OperatorDelete == E->getOperatorDelete()) {
8963 // Mark any declarations we need as referenced.
8964 // FIXME: instantiation-specific.
8965 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008966 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008967
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008968 if (!E->getArgument()->isTypeDependent()) {
8969 QualType Destroyed = SemaRef.Context.getBaseElementType(
8970 E->getDestroyedType());
8971 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8972 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008973 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008974 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008975 }
8976 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008977
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008978 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008979 }
Mike Stump11289f42009-09-09 15:08:12 +00008980
Douglas Gregora16548e2009-08-11 05:31:07 +00008981 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8982 E->isGlobalDelete(),
8983 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008984 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008985}
Mike Stump11289f42009-09-09 15:08:12 +00008986
Douglas Gregora16548e2009-08-11 05:31:07 +00008987template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008988ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008989TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008990 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008991 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008992 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008993 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008994
John McCallba7bf592010-08-24 05:47:05 +00008995 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008996 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008997 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008998 E->getOperatorLoc(),
8999 E->isArrow()? tok::arrow : tok::period,
9000 ObjectTypePtr,
9001 MayBePseudoDestructor);
9002 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009003 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009004
John McCallba7bf592010-08-24 05:47:05 +00009005 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009006 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9007 if (QualifierLoc) {
9008 QualifierLoc
9009 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9010 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009011 return ExprError();
9012 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009013 CXXScopeSpec SS;
9014 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009015
Douglas Gregor678f90d2010-02-25 01:56:36 +00009016 PseudoDestructorTypeStorage Destroyed;
9017 if (E->getDestroyedTypeInfo()) {
9018 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009019 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009020 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009021 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009022 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009023 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009024 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009025 // We aren't likely to be able to resolve the identifier down to a type
9026 // now anyway, so just retain the identifier.
9027 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9028 E->getDestroyedTypeLoc());
9029 } else {
9030 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009031 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009032 *E->getDestroyedTypeIdentifier(),
9033 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009034 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009035 SS, ObjectTypePtr,
9036 false);
9037 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009038 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009039
Douglas Gregor678f90d2010-02-25 01:56:36 +00009040 Destroyed
9041 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9042 E->getDestroyedTypeLoc());
9043 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009044
Craig Topperc3ec1492014-05-26 06:22:03 +00009045 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009046 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009047 CXXScopeSpec EmptySS;
9048 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009049 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009050 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009051 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009052 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009053
John McCallb268a282010-08-23 23:25:46 +00009054 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009055 E->getOperatorLoc(),
9056 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009057 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009058 ScopeTypeInfo,
9059 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009060 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009061 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009062}
Mike Stump11289f42009-09-09 15:08:12 +00009063
Douglas Gregorad8a3362009-09-04 17:36:40 +00009064template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009065ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009066TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009067 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009068 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9069 Sema::LookupOrdinaryName);
9070
9071 // Transform all the decls.
9072 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9073 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009074 NamedDecl *InstD = static_cast<NamedDecl*>(
9075 getDerived().TransformDecl(Old->getNameLoc(),
9076 *I));
John McCall84d87672009-12-10 09:41:52 +00009077 if (!InstD) {
9078 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9079 // This can happen because of dependent hiding.
9080 if (isa<UsingShadowDecl>(*I))
9081 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009082 else {
9083 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009084 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009085 }
John McCall84d87672009-12-10 09:41:52 +00009086 }
John McCalle66edc12009-11-24 19:00:30 +00009087
9088 // Expand using declarations.
9089 if (isa<UsingDecl>(InstD)) {
9090 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009091 for (auto *I : UD->shadows())
9092 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009093 continue;
9094 }
9095
9096 R.addDecl(InstD);
9097 }
9098
9099 // Resolve a kind, but don't do any further analysis. If it's
9100 // ambiguous, the callee needs to deal with it.
9101 R.resolveKind();
9102
9103 // Rebuild the nested-name qualifier, if present.
9104 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009105 if (Old->getQualifierLoc()) {
9106 NestedNameSpecifierLoc QualifierLoc
9107 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9108 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009109 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009110
Douglas Gregor0da1d432011-02-28 20:01:57 +00009111 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009112 }
9113
Douglas Gregor9262f472010-04-27 18:19:34 +00009114 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009115 CXXRecordDecl *NamingClass
9116 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9117 Old->getNameLoc(),
9118 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009119 if (!NamingClass) {
9120 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009121 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009122 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009123
Douglas Gregorda7be082010-04-27 16:10:10 +00009124 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009125 }
9126
Abramo Bagnara7945c982012-01-27 09:46:47 +00009127 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9128
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009129 // If we have neither explicit template arguments, nor the template keyword,
9130 // it's a normal declaration name.
9131 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00009132 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
9133
9134 // If we have template arguments, rebuild them, then rebuild the
9135 // templateid expression.
9136 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009137 if (Old->hasExplicitTemplateArgs() &&
9138 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009139 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009140 TransArgs)) {
9141 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009142 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009143 }
John McCalle66edc12009-11-24 19:00:30 +00009144
Abramo Bagnara7945c982012-01-27 09:46:47 +00009145 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009146 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009147}
Mike Stump11289f42009-09-09 15:08:12 +00009148
Douglas Gregora16548e2009-08-11 05:31:07 +00009149template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009150ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009151TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9152 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009153 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009154 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9155 TypeSourceInfo *From = E->getArg(I);
9156 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009157 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009158 TypeLocBuilder TLB;
9159 TLB.reserve(FromTL.getFullDataSize());
9160 QualType To = getDerived().TransformType(TLB, FromTL);
9161 if (To.isNull())
9162 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009163
Douglas Gregor29c42f22012-02-24 07:38:34 +00009164 if (To == From->getType())
9165 Args.push_back(From);
9166 else {
9167 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9168 ArgChanged = true;
9169 }
9170 continue;
9171 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009172
Douglas Gregor29c42f22012-02-24 07:38:34 +00009173 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009174
Douglas Gregor29c42f22012-02-24 07:38:34 +00009175 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009176 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009177 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9178 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9179 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009180
Douglas Gregor29c42f22012-02-24 07:38:34 +00009181 // Determine whether the set of unexpanded parameter packs can and should
9182 // be expanded.
9183 bool Expand = true;
9184 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009185 Optional<unsigned> OrigNumExpansions =
9186 ExpansionTL.getTypePtr()->getNumExpansions();
9187 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009188 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9189 PatternTL.getSourceRange(),
9190 Unexpanded,
9191 Expand, RetainExpansion,
9192 NumExpansions))
9193 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009194
Douglas Gregor29c42f22012-02-24 07:38:34 +00009195 if (!Expand) {
9196 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009197 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009198 // expansion.
9199 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009200
Douglas Gregor29c42f22012-02-24 07:38:34 +00009201 TypeLocBuilder TLB;
9202 TLB.reserve(From->getTypeLoc().getFullDataSize());
9203
9204 QualType To = getDerived().TransformType(TLB, PatternTL);
9205 if (To.isNull())
9206 return ExprError();
9207
Chad Rosier1dcde962012-08-08 18:46:20 +00009208 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009209 PatternTL.getSourceRange(),
9210 ExpansionTL.getEllipsisLoc(),
9211 NumExpansions);
9212 if (To.isNull())
9213 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009214
Douglas Gregor29c42f22012-02-24 07:38:34 +00009215 PackExpansionTypeLoc ToExpansionTL
9216 = TLB.push<PackExpansionTypeLoc>(To);
9217 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9218 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9219 continue;
9220 }
9221
9222 // Expand the pack expansion by substituting for each argument in the
9223 // pack(s).
9224 for (unsigned I = 0; I != *NumExpansions; ++I) {
9225 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9226 TypeLocBuilder TLB;
9227 TLB.reserve(PatternTL.getFullDataSize());
9228 QualType To = getDerived().TransformType(TLB, PatternTL);
9229 if (To.isNull())
9230 return ExprError();
9231
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009232 if (To->containsUnexpandedParameterPack()) {
9233 To = getDerived().RebuildPackExpansionType(To,
9234 PatternTL.getSourceRange(),
9235 ExpansionTL.getEllipsisLoc(),
9236 NumExpansions);
9237 if (To.isNull())
9238 return ExprError();
9239
9240 PackExpansionTypeLoc ToExpansionTL
9241 = TLB.push<PackExpansionTypeLoc>(To);
9242 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9243 }
9244
Douglas Gregor29c42f22012-02-24 07:38:34 +00009245 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9246 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009247
Douglas Gregor29c42f22012-02-24 07:38:34 +00009248 if (!RetainExpansion)
9249 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009250
Douglas Gregor29c42f22012-02-24 07:38:34 +00009251 // If we're supposed to retain a pack expansion, do so by temporarily
9252 // forgetting the partially-substituted parameter pack.
9253 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9254
9255 TypeLocBuilder TLB;
9256 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009257
Douglas Gregor29c42f22012-02-24 07:38:34 +00009258 QualType To = getDerived().TransformType(TLB, PatternTL);
9259 if (To.isNull())
9260 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009261
9262 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009263 PatternTL.getSourceRange(),
9264 ExpansionTL.getEllipsisLoc(),
9265 NumExpansions);
9266 if (To.isNull())
9267 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009268
Douglas Gregor29c42f22012-02-24 07:38:34 +00009269 PackExpansionTypeLoc ToExpansionTL
9270 = TLB.push<PackExpansionTypeLoc>(To);
9271 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9272 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9273 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009274
Douglas Gregor29c42f22012-02-24 07:38:34 +00009275 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009276 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009277
9278 return getDerived().RebuildTypeTrait(E->getTrait(),
9279 E->getLocStart(),
9280 Args,
9281 E->getLocEnd());
9282}
9283
9284template<typename Derived>
9285ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009286TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9287 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9288 if (!T)
9289 return ExprError();
9290
9291 if (!getDerived().AlwaysRebuild() &&
9292 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009293 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009294
9295 ExprResult SubExpr;
9296 {
9297 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9298 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9299 if (SubExpr.isInvalid())
9300 return ExprError();
9301
9302 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009303 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009304 }
9305
9306 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9307 E->getLocStart(),
9308 T,
9309 SubExpr.get(),
9310 E->getLocEnd());
9311}
9312
9313template<typename Derived>
9314ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009315TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9316 ExprResult SubExpr;
9317 {
9318 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9319 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9320 if (SubExpr.isInvalid())
9321 return ExprError();
9322
9323 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009324 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009325 }
9326
9327 return getDerived().RebuildExpressionTrait(
9328 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9329}
9330
Reid Kleckner32506ed2014-06-12 23:03:48 +00009331template <typename Derived>
9332ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9333 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9334 TypeSourceInfo **RecoveryTSI) {
9335 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9336 DRE, AddrTaken, RecoveryTSI);
9337
9338 // Propagate both errors and recovered types, which return ExprEmpty.
9339 if (!NewDRE.isUsable())
9340 return NewDRE;
9341
9342 // We got an expr, wrap it up in parens.
9343 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9344 return PE;
9345 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9346 PE->getRParen());
9347}
9348
9349template <typename Derived>
9350ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9351 DependentScopeDeclRefExpr *E) {
9352 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9353 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009354}
9355
9356template<typename Derived>
9357ExprResult
9358TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9359 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009360 bool IsAddressOfOperand,
9361 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009362 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009363 NestedNameSpecifierLoc QualifierLoc
9364 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9365 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009366 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009367 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009368
John McCall31f82722010-11-12 08:19:04 +00009369 // TODO: If this is a conversion-function-id, verify that the
9370 // destination type name (if present) resolves the same way after
9371 // instantiation as it did in the local scope.
9372
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009373 DeclarationNameInfo NameInfo
9374 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9375 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009376 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009377
John McCalle66edc12009-11-24 19:00:30 +00009378 if (!E->hasExplicitTemplateArgs()) {
9379 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009380 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009381 // Note: it is sufficient to compare the Name component of NameInfo:
9382 // if name has not changed, DNLoc has not changed either.
9383 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009384 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009385
Reid Kleckner32506ed2014-06-12 23:03:48 +00009386 return getDerived().RebuildDependentScopeDeclRefExpr(
9387 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9388 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009389 }
John McCall6b51f282009-11-23 01:53:49 +00009390
9391 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009392 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9393 E->getNumTemplateArgs(),
9394 TransArgs))
9395 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009396
Reid Kleckner32506ed2014-06-12 23:03:48 +00009397 return getDerived().RebuildDependentScopeDeclRefExpr(
9398 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9399 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009400}
9401
9402template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009403ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009404TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009405 // CXXConstructExprs other than for list-initialization and
9406 // CXXTemporaryObjectExpr are always implicit, so when we have
9407 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009408 if ((E->getNumArgs() == 1 ||
9409 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009410 (!getDerived().DropCallArgument(E->getArg(0))) &&
9411 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009412 return getDerived().TransformExpr(E->getArg(0));
9413
Douglas Gregora16548e2009-08-11 05:31:07 +00009414 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9415
9416 QualType T = getDerived().TransformType(E->getType());
9417 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009418 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009419
9420 CXXConstructorDecl *Constructor
9421 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009422 getDerived().TransformDecl(E->getLocStart(),
9423 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009424 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009425 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009426
Douglas Gregora16548e2009-08-11 05:31:07 +00009427 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009428 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009429 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009430 &ArgumentChanged))
9431 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009432
Douglas Gregora16548e2009-08-11 05:31:07 +00009433 if (!getDerived().AlwaysRebuild() &&
9434 T == E->getType() &&
9435 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009436 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009437 // Mark the constructor as referenced.
9438 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009439 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009440 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009441 }
Mike Stump11289f42009-09-09 15:08:12 +00009442
Douglas Gregordb121ba2009-12-14 16:27:04 +00009443 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9444 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009445 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009446 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009447 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009448 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009449 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009450 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009451 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009452}
Mike Stump11289f42009-09-09 15:08:12 +00009453
Douglas Gregora16548e2009-08-11 05:31:07 +00009454/// \brief Transform a C++ temporary-binding expression.
9455///
Douglas Gregor363b1512009-12-24 18:51:59 +00009456/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9457/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009458template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009459ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009460TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009461 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009462}
Mike Stump11289f42009-09-09 15:08:12 +00009463
John McCall5d413782010-12-06 08:20:24 +00009464/// \brief Transform a C++ expression that contains cleanups that should
9465/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009466///
John McCall5d413782010-12-06 08:20:24 +00009467/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009468/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009469template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009470ExprResult
John McCall5d413782010-12-06 08:20:24 +00009471TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009472 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009473}
Mike Stump11289f42009-09-09 15:08:12 +00009474
Douglas Gregora16548e2009-08-11 05:31:07 +00009475template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009476ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009477TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009478 CXXTemporaryObjectExpr *E) {
9479 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9480 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009481 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009482
Douglas Gregora16548e2009-08-11 05:31:07 +00009483 CXXConstructorDecl *Constructor
9484 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009485 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009486 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009487 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009488 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009489
Douglas Gregora16548e2009-08-11 05:31:07 +00009490 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009491 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009492 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009493 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009494 &ArgumentChanged))
9495 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009496
Douglas Gregora16548e2009-08-11 05:31:07 +00009497 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009498 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009499 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009500 !ArgumentChanged) {
9501 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009502 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009503 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009504 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009505
Richard Smithd59b8322012-12-19 01:39:02 +00009506 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009507 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9508 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009509 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009510 E->getLocEnd());
9511}
Mike Stump11289f42009-09-09 15:08:12 +00009512
Douglas Gregora16548e2009-08-11 05:31:07 +00009513template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009514ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009515TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009516 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009517 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009518 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009519 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9520 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009521 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009522 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009523 CEnd = E->capture_end();
9524 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009525 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009526 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009527 EnterExpressionEvaluationContext EEEC(getSema(),
9528 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009529 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9530 C->getCapturedVar()->getInit(),
9531 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009532
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009533 if (NewExprInitResult.isInvalid())
9534 return ExprError();
9535 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009536
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009537 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009538 QualType NewInitCaptureType =
9539 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
9540 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009541 NewExprInit);
9542 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009543 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9544 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009545 }
9546
Faisal Vali2cba1332013-10-23 06:44:28 +00009547 // Transform the template parameters, and add them to the current
9548 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +00009549 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +00009550 E->getTemplateParameterList());
9551
Richard Smith01014ce2014-11-20 23:53:14 +00009552 // Transform the type of the original lambda's call operator.
9553 // The transformation MUST be done in the CurrentInstantiationScope since
9554 // it introduces a mapping of the original to the newly created
9555 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009556 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009557 {
9558 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9559 FunctionProtoTypeLoc OldCallOpFPTL =
9560 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009561
9562 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009563 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009564 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009565 QualType NewCallOpType = TransformFunctionProtoType(
9566 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009567 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9568 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9569 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009570 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009571 if (NewCallOpType.isNull())
9572 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009573 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9574 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009575 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009576
Richard Smithc38498f2015-04-27 21:27:54 +00009577 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9578 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9579 LSI->GLTemplateParameterList = TPL;
9580
Eli Friedmand564afb2012-09-19 01:18:11 +00009581 // Create the local class that will describe the lambda.
9582 CXXRecordDecl *Class
9583 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009584 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009585 /*KnownDependent=*/false,
9586 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009587 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9588
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009589 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009590 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9591 Class, E->getIntroducerRange(), NewCallOpTSI,
9592 E->getCallOperator()->getLocEnd(),
9593 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009594 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009595
Faisal Vali2cba1332013-10-23 06:44:28 +00009596 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +00009597 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +00009598
Douglas Gregorb4328232012-02-14 00:00:48 +00009599 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +00009600 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009601 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009602
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009603 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +00009604 getSema().buildLambdaScope(LSI, NewCallOperator,
9605 E->getIntroducerRange(),
9606 E->getCaptureDefault(),
9607 E->getCaptureDefaultLoc(),
9608 E->hasExplicitParameters(),
9609 E->hasExplicitResultType(),
9610 E->isMutable());
9611
9612 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009613
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009614 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009615 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009616 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009617 CEnd = E->capture_end();
9618 C != CEnd; ++C) {
9619 // When we hit the first implicit capture, tell Sema that we've finished
9620 // the list of explicit captures.
9621 if (!FinishedExplicitCaptures && C->isImplicit()) {
9622 getSema().finishLambdaExplicitCaptures(LSI);
9623 FinishedExplicitCaptures = true;
9624 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009625
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009626 // Capturing 'this' is trivial.
9627 if (C->capturesThis()) {
9628 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9629 continue;
9630 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009631 // Captured expression will be recaptured during captured variables
9632 // rebuilding.
9633 if (C->capturesVLAType())
9634 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009635
Richard Smithba71c082013-05-16 06:20:58 +00009636 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +00009637 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009638 InitCaptureInfoTy InitExprTypePair =
9639 InitCaptureExprsAndTypes[C - E->capture_begin()];
9640 ExprResult Init = InitExprTypePair.first;
9641 QualType InitQualType = InitExprTypePair.second;
9642 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009643 Invalid = true;
9644 continue;
9645 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009646 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009647 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9648 OldVD->getLocation(), InitExprTypePair.second,
9649 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009650 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009651 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009652 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009653 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009654 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009655 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009656 continue;
9657 }
9658
9659 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9660
Douglas Gregor3e308b12012-02-14 19:27:52 +00009661 // Determine the capture kind for Sema.
9662 Sema::TryCaptureKind Kind
9663 = C->isImplicit()? Sema::TryCapture_Implicit
9664 : C->getCaptureKind() == LCK_ByCopy
9665 ? Sema::TryCapture_ExplicitByVal
9666 : Sema::TryCapture_ExplicitByRef;
9667 SourceLocation EllipsisLoc;
9668 if (C->isPackExpansion()) {
9669 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9670 bool ShouldExpand = false;
9671 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009672 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009673 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9674 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009675 Unexpanded,
9676 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009677 NumExpansions)) {
9678 Invalid = true;
9679 continue;
9680 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009681
Douglas Gregor3e308b12012-02-14 19:27:52 +00009682 if (ShouldExpand) {
9683 // The transform has determined that we should perform an expansion;
9684 // transform and capture each of the arguments.
9685 // expansion of the pattern. Do so.
9686 VarDecl *Pack = C->getCapturedVar();
9687 for (unsigned I = 0; I != *NumExpansions; ++I) {
9688 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9689 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009690 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009691 Pack));
9692 if (!CapturedVar) {
9693 Invalid = true;
9694 continue;
9695 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009696
Douglas Gregor3e308b12012-02-14 19:27:52 +00009697 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009698 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9699 }
Richard Smith9467be42014-06-06 17:33:35 +00009700
9701 // FIXME: Retain a pack expansion if RetainExpansion is true.
9702
Douglas Gregor3e308b12012-02-14 19:27:52 +00009703 continue;
9704 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009705
Douglas Gregor3e308b12012-02-14 19:27:52 +00009706 EllipsisLoc = C->getEllipsisLoc();
9707 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009708
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009709 // Transform the captured variable.
9710 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009711 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009712 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009713 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009714 Invalid = true;
9715 continue;
9716 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009717
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009718 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +00009719 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
9720 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009721 }
9722 if (!FinishedExplicitCaptures)
9723 getSema().finishLambdaExplicitCaptures(LSI);
9724
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009725 // Enter a new evaluation context to insulate the lambda from any
9726 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009727 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009728
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009729 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +00009730 StmtResult Body =
9731 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
9732
9733 // ActOnLambda* will pop the function scope for us.
9734 FuncScopeCleanup.disable();
9735
Douglas Gregorb4328232012-02-14 00:00:48 +00009736 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +00009737 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +00009738 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009739 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009740 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009741 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009742
Richard Smithc38498f2015-04-27 21:27:54 +00009743 // Copy the LSI before ActOnFinishFunctionBody removes it.
9744 // FIXME: This is dumb. Store the lambda information somewhere that outlives
9745 // the call operator.
9746 auto LSICopy = *LSI;
9747 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
9748 /*IsInstantiation*/ true);
9749 SavedContext.pop();
9750
9751 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
9752 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +00009753}
9754
9755template<typename Derived>
9756ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009757TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009758 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009759 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9760 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009761 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009762
Douglas Gregora16548e2009-08-11 05:31:07 +00009763 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009764 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009765 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009766 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009767 &ArgumentChanged))
9768 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009769
Douglas Gregora16548e2009-08-11 05:31:07 +00009770 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009771 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009772 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009773 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009774
Douglas Gregora16548e2009-08-11 05:31:07 +00009775 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009776 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009777 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009778 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009779 E->getRParenLoc());
9780}
Mike Stump11289f42009-09-09 15:08:12 +00009781
Douglas Gregora16548e2009-08-11 05:31:07 +00009782template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009783ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009784TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009785 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009786 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009787 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009788 Expr *OldBase;
9789 QualType BaseType;
9790 QualType ObjectType;
9791 if (!E->isImplicitAccess()) {
9792 OldBase = E->getBase();
9793 Base = getDerived().TransformExpr(OldBase);
9794 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009795 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009796
John McCall2d74de92009-12-01 22:10:20 +00009797 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009798 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009799 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009800 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009801 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009802 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009803 ObjectTy,
9804 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009805 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009806 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009807
John McCallba7bf592010-08-24 05:47:05 +00009808 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009809 BaseType = ((Expr*) Base.get())->getType();
9810 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009811 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009812 BaseType = getDerived().TransformType(E->getBaseType());
9813 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9814 }
Mike Stump11289f42009-09-09 15:08:12 +00009815
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009816 // Transform the first part of the nested-name-specifier that qualifies
9817 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009818 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009819 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009820 E->getFirstQualifierFoundInScope(),
9821 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009822
Douglas Gregore16af532011-02-28 18:50:33 +00009823 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009824 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009825 QualifierLoc
9826 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9827 ObjectType,
9828 FirstQualifierInScope);
9829 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009830 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009831 }
Mike Stump11289f42009-09-09 15:08:12 +00009832
Abramo Bagnara7945c982012-01-27 09:46:47 +00009833 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9834
John McCall31f82722010-11-12 08:19:04 +00009835 // TODO: If this is a conversion-function-id, verify that the
9836 // destination type name (if present) resolves the same way after
9837 // instantiation as it did in the local scope.
9838
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009839 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009840 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009841 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009842 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009843
John McCall2d74de92009-12-01 22:10:20 +00009844 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009845 // This is a reference to a member without an explicitly-specified
9846 // template argument list. Optimize for this common case.
9847 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009848 Base.get() == OldBase &&
9849 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009850 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009851 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009852 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009853 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009854
John McCallb268a282010-08-23 23:25:46 +00009855 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009856 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009857 E->isArrow(),
9858 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009859 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009860 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009861 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009862 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009863 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009864 }
9865
John McCall6b51f282009-11-23 01:53:49 +00009866 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009867 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9868 E->getNumTemplateArgs(),
9869 TransArgs))
9870 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009871
John McCallb268a282010-08-23 23:25:46 +00009872 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009873 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009874 E->isArrow(),
9875 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009876 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009877 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009878 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009879 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009880 &TransArgs);
9881}
9882
9883template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009884ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009885TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009886 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009887 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009888 QualType BaseType;
9889 if (!Old->isImplicitAccess()) {
9890 Base = getDerived().TransformExpr(Old->getBase());
9891 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009892 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009893 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009894 Old->isArrow());
9895 if (Base.isInvalid())
9896 return ExprError();
9897 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009898 } else {
9899 BaseType = getDerived().TransformType(Old->getBaseType());
9900 }
John McCall10eae182009-11-30 22:42:35 +00009901
Douglas Gregor0da1d432011-02-28 20:01:57 +00009902 NestedNameSpecifierLoc QualifierLoc;
9903 if (Old->getQualifierLoc()) {
9904 QualifierLoc
9905 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9906 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009907 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009908 }
9909
Abramo Bagnara7945c982012-01-27 09:46:47 +00009910 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9911
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009912 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009913 Sema::LookupOrdinaryName);
9914
9915 // Transform all the decls.
9916 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9917 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009918 NamedDecl *InstD = static_cast<NamedDecl*>(
9919 getDerived().TransformDecl(Old->getMemberLoc(),
9920 *I));
John McCall84d87672009-12-10 09:41:52 +00009921 if (!InstD) {
9922 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9923 // This can happen because of dependent hiding.
9924 if (isa<UsingShadowDecl>(*I))
9925 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009926 else {
9927 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009928 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009929 }
John McCall84d87672009-12-10 09:41:52 +00009930 }
John McCall10eae182009-11-30 22:42:35 +00009931
9932 // Expand using declarations.
9933 if (isa<UsingDecl>(InstD)) {
9934 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009935 for (auto *I : UD->shadows())
9936 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009937 continue;
9938 }
9939
9940 R.addDecl(InstD);
9941 }
9942
9943 R.resolveKind();
9944
Douglas Gregor9262f472010-04-27 18:19:34 +00009945 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009946 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009947 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009948 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009949 Old->getMemberLoc(),
9950 Old->getNamingClass()));
9951 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009952 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009953
Douglas Gregorda7be082010-04-27 16:10:10 +00009954 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009955 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009956
John McCall10eae182009-11-30 22:42:35 +00009957 TemplateArgumentListInfo TransArgs;
9958 if (Old->hasExplicitTemplateArgs()) {
9959 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9960 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009961 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9962 Old->getNumTemplateArgs(),
9963 TransArgs))
9964 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009965 }
John McCall38836f02010-01-15 08:34:02 +00009966
9967 // FIXME: to do this check properly, we will need to preserve the
9968 // first-qualifier-in-scope here, just in case we had a dependent
9969 // base (and therefore couldn't do the check) and a
9970 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009971 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009972
John McCallb268a282010-08-23 23:25:46 +00009973 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009974 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009975 Old->getOperatorLoc(),
9976 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009977 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009978 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009979 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009980 R,
9981 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009982 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009983}
9984
9985template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009986ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009987TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009988 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009989 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9990 if (SubExpr.isInvalid())
9991 return ExprError();
9992
9993 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009994 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009995
9996 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9997}
9998
9999template<typename Derived>
10000ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010001TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010002 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10003 if (Pattern.isInvalid())
10004 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010005
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010006 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010007 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010008
Douglas Gregorb8840002011-01-14 21:20:45 +000010009 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10010 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010011}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010012
10013template<typename Derived>
10014ExprResult
10015TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10016 // If E is not value-dependent, then nothing will change when we transform it.
10017 // Note: This is an instantiation-centric view.
10018 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010019 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010020
Richard Smithd784e682015-09-23 21:41:42 +000010021 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010022
Richard Smithd784e682015-09-23 21:41:42 +000010023 ArrayRef<TemplateArgument> PackArgs;
10024 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010025
Richard Smithd784e682015-09-23 21:41:42 +000010026 // Find the argument list to transform.
10027 if (E->isPartiallySubstituted()) {
10028 PackArgs = E->getPartialArguments();
10029 } else if (E->isValueDependent()) {
10030 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10031 bool ShouldExpand = false;
10032 bool RetainExpansion = false;
10033 Optional<unsigned> NumExpansions;
10034 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10035 Unexpanded,
10036 ShouldExpand, RetainExpansion,
10037 NumExpansions))
10038 return ExprError();
10039
10040 // If we need to expand the pack, build a template argument from it and
10041 // expand that.
10042 if (ShouldExpand) {
10043 auto *Pack = E->getPack();
10044 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10045 ArgStorage = getSema().Context.getPackExpansionType(
10046 getSema().Context.getTypeDeclType(TTPD), None);
10047 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10048 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10049 } else {
10050 auto *VD = cast<ValueDecl>(Pack);
10051 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10052 VK_RValue, E->getPackLoc());
10053 if (DRE.isInvalid())
10054 return ExprError();
10055 ArgStorage = new (getSema().Context) PackExpansionExpr(
10056 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10057 }
10058 PackArgs = ArgStorage;
10059 }
10060 }
10061
10062 // If we're not expanding the pack, just transform the decl.
10063 if (!PackArgs.size()) {
10064 auto *Pack = cast_or_null<NamedDecl>(
10065 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010066 if (!Pack)
10067 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010068 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10069 E->getPackLoc(),
10070 E->getRParenLoc(), None, None);
10071 }
10072
10073 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10074 E->getPackLoc());
10075 {
10076 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10077 typedef TemplateArgumentLocInventIterator<
10078 Derived, const TemplateArgument*> PackLocIterator;
10079 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10080 PackLocIterator(*this, PackArgs.end()),
10081 TransformedPackArgs, /*Uneval*/true))
10082 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010083 }
10084
Richard Smithd784e682015-09-23 21:41:42 +000010085 SmallVector<TemplateArgument, 8> Args;
10086 bool PartialSubstitution = false;
10087 for (auto &Loc : TransformedPackArgs.arguments()) {
10088 Args.push_back(Loc.getArgument());
10089 if (Loc.getArgument().isPackExpansion())
10090 PartialSubstitution = true;
10091 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010092
Richard Smithd784e682015-09-23 21:41:42 +000010093 if (PartialSubstitution)
10094 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10095 E->getPackLoc(),
10096 E->getRParenLoc(), None, Args);
10097
10098 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010099 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010100 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010101}
10102
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010103template<typename Derived>
10104ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010105TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10106 SubstNonTypeTemplateParmPackExpr *E) {
10107 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010108 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010109}
10110
10111template<typename Derived>
10112ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010113TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10114 SubstNonTypeTemplateParmExpr *E) {
10115 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010116 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010117}
10118
10119template<typename Derived>
10120ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010121TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10122 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010123 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010124}
10125
10126template<typename Derived>
10127ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010128TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10129 MaterializeTemporaryExpr *E) {
10130 return getDerived().TransformExpr(E->GetTemporaryExpr());
10131}
Chad Rosier1dcde962012-08-08 18:46:20 +000010132
Douglas Gregorfe314812011-06-21 17:03:29 +000010133template<typename Derived>
10134ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010135TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10136 Expr *Pattern = E->getPattern();
10137
10138 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10139 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10140 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10141
10142 // Determine whether the set of unexpanded parameter packs can and should
10143 // be expanded.
10144 bool Expand = true;
10145 bool RetainExpansion = false;
10146 Optional<unsigned> NumExpansions;
10147 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10148 Pattern->getSourceRange(),
10149 Unexpanded,
10150 Expand, RetainExpansion,
10151 NumExpansions))
10152 return true;
10153
10154 if (!Expand) {
10155 // Do not expand any packs here, just transform and rebuild a fold
10156 // expression.
10157 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10158
10159 ExprResult LHS =
10160 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10161 if (LHS.isInvalid())
10162 return true;
10163
10164 ExprResult RHS =
10165 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10166 if (RHS.isInvalid())
10167 return true;
10168
10169 if (!getDerived().AlwaysRebuild() &&
10170 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10171 return E;
10172
10173 return getDerived().RebuildCXXFoldExpr(
10174 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10175 RHS.get(), E->getLocEnd());
10176 }
10177
10178 // The transform has determined that we should perform an elementwise
10179 // expansion of the pattern. Do so.
10180 ExprResult Result = getDerived().TransformExpr(E->getInit());
10181 if (Result.isInvalid())
10182 return true;
10183 bool LeftFold = E->isLeftFold();
10184
10185 // If we're retaining an expansion for a right fold, it is the innermost
10186 // component and takes the init (if any).
10187 if (!LeftFold && RetainExpansion) {
10188 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10189
10190 ExprResult Out = getDerived().TransformExpr(Pattern);
10191 if (Out.isInvalid())
10192 return true;
10193
10194 Result = getDerived().RebuildCXXFoldExpr(
10195 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10196 Result.get(), E->getLocEnd());
10197 if (Result.isInvalid())
10198 return true;
10199 }
10200
10201 for (unsigned I = 0; I != *NumExpansions; ++I) {
10202 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10203 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10204 ExprResult Out = getDerived().TransformExpr(Pattern);
10205 if (Out.isInvalid())
10206 return true;
10207
10208 if (Out.get()->containsUnexpandedParameterPack()) {
10209 // We still have a pack; retain a pack expansion for this slice.
10210 Result = getDerived().RebuildCXXFoldExpr(
10211 E->getLocStart(),
10212 LeftFold ? Result.get() : Out.get(),
10213 E->getOperator(), E->getEllipsisLoc(),
10214 LeftFold ? Out.get() : Result.get(),
10215 E->getLocEnd());
10216 } else if (Result.isUsable()) {
10217 // We've got down to a single element; build a binary operator.
10218 Result = getDerived().RebuildBinaryOperator(
10219 E->getEllipsisLoc(), E->getOperator(),
10220 LeftFold ? Result.get() : Out.get(),
10221 LeftFold ? Out.get() : Result.get());
10222 } else
10223 Result = Out;
10224
10225 if (Result.isInvalid())
10226 return true;
10227 }
10228
10229 // If we're retaining an expansion for a left fold, it is the outermost
10230 // component and takes the complete expansion so far as its init (if any).
10231 if (LeftFold && RetainExpansion) {
10232 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10233
10234 ExprResult Out = getDerived().TransformExpr(Pattern);
10235 if (Out.isInvalid())
10236 return true;
10237
10238 Result = getDerived().RebuildCXXFoldExpr(
10239 E->getLocStart(), Result.get(),
10240 E->getOperator(), E->getEllipsisLoc(),
10241 Out.get(), E->getLocEnd());
10242 if (Result.isInvalid())
10243 return true;
10244 }
10245
10246 // If we had no init and an empty pack, and we're not retaining an expansion,
10247 // then produce a fallback value or error.
10248 if (Result.isUnset())
10249 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10250 E->getOperator());
10251
10252 return Result;
10253}
10254
10255template<typename Derived>
10256ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010257TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10258 CXXStdInitializerListExpr *E) {
10259 return getDerived().TransformExpr(E->getSubExpr());
10260}
10261
10262template<typename Derived>
10263ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010264TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010265 return SemaRef.MaybeBindToTemporary(E);
10266}
10267
10268template<typename Derived>
10269ExprResult
10270TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010271 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010272}
10273
10274template<typename Derived>
10275ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010276TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10277 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10278 if (SubExpr.isInvalid())
10279 return ExprError();
10280
10281 if (!getDerived().AlwaysRebuild() &&
10282 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010283 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010284
10285 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010286}
10287
10288template<typename Derived>
10289ExprResult
10290TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10291 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010292 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010293 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010294 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010295 /*IsCall=*/false, Elements, &ArgChanged))
10296 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010297
Ted Kremeneke65b0862012-03-06 20:05:56 +000010298 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10299 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010300
Ted Kremeneke65b0862012-03-06 20:05:56 +000010301 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10302 Elements.data(),
10303 Elements.size());
10304}
10305
10306template<typename Derived>
10307ExprResult
10308TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010309 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010310 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010311 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010312 bool ArgChanged = false;
10313 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10314 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010315
Ted Kremeneke65b0862012-03-06 20:05:56 +000010316 if (OrigElement.isPackExpansion()) {
10317 // This key/value element is a pack expansion.
10318 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10319 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10320 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10321 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10322
10323 // Determine whether the set of unexpanded parameter packs can
10324 // and should be expanded.
10325 bool Expand = true;
10326 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010327 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10328 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010329 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10330 OrigElement.Value->getLocEnd());
10331 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10332 PatternRange,
10333 Unexpanded,
10334 Expand, RetainExpansion,
10335 NumExpansions))
10336 return ExprError();
10337
10338 if (!Expand) {
10339 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010340 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010341 // expansion.
10342 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10343 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10344 if (Key.isInvalid())
10345 return ExprError();
10346
10347 if (Key.get() != OrigElement.Key)
10348 ArgChanged = true;
10349
10350 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10351 if (Value.isInvalid())
10352 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010353
Ted Kremeneke65b0862012-03-06 20:05:56 +000010354 if (Value.get() != OrigElement.Value)
10355 ArgChanged = true;
10356
Chad Rosier1dcde962012-08-08 18:46:20 +000010357 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010358 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10359 };
10360 Elements.push_back(Expansion);
10361 continue;
10362 }
10363
10364 // Record right away that the argument was changed. This needs
10365 // to happen even if the array expands to nothing.
10366 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010367
Ted Kremeneke65b0862012-03-06 20:05:56 +000010368 // The transform has determined that we should perform an elementwise
10369 // expansion of the pattern. Do so.
10370 for (unsigned I = 0; I != *NumExpansions; ++I) {
10371 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10372 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10373 if (Key.isInvalid())
10374 return ExprError();
10375
10376 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10377 if (Value.isInvalid())
10378 return ExprError();
10379
Chad Rosier1dcde962012-08-08 18:46:20 +000010380 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010381 Key.get(), Value.get(), SourceLocation(), NumExpansions
10382 };
10383
10384 // If any unexpanded parameter packs remain, we still have a
10385 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010386 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010387 if (Key.get()->containsUnexpandedParameterPack() ||
10388 Value.get()->containsUnexpandedParameterPack())
10389 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010390
Ted Kremeneke65b0862012-03-06 20:05:56 +000010391 Elements.push_back(Element);
10392 }
10393
Richard Smith9467be42014-06-06 17:33:35 +000010394 // FIXME: Retain a pack expansion if RetainExpansion is true.
10395
Ted Kremeneke65b0862012-03-06 20:05:56 +000010396 // We've finished with this pack expansion.
10397 continue;
10398 }
10399
10400 // Transform and check key.
10401 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10402 if (Key.isInvalid())
10403 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010404
Ted Kremeneke65b0862012-03-06 20:05:56 +000010405 if (Key.get() != OrigElement.Key)
10406 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010407
Ted Kremeneke65b0862012-03-06 20:05:56 +000010408 // Transform and check value.
10409 ExprResult Value
10410 = getDerived().TransformExpr(OrigElement.Value);
10411 if (Value.isInvalid())
10412 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010413
Ted Kremeneke65b0862012-03-06 20:05:56 +000010414 if (Value.get() != OrigElement.Value)
10415 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010416
10417 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010418 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010419 };
10420 Elements.push_back(Element);
10421 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010422
Ted Kremeneke65b0862012-03-06 20:05:56 +000010423 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10424 return SemaRef.MaybeBindToTemporary(E);
10425
10426 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
10427 Elements.data(),
10428 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +000010429}
10430
Mike Stump11289f42009-09-09 15:08:12 +000010431template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010432ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010433TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010434 TypeSourceInfo *EncodedTypeInfo
10435 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10436 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010437 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010438
Douglas Gregora16548e2009-08-11 05:31:07 +000010439 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010440 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010441 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010442
10443 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010444 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010445 E->getRParenLoc());
10446}
Mike Stump11289f42009-09-09 15:08:12 +000010447
Douglas Gregora16548e2009-08-11 05:31:07 +000010448template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010449ExprResult TreeTransform<Derived>::
10450TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010451 // This is a kind of implicit conversion, and it needs to get dropped
10452 // and recomputed for the same general reasons that ImplicitCastExprs
10453 // do, as well a more specific one: this expression is only valid when
10454 // it appears *immediately* as an argument expression.
10455 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010456}
10457
10458template<typename Derived>
10459ExprResult TreeTransform<Derived>::
10460TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010461 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010462 = getDerived().TransformType(E->getTypeInfoAsWritten());
10463 if (!TSInfo)
10464 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010465
John McCall31168b02011-06-15 23:02:42 +000010466 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010467 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010468 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010469
John McCall31168b02011-06-15 23:02:42 +000010470 if (!getDerived().AlwaysRebuild() &&
10471 TSInfo == E->getTypeInfoAsWritten() &&
10472 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010473 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010474
John McCall31168b02011-06-15 23:02:42 +000010475 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010476 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010477 Result.get());
10478}
10479
10480template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010481ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010482TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010483 // Transform arguments.
10484 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010485 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010486 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010487 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010488 &ArgChanged))
10489 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010490
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010491 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10492 // Class message: transform the receiver type.
10493 TypeSourceInfo *ReceiverTypeInfo
10494 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10495 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010496 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010497
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010498 // If nothing changed, just retain the existing message send.
10499 if (!getDerived().AlwaysRebuild() &&
10500 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010501 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010502
10503 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010504 SmallVector<SourceLocation, 16> SelLocs;
10505 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010506 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10507 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010508 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010509 E->getMethodDecl(),
10510 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010511 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010512 E->getRightLoc());
10513 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010514 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10515 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10516 // Build a new class message send to 'super'.
10517 SmallVector<SourceLocation, 16> SelLocs;
10518 E->getSelectorLocs(SelLocs);
10519 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10520 E->getSelector(),
10521 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000010522 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010523 E->getMethodDecl(),
10524 E->getLeftLoc(),
10525 Args,
10526 E->getRightLoc());
10527 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010528
10529 // Instance message: transform the receiver
10530 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10531 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010532 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010533 = getDerived().TransformExpr(E->getInstanceReceiver());
10534 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010535 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010536
10537 // If nothing changed, just retain the existing message send.
10538 if (!getDerived().AlwaysRebuild() &&
10539 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010540 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010541
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010542 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010543 SmallVector<SourceLocation, 16> SelLocs;
10544 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010545 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010546 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010547 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010548 E->getMethodDecl(),
10549 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010550 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010551 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010552}
10553
Mike Stump11289f42009-09-09 15:08:12 +000010554template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010555ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010556TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010557 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010558}
10559
Mike Stump11289f42009-09-09 15:08:12 +000010560template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010561ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010562TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010563 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010564}
10565
Mike Stump11289f42009-09-09 15:08:12 +000010566template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010567ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010568TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010569 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010570 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010571 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010572 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010573
10574 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010575
Douglas Gregord51d90d2010-04-26 20:11:03 +000010576 // If nothing changed, just retain the existing expression.
10577 if (!getDerived().AlwaysRebuild() &&
10578 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010579 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010580
John McCallb268a282010-08-23 23:25:46 +000010581 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010582 E->getLocation(),
10583 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010584}
10585
Mike Stump11289f42009-09-09 15:08:12 +000010586template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010587ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010588TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010589 // 'super' and types never change. Property never changes. Just
10590 // retain the existing expression.
10591 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010592 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010593
Douglas Gregor9faee212010-04-26 20:47:02 +000010594 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010595 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010596 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010597 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010598
Douglas Gregor9faee212010-04-26 20:47:02 +000010599 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010600
Douglas Gregor9faee212010-04-26 20:47:02 +000010601 // If nothing changed, just retain the existing expression.
10602 if (!getDerived().AlwaysRebuild() &&
10603 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010604 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010605
John McCallb7bd14f2010-12-02 01:19:52 +000010606 if (E->isExplicitProperty())
10607 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10608 E->getExplicitProperty(),
10609 E->getLocation());
10610
10611 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010612 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010613 E->getImplicitPropertyGetter(),
10614 E->getImplicitPropertySetter(),
10615 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010616}
10617
Mike Stump11289f42009-09-09 15:08:12 +000010618template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010619ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010620TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10621 // Transform the base expression.
10622 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10623 if (Base.isInvalid())
10624 return ExprError();
10625
10626 // Transform the key expression.
10627 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10628 if (Key.isInvalid())
10629 return ExprError();
10630
10631 // If nothing changed, just retain the existing expression.
10632 if (!getDerived().AlwaysRebuild() &&
10633 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010634 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010635
Chad Rosier1dcde962012-08-08 18:46:20 +000010636 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010637 Base.get(), Key.get(),
10638 E->getAtIndexMethodDecl(),
10639 E->setAtIndexMethodDecl());
10640}
10641
10642template<typename Derived>
10643ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010644TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010645 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010646 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010647 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010648 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010649
Douglas Gregord51d90d2010-04-26 20:11:03 +000010650 // If nothing changed, just retain the existing expression.
10651 if (!getDerived().AlwaysRebuild() &&
10652 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010653 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010654
John McCallb268a282010-08-23 23:25:46 +000010655 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010656 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010657 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010658}
10659
Mike Stump11289f42009-09-09 15:08:12 +000010660template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010661ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010662TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010663 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010664 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010665 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010666 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010667 SubExprs, &ArgumentChanged))
10668 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010669
Douglas Gregora16548e2009-08-11 05:31:07 +000010670 if (!getDerived().AlwaysRebuild() &&
10671 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010672 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010673
Douglas Gregora16548e2009-08-11 05:31:07 +000010674 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010675 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010676 E->getRParenLoc());
10677}
10678
Mike Stump11289f42009-09-09 15:08:12 +000010679template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010680ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010681TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10682 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10683 if (SrcExpr.isInvalid())
10684 return ExprError();
10685
10686 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10687 if (!Type)
10688 return ExprError();
10689
10690 if (!getDerived().AlwaysRebuild() &&
10691 Type == E->getTypeSourceInfo() &&
10692 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010693 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010694
10695 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10696 SrcExpr.get(), Type,
10697 E->getRParenLoc());
10698}
10699
10700template<typename Derived>
10701ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010702TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000010703 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000010704
Craig Topperc3ec1492014-05-26 06:22:03 +000010705 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000010706 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
10707
10708 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000010709 blockScope->TheDecl->setBlockMissingReturnType(
10710 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000010711
Chris Lattner01cf8db2011-07-20 06:58:45 +000010712 SmallVector<ParmVarDecl*, 4> params;
10713 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000010714
Fariborz Jahanian1babe772010-07-09 18:44:02 +000010715 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000010716 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
10717 oldBlock->param_begin(),
10718 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010719 nullptr, paramTypes, &params)) {
10720 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010721 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010722 }
John McCall490112f2011-02-04 18:33:18 +000010723
Jordan Rosea0a86be2013-03-08 22:25:36 +000010724 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000010725 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000010726 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000010727
Jordan Rose5c382722013-03-08 21:51:21 +000010728 QualType functionType =
10729 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010730 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000010731 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000010732
10733 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000010734 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000010735 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000010736
10737 if (!oldBlock->blockMissingReturnType()) {
10738 blockScope->HasImplicitReturnType = false;
10739 blockScope->ReturnType = exprResultType;
10740 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010741
John McCall3882ace2011-01-05 12:14:39 +000010742 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000010743 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010744 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010745 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000010746 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010747 }
John McCall3882ace2011-01-05 12:14:39 +000010748
John McCall490112f2011-02-04 18:33:18 +000010749#ifndef NDEBUG
10750 // In builds with assertions, make sure that we captured everything we
10751 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010752 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000010753 for (const auto &I : oldBlock->captures()) {
10754 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000010755
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010756 // Ignore parameter packs.
10757 if (isa<ParmVarDecl>(oldCapture) &&
10758 cast<ParmVarDecl>(oldCapture)->isParameterPack())
10759 continue;
John McCall490112f2011-02-04 18:33:18 +000010760
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010761 VarDecl *newCapture =
10762 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
10763 oldCapture));
10764 assert(blockScope->CaptureMap.count(newCapture));
10765 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010766 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000010767 }
10768#endif
10769
10770 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010771 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000010772}
10773
Mike Stump11289f42009-09-09 15:08:12 +000010774template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010775ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000010776TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010777 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010778}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010779
10780template<typename Derived>
10781ExprResult
10782TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010783 QualType RetTy = getDerived().TransformType(E->getType());
10784 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010785 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010786 SubExprs.reserve(E->getNumSubExprs());
10787 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10788 SubExprs, &ArgumentChanged))
10789 return ExprError();
10790
10791 if (!getDerived().AlwaysRebuild() &&
10792 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010793 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010794
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010795 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010796 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010797}
Chad Rosier1dcde962012-08-08 18:46:20 +000010798
Douglas Gregora16548e2009-08-11 05:31:07 +000010799//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010800// Type reconstruction
10801//===----------------------------------------------------------------------===//
10802
Mike Stump11289f42009-09-09 15:08:12 +000010803template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010804QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10805 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010806 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010807 getDerived().getBaseEntity());
10808}
10809
Mike Stump11289f42009-09-09 15:08:12 +000010810template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010811QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10812 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010813 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010814 getDerived().getBaseEntity());
10815}
10816
Mike Stump11289f42009-09-09 15:08:12 +000010817template<typename Derived>
10818QualType
John McCall70dd5f62009-10-30 00:06:24 +000010819TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10820 bool WrittenAsLValue,
10821 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010822 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010823 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010824}
10825
10826template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010827QualType
John McCall70dd5f62009-10-30 00:06:24 +000010828TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10829 QualType ClassType,
10830 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010831 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10832 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010833}
10834
10835template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000010836QualType TreeTransform<Derived>::RebuildObjCObjectType(
10837 QualType BaseType,
10838 SourceLocation Loc,
10839 SourceLocation TypeArgsLAngleLoc,
10840 ArrayRef<TypeSourceInfo *> TypeArgs,
10841 SourceLocation TypeArgsRAngleLoc,
10842 SourceLocation ProtocolLAngleLoc,
10843 ArrayRef<ObjCProtocolDecl *> Protocols,
10844 ArrayRef<SourceLocation> ProtocolLocs,
10845 SourceLocation ProtocolRAngleLoc) {
10846 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
10847 TypeArgs, TypeArgsRAngleLoc,
10848 ProtocolLAngleLoc, Protocols, ProtocolLocs,
10849 ProtocolRAngleLoc,
10850 /*FailOnError=*/true);
10851}
10852
10853template<typename Derived>
10854QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
10855 QualType PointeeType,
10856 SourceLocation Star) {
10857 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
10858}
10859
10860template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010861QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010862TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10863 ArrayType::ArraySizeModifier SizeMod,
10864 const llvm::APInt *Size,
10865 Expr *SizeExpr,
10866 unsigned IndexTypeQuals,
10867 SourceRange BracketsRange) {
10868 if (SizeExpr || !Size)
10869 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10870 IndexTypeQuals, BracketsRange,
10871 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010872
10873 QualType Types[] = {
10874 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10875 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10876 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010877 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010878 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010879 QualType SizeType;
10880 for (unsigned I = 0; I != NumTypes; ++I)
10881 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10882 SizeType = Types[I];
10883 break;
10884 }
Mike Stump11289f42009-09-09 15:08:12 +000010885
Eli Friedman9562f392012-01-25 23:20:27 +000010886 // Note that we can return a VariableArrayType here in the case where
10887 // the element type was a dependent VariableArrayType.
10888 IntegerLiteral *ArraySize
10889 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10890 /*FIXME*/BracketsRange.getBegin());
10891 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010892 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010893 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010894}
Mike Stump11289f42009-09-09 15:08:12 +000010895
Douglas Gregord6ff3322009-08-04 16:50:30 +000010896template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010897QualType
10898TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010899 ArrayType::ArraySizeModifier SizeMod,
10900 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010901 unsigned IndexTypeQuals,
10902 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010903 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010904 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010905}
10906
10907template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010908QualType
Mike Stump11289f42009-09-09 15:08:12 +000010909TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010910 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010911 unsigned IndexTypeQuals,
10912 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010913 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010914 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010915}
Mike Stump11289f42009-09-09 15:08:12 +000010916
Douglas Gregord6ff3322009-08-04 16:50:30 +000010917template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010918QualType
10919TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010920 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010921 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010922 unsigned IndexTypeQuals,
10923 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010924 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010925 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010926 IndexTypeQuals, BracketsRange);
10927}
10928
10929template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010930QualType
10931TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010932 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010933 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010934 unsigned IndexTypeQuals,
10935 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010936 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010937 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010938 IndexTypeQuals, BracketsRange);
10939}
10940
10941template<typename Derived>
10942QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010943 unsigned NumElements,
10944 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010945 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010946 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010947}
Mike Stump11289f42009-09-09 15:08:12 +000010948
Douglas Gregord6ff3322009-08-04 16:50:30 +000010949template<typename Derived>
10950QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10951 unsigned NumElements,
10952 SourceLocation AttributeLoc) {
10953 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10954 NumElements, true);
10955 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010956 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10957 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010958 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010959}
Mike Stump11289f42009-09-09 15:08:12 +000010960
Douglas Gregord6ff3322009-08-04 16:50:30 +000010961template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010962QualType
10963TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010964 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010965 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010966 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010967}
Mike Stump11289f42009-09-09 15:08:12 +000010968
Douglas Gregord6ff3322009-08-04 16:50:30 +000010969template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010970QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10971 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010972 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010973 const FunctionProtoType::ExtProtoInfo &EPI) {
10974 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010975 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010976 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010977 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010978}
Mike Stump11289f42009-09-09 15:08:12 +000010979
Douglas Gregord6ff3322009-08-04 16:50:30 +000010980template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010981QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10982 return SemaRef.Context.getFunctionNoProtoType(T);
10983}
10984
10985template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010986QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10987 assert(D && "no decl found");
10988 if (D->isInvalidDecl()) return QualType();
10989
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010990 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010991 TypeDecl *Ty;
10992 if (isa<UsingDecl>(D)) {
10993 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010994 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010995 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10996
10997 // A valid resolved using typename decl points to exactly one type decl.
10998 assert(++Using->shadow_begin() == Using->shadow_end());
10999 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011000
John McCallb96ec562009-12-04 22:46:56 +000011001 } else {
11002 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11003 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11004 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11005 }
11006
11007 return SemaRef.Context.getTypeDeclType(Ty);
11008}
11009
11010template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011011QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11012 SourceLocation Loc) {
11013 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011014}
11015
11016template<typename Derived>
11017QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11018 return SemaRef.Context.getTypeOfType(Underlying);
11019}
11020
11021template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011022QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11023 SourceLocation Loc) {
11024 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011025}
11026
11027template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011028QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11029 UnaryTransformType::UTTKind UKind,
11030 SourceLocation Loc) {
11031 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11032}
11033
11034template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011035QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011036 TemplateName Template,
11037 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011038 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011039 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011040}
Mike Stump11289f42009-09-09 15:08:12 +000011041
Douglas Gregor1135c352009-08-06 05:28:30 +000011042template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011043QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11044 SourceLocation KWLoc) {
11045 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11046}
11047
11048template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011049TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011050TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011051 bool TemplateKW,
11052 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011053 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011054 Template);
11055}
11056
11057template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011058TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011059TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11060 const IdentifierInfo &Name,
11061 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011062 QualType ObjectType,
11063 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011064 UnqualifiedId TemplateName;
11065 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011066 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011067 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011068 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011069 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011070 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011071 /*EnteringContext=*/false,
11072 Template);
John McCall31f82722010-11-12 08:19:04 +000011073 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011074}
Mike Stump11289f42009-09-09 15:08:12 +000011075
Douglas Gregora16548e2009-08-11 05:31:07 +000011076template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011077TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011078TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011079 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011080 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011081 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011082 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011083 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011084 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011085 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011086 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011087 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011088 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011089 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011090 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011091 /*EnteringContext=*/false,
11092 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011093 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011094}
Chad Rosier1dcde962012-08-08 18:46:20 +000011095
Douglas Gregor71395fa2009-11-04 00:56:37 +000011096template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011097ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011098TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11099 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011100 Expr *OrigCallee,
11101 Expr *First,
11102 Expr *Second) {
11103 Expr *Callee = OrigCallee->IgnoreParenCasts();
11104 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011105
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011106 if (First->getObjectKind() == OK_ObjCProperty) {
11107 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11108 if (BinaryOperator::isAssignmentOp(Opc))
11109 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11110 First, Second);
11111 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11112 if (Result.isInvalid())
11113 return ExprError();
11114 First = Result.get();
11115 }
11116
11117 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11118 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11119 if (Result.isInvalid())
11120 return ExprError();
11121 Second = Result.get();
11122 }
11123
Douglas Gregora16548e2009-08-11 05:31:07 +000011124 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011125 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011126 if (!First->getType()->isOverloadableType() &&
11127 !Second->getType()->isOverloadableType())
11128 return getSema().CreateBuiltinArraySubscriptExpr(First,
11129 Callee->getLocStart(),
11130 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011131 } else if (Op == OO_Arrow) {
11132 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011133 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11134 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011135 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011136 // The argument is not of overloadable type, so try to create a
11137 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011138 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011139 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011140
John McCallb268a282010-08-23 23:25:46 +000011141 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011142 }
11143 } else {
John McCallb268a282010-08-23 23:25:46 +000011144 if (!First->getType()->isOverloadableType() &&
11145 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011146 // Neither of the arguments is an overloadable type, so try to
11147 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011148 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011149 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011150 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011151 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011152 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011153
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011154 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011155 }
11156 }
Mike Stump11289f42009-09-09 15:08:12 +000011157
11158 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011159 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011160 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011161
John McCallb268a282010-08-23 23:25:46 +000011162 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011163 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011164 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011165 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011166 // If we've resolved this to a particular non-member function, just call
11167 // that function. If we resolved it to a member function,
11168 // CreateOverloaded* will find that function for us.
11169 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11170 if (!isa<CXXMethodDecl>(ND))
11171 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011172 }
Mike Stump11289f42009-09-09 15:08:12 +000011173
Douglas Gregora16548e2009-08-11 05:31:07 +000011174 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011175 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011176 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011177
Douglas Gregora16548e2009-08-11 05:31:07 +000011178 // Create the overloaded operator invocation for unary operators.
11179 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011180 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011181 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011182 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011183 }
Mike Stump11289f42009-09-09 15:08:12 +000011184
Douglas Gregore9d62932011-07-15 16:25:15 +000011185 if (Op == OO_Subscript) {
11186 SourceLocation LBrace;
11187 SourceLocation RBrace;
11188
11189 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011190 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011191 LBrace = SourceLocation::getFromRawEncoding(
11192 NameLoc.CXXOperatorName.BeginOpNameLoc);
11193 RBrace = SourceLocation::getFromRawEncoding(
11194 NameLoc.CXXOperatorName.EndOpNameLoc);
11195 } else {
11196 LBrace = Callee->getLocStart();
11197 RBrace = OpLoc;
11198 }
11199
11200 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11201 First, Second);
11202 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011203
Douglas Gregora16548e2009-08-11 05:31:07 +000011204 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011205 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011206 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011207 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11208 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011209 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011210
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011211 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011212}
Mike Stump11289f42009-09-09 15:08:12 +000011213
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011214template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011215ExprResult
John McCallb268a282010-08-23 23:25:46 +000011216TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011217 SourceLocation OperatorLoc,
11218 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011219 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011220 TypeSourceInfo *ScopeType,
11221 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011222 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011223 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011224 QualType BaseType = Base->getType();
11225 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011226 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011227 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011228 !BaseType->getAs<PointerType>()->getPointeeType()
11229 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011230 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011231 return SemaRef.BuildPseudoDestructorExpr(
11232 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11233 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011234 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011235
Douglas Gregor678f90d2010-02-25 01:56:36 +000011236 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011237 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11238 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11239 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11240 NameInfo.setNamedTypeInfo(DestroyedType);
11241
Richard Smith8e4a3862012-05-15 06:15:11 +000011242 // The scope type is now known to be a valid nested name specifier
11243 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011244 if (ScopeType) {
11245 if (!ScopeType->getType()->getAs<TagType>()) {
11246 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11247 diag::err_expected_class_or_namespace)
11248 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11249 return ExprError();
11250 }
11251 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11252 CCLoc);
11253 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011254
Abramo Bagnara7945c982012-01-27 09:46:47 +000011255 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011256 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011257 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011258 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011259 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011260 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000011261 /*TemplateArgs*/ nullptr,
11262 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011263}
11264
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011265template<typename Derived>
11266StmtResult
11267TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011268 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011269 CapturedDecl *CD = S->getCapturedDecl();
11270 unsigned NumParams = CD->getNumParams();
11271 unsigned ContextParamPos = CD->getContextParamPosition();
11272 SmallVector<Sema::CapturedParamNameType, 4> Params;
11273 for (unsigned I = 0; I < NumParams; ++I) {
11274 if (I != ContextParamPos) {
11275 Params.push_back(
11276 std::make_pair(
11277 CD->getParam(I)->getName(),
11278 getDerived().TransformType(CD->getParam(I)->getType())));
11279 } else {
11280 Params.push_back(std::make_pair(StringRef(), QualType()));
11281 }
11282 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011283 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011284 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011285 StmtResult Body;
11286 {
11287 Sema::CompoundScopeRAII CompoundScope(getSema());
11288 Body = getDerived().TransformStmt(S->getCapturedStmt());
11289 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011290
11291 if (Body.isInvalid()) {
11292 getSema().ActOnCapturedRegionError();
11293 return StmtError();
11294 }
11295
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011296 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011297}
11298
Douglas Gregord6ff3322009-08-04 16:50:30 +000011299} // end namespace clang
11300
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000011301#endif