blob: 799127e50be1ccd029743110f340cf01f9d82753 [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,
507 TemplateArgumentLoc &Output);
508
Douglas Gregor62e06f22010-12-20 17:31:10 +0000509 /// \brief Transform the given set of template arguments.
510 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000511 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000512 /// in the input set using \c TransformTemplateArgument(), and appends
513 /// the transformed arguments to the output list.
514 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000515 /// Note that this overload of \c TransformTemplateArguments() is merely
516 /// a convenience function. Subclasses that wish to override this behavior
517 /// should override the iterator-based member template version.
518 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000519 /// \param Inputs The set of template arguments to be transformed.
520 ///
521 /// \param NumInputs The number of template arguments in \p Inputs.
522 ///
523 /// \param Outputs The set of transformed template arguments output by this
524 /// routine.
525 ///
526 /// Returns true if an error occurred.
527 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
528 unsigned NumInputs,
Douglas Gregorfe921a72010-12-20 23:36:19 +0000529 TemplateArgumentListInfo &Outputs) {
530 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs);
531 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000532
533 /// \brief Transform the given set of template arguments.
534 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000535 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000536 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000537 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000538 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000539 /// \param First An iterator to the first template argument.
540 ///
541 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000542 ///
543 /// \param Outputs The set of transformed template arguments output by this
544 /// routine.
545 ///
546 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000547 template<typename InputIterator>
548 bool TransformTemplateArguments(InputIterator First,
549 InputIterator Last,
550 TemplateArgumentListInfo &Outputs);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000551
John McCall0ad16662009-10-29 08:12:44 +0000552 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
553 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
554 TemplateArgumentLoc &ArgLoc);
555
John McCallbcd03502009-12-07 02:54:59 +0000556 /// \brief Fakes up a TypeSourceInfo for a type.
557 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
558 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000559 getDerived().getBaseLocation());
560 }
Mike Stump11289f42009-09-09 15:08:12 +0000561
John McCall550e0c22009-10-21 00:40:46 +0000562#define ABSTRACT_TYPELOC(CLASS, PARENT)
563#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000564 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000565#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000566
Richard Smith2e321552014-11-12 02:00:47 +0000567 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000568 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
569 FunctionProtoTypeLoc TL,
570 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000571 unsigned ThisTypeQuals,
572 Fn TransformExceptionSpec);
573
574 bool TransformExceptionSpec(SourceLocation Loc,
575 FunctionProtoType::ExceptionSpecInfo &ESI,
576 SmallVectorImpl<QualType> &Exceptions,
577 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000578
David Majnemerfad8f482013-10-15 09:33:02 +0000579 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000580
Chad Rosier1dcde962012-08-08 18:46:20 +0000581 QualType
John McCall31f82722010-11-12 08:19:04 +0000582 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
583 TemplateSpecializationTypeLoc TL,
584 TemplateName Template);
585
Chad Rosier1dcde962012-08-08 18:46:20 +0000586 QualType
John McCall31f82722010-11-12 08:19:04 +0000587 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
588 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000589 TemplateName Template,
590 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000591
Nico Weberc153d242014-07-28 00:02:09 +0000592 QualType TransformDependentTemplateSpecializationType(
593 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
594 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000595
John McCall58f10c32010-03-11 09:03:00 +0000596 /// \brief Transforms the parameters of a function type into the
597 /// given vectors.
598 ///
599 /// The result vectors should be kept in sync; null entries in the
600 /// variables vector are acceptable.
601 ///
602 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000603 bool TransformFunctionTypeParams(SourceLocation Loc,
604 ParmVarDecl **Params, unsigned NumParams,
605 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000606 SmallVectorImpl<QualType> &PTypes,
607 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000608
609 /// \brief Transforms a single function-type parameter. Return null
610 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000611 ///
612 /// \param indexAdjustment - A number to add to the parameter's
613 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000614 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000615 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000616 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000617 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000618
John McCall31f82722010-11-12 08:19:04 +0000619 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000620
John McCalldadc5752010-08-24 06:29:42 +0000621 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
622 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000623
Faisal Vali2cba1332013-10-23 06:44:28 +0000624 TemplateParameterList *TransformTemplateParameterList(
625 TemplateParameterList *TPL) {
626 return TPL;
627 }
628
Richard Smithdb2630f2012-10-21 03:28:35 +0000629 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000630
Richard Smithdb2630f2012-10-21 03:28:35 +0000631 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000632 bool IsAddressOfOperand,
633 TypeSourceInfo **RecoveryTSI);
634
635 ExprResult TransformParenDependentScopeDeclRefExpr(
636 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
637 TypeSourceInfo **RecoveryTSI);
638
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000639 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000640
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000641// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
642// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000643#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000644 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000645 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000646#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000647 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000648 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000649#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000650#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000651
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000652#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000653 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000654 OMPClause *Transform ## Class(Class *S);
655#include "clang/Basic/OpenMPKinds.def"
656
Douglas Gregord6ff3322009-08-04 16:50:30 +0000657 /// \brief Build a new pointer type given its pointee type.
658 ///
659 /// By default, performs semantic analysis when building the pointer type.
660 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000661 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000662
663 /// \brief Build a new block pointer type given its pointee type.
664 ///
Mike Stump11289f42009-09-09 15:08:12 +0000665 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000667 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000668
John McCall70dd5f62009-10-30 00:06:24 +0000669 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000670 ///
John McCall70dd5f62009-10-30 00:06:24 +0000671 /// By default, performs semantic analysis when building the
672 /// reference type. Subclasses may override this routine to provide
673 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000674 ///
John McCall70dd5f62009-10-30 00:06:24 +0000675 /// \param LValue whether the type was written with an lvalue sigil
676 /// or an rvalue sigil.
677 QualType RebuildReferenceType(QualType ReferentType,
678 bool LValue,
679 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000680
Douglas Gregord6ff3322009-08-04 16:50:30 +0000681 /// \brief Build a new member pointer type given the pointee type and the
682 /// class type it refers into.
683 ///
684 /// By default, performs semantic analysis when building the member pointer
685 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000686 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
687 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000688
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000689 /// \brief Build an Objective-C object type.
690 ///
691 /// By default, performs semantic analysis when building the object type.
692 /// Subclasses may override this routine to provide different behavior.
693 QualType RebuildObjCObjectType(QualType BaseType,
694 SourceLocation Loc,
695 SourceLocation TypeArgsLAngleLoc,
696 ArrayRef<TypeSourceInfo *> TypeArgs,
697 SourceLocation TypeArgsRAngleLoc,
698 SourceLocation ProtocolLAngleLoc,
699 ArrayRef<ObjCProtocolDecl *> Protocols,
700 ArrayRef<SourceLocation> ProtocolLocs,
701 SourceLocation ProtocolRAngleLoc);
702
703 /// \brief Build a new Objective-C object pointer type given the pointee type.
704 ///
705 /// By default, directly builds the pointer type, with no additional semantic
706 /// analysis.
707 QualType RebuildObjCObjectPointerType(QualType PointeeType,
708 SourceLocation Star);
709
Douglas Gregord6ff3322009-08-04 16:50:30 +0000710 /// \brief Build a new array type given the element type, size
711 /// modifier, size of the array (if known), size expression, and index type
712 /// qualifiers.
713 ///
714 /// By default, performs semantic analysis when building the array type.
715 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000716 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000717 QualType RebuildArrayType(QualType ElementType,
718 ArrayType::ArraySizeModifier SizeMod,
719 const llvm::APInt *Size,
720 Expr *SizeExpr,
721 unsigned IndexTypeQuals,
722 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000723
Douglas Gregord6ff3322009-08-04 16:50:30 +0000724 /// \brief Build a new constant array type given the element type, size
725 /// modifier, (known) size of the array, and index type qualifiers.
726 ///
727 /// By default, performs semantic analysis when building the array type.
728 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000729 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000730 ArrayType::ArraySizeModifier SizeMod,
731 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000732 unsigned IndexTypeQuals,
733 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000734
Douglas Gregord6ff3322009-08-04 16:50:30 +0000735 /// \brief Build a new incomplete array type given the element type, size
736 /// modifier, and index type qualifiers.
737 ///
738 /// By default, performs semantic analysis when building the array type.
739 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000740 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000741 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000742 unsigned IndexTypeQuals,
743 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000744
Mike Stump11289f42009-09-09 15:08:12 +0000745 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000746 /// size modifier, size expression, and index type qualifiers.
747 ///
748 /// By default, performs semantic analysis when building the array type.
749 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000750 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000751 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000752 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000753 unsigned IndexTypeQuals,
754 SourceRange BracketsRange);
755
Mike Stump11289f42009-09-09 15:08:12 +0000756 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000757 /// size modifier, size expression, and index type qualifiers.
758 ///
759 /// By default, performs semantic analysis when building the array type.
760 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000761 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000762 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000763 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000764 unsigned IndexTypeQuals,
765 SourceRange BracketsRange);
766
767 /// \brief Build a new vector type given the element type and
768 /// number of elements.
769 ///
770 /// By default, performs semantic analysis when building the vector type.
771 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000772 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000773 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000774
Douglas Gregord6ff3322009-08-04 16:50:30 +0000775 /// \brief Build a new extended vector type given the element type and
776 /// number of elements.
777 ///
778 /// By default, performs semantic analysis when building the vector type.
779 /// Subclasses may override this routine to provide different behavior.
780 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
781 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000782
783 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000784 /// given the element type and number of elements.
785 ///
786 /// By default, performs semantic analysis when building the vector type.
787 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000788 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000789 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000790 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000791
Douglas Gregord6ff3322009-08-04 16:50:30 +0000792 /// \brief Build a new function type.
793 ///
794 /// By default, performs semantic analysis when building the function type.
795 /// Subclasses may override this routine to provide different behavior.
796 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000797 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000798 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000799
John McCall550e0c22009-10-21 00:40:46 +0000800 /// \brief Build a new unprototyped function type.
801 QualType RebuildFunctionNoProtoType(QualType ResultType);
802
John McCallb96ec562009-12-04 22:46:56 +0000803 /// \brief Rebuild an unresolved typename type, given the decl that
804 /// the UnresolvedUsingTypenameDecl was transformed to.
805 QualType RebuildUnresolvedUsingType(Decl *D);
806
Douglas Gregord6ff3322009-08-04 16:50:30 +0000807 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000808 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000809 return SemaRef.Context.getTypeDeclType(Typedef);
810 }
811
812 /// \brief Build a new class/struct/union type.
813 QualType RebuildRecordType(RecordDecl *Record) {
814 return SemaRef.Context.getTypeDeclType(Record);
815 }
816
817 /// \brief Build a new Enum type.
818 QualType RebuildEnumType(EnumDecl *Enum) {
819 return SemaRef.Context.getTypeDeclType(Enum);
820 }
John McCallfcc33b02009-09-05 00:15:47 +0000821
Mike Stump11289f42009-09-09 15:08:12 +0000822 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000823 ///
824 /// By default, performs semantic analysis when building the typeof type.
825 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000826 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000827
Mike Stump11289f42009-09-09 15:08:12 +0000828 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000829 ///
830 /// By default, builds a new TypeOfType with the given underlying type.
831 QualType RebuildTypeOfType(QualType Underlying);
832
Alexis Hunte852b102011-05-24 22:41:36 +0000833 /// \brief Build a new unary transform type.
834 QualType RebuildUnaryTransformType(QualType BaseType,
835 UnaryTransformType::UTTKind UKind,
836 SourceLocation Loc);
837
Richard Smith74aeef52013-04-26 16:15:35 +0000838 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000839 ///
840 /// By default, performs semantic analysis when building the decltype type.
841 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000842 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000843
Richard Smith74aeef52013-04-26 16:15:35 +0000844 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000845 ///
846 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000847 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000848 // Note, IsDependent is always false here: we implicitly convert an 'auto'
849 // which has been deduced to a dependent type into an undeduced 'auto', so
850 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000851 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
852 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000853 }
854
Douglas Gregord6ff3322009-08-04 16:50:30 +0000855 /// \brief Build a new template specialization type.
856 ///
857 /// By default, performs semantic analysis when building the template
858 /// specialization type. Subclasses may override this routine to provide
859 /// different behavior.
860 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000861 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000862 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000863
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000864 /// \brief Build a new parenthesized type.
865 ///
866 /// By default, builds a new ParenType type from the inner type.
867 /// Subclasses may override this routine to provide different behavior.
868 QualType RebuildParenType(QualType InnerType) {
869 return SemaRef.Context.getParenType(InnerType);
870 }
871
Douglas Gregord6ff3322009-08-04 16:50:30 +0000872 /// \brief Build a new qualified name type.
873 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000874 /// By default, builds a new ElaboratedType type from the keyword,
875 /// the nested-name-specifier and the named type.
876 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000877 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
878 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000879 NestedNameSpecifierLoc QualifierLoc,
880 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000881 return SemaRef.Context.getElaboratedType(Keyword,
882 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000883 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000884 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000885
886 /// \brief Build a new typename type that refers to a template-id.
887 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000888 /// By default, builds a new DependentNameType type from the
889 /// nested-name-specifier and the given type. Subclasses may override
890 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000891 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000892 ElaboratedTypeKeyword Keyword,
893 NestedNameSpecifierLoc QualifierLoc,
894 const IdentifierInfo *Name,
895 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000896 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000897 // Rebuild the template name.
898 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000899 CXXScopeSpec SS;
900 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000901 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000902 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
903 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000904
Douglas Gregora7a795b2011-03-01 20:11:18 +0000905 if (InstName.isNull())
906 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000907
Douglas Gregora7a795b2011-03-01 20:11:18 +0000908 // If it's still dependent, make a dependent specialization.
909 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000910 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
911 QualifierLoc.getNestedNameSpecifier(),
912 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000913 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000914
Douglas Gregora7a795b2011-03-01 20:11:18 +0000915 // Otherwise, make an elaborated type wrapping a non-dependent
916 // specialization.
917 QualType T =
918 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
919 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000920
Craig Topperc3ec1492014-05-26 06:22:03 +0000921 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000922 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000923
924 return SemaRef.Context.getElaboratedType(Keyword,
925 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000926 T);
927 }
928
Douglas Gregord6ff3322009-08-04 16:50:30 +0000929 /// \brief Build a new typename type that refers to an identifier.
930 ///
931 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000932 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000933 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000934 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000935 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000936 NestedNameSpecifierLoc QualifierLoc,
937 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000938 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000939 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000940 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000941
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000942 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000943 // If the name is still dependent, just build a new dependent name type.
944 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000945 return SemaRef.Context.getDependentNameType(Keyword,
946 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000947 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000948 }
949
Abramo Bagnara6150c882010-05-11 21:36:43 +0000950 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000951 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000952 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000953
954 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
955
Abramo Bagnarad7548482010-05-19 21:37:53 +0000956 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000957 // into a non-dependent elaborated-type-specifier. Find the tag we're
958 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000959 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000960 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
961 if (!DC)
962 return QualType();
963
John McCallbf8c5192010-05-27 06:40:31 +0000964 if (SemaRef.RequireCompleteDeclContext(SS, DC))
965 return QualType();
966
Craig Topperc3ec1492014-05-26 06:22:03 +0000967 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000968 SemaRef.LookupQualifiedName(Result, DC);
969 switch (Result.getResultKind()) {
970 case LookupResult::NotFound:
971 case LookupResult::NotFoundInCurrentInstantiation:
972 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000973
Douglas Gregore677daf2010-03-31 22:19:08 +0000974 case LookupResult::Found:
975 Tag = Result.getAsSingle<TagDecl>();
976 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000977
Douglas Gregore677daf2010-03-31 22:19:08 +0000978 case LookupResult::FoundOverloaded:
979 case LookupResult::FoundUnresolvedValue:
980 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000981
Douglas Gregore677daf2010-03-31 22:19:08 +0000982 case LookupResult::Ambiguous:
983 // Let the LookupResult structure handle ambiguities.
984 return QualType();
985 }
986
987 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000988 // Check where the name exists but isn't a tag type and use that to emit
989 // better diagnostics.
990 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
991 SemaRef.LookupQualifiedName(Result, DC);
992 switch (Result.getResultKind()) {
993 case LookupResult::Found:
994 case LookupResult::FoundOverloaded:
995 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +0000996 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +0000997 unsigned Kind = 0;
998 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +0000999 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
1000 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +00001001 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
1002 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1003 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001004 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001005 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001006 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001007 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001008 break;
1009 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001010 return QualType();
1011 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001012
Richard Trieucaa33d32011-06-10 03:11:26 +00001013 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001014 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001015 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001016 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1017 return QualType();
1018 }
1019
1020 // Build the elaborated-type-specifier type.
1021 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001022 return SemaRef.Context.getElaboratedType(Keyword,
1023 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001024 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001025 }
Mike Stump11289f42009-09-09 15:08:12 +00001026
Douglas Gregor822d0302011-01-12 17:07:58 +00001027 /// \brief Build a new pack expansion type.
1028 ///
1029 /// By default, builds a new PackExpansionType type from the given pattern.
1030 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001031 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001032 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001033 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001034 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001035 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1036 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001037 }
1038
Eli Friedman0dfb8892011-10-06 23:00:33 +00001039 /// \brief Build a new atomic type given its value type.
1040 ///
1041 /// By default, performs semantic analysis when building the atomic type.
1042 /// Subclasses may override this routine to provide different behavior.
1043 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1044
Douglas Gregor71dc5092009-08-06 06:41:21 +00001045 /// \brief Build a new template name given a nested name specifier, a flag
1046 /// indicating whether the "template" keyword was provided, and the template
1047 /// that the template name refers to.
1048 ///
1049 /// By default, builds the new template name directly. Subclasses may override
1050 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001051 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001052 bool TemplateKW,
1053 TemplateDecl *Template);
1054
Douglas Gregor71dc5092009-08-06 06:41:21 +00001055 /// \brief Build a new template name given a nested name specifier and the
1056 /// name that is referred to as a template.
1057 ///
1058 /// By default, performs semantic analysis to determine whether the name can
1059 /// be resolved to a specific template, then builds the appropriate kind of
1060 /// template name. Subclasses may override this routine to provide different
1061 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001062 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1063 const IdentifierInfo &Name,
1064 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001065 QualType ObjectType,
1066 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001067
Douglas Gregor71395fa2009-11-04 00:56:37 +00001068 /// \brief Build a new template name given a nested name specifier and the
1069 /// overloaded operator name that is referred to as a template.
1070 ///
1071 /// By default, performs semantic analysis to determine whether the name can
1072 /// be resolved to a specific template, then builds the appropriate kind of
1073 /// template name. Subclasses may override this routine to provide different
1074 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001075 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001076 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001077 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001078 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001079
1080 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001081 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001082 ///
1083 /// By default, performs semantic analysis to determine whether the name can
1084 /// be resolved to a specific template, then builds the appropriate kind of
1085 /// template name. Subclasses may override this routine to provide different
1086 /// behavior.
1087 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1088 const TemplateArgument &ArgPack) {
1089 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1090 }
1091
Douglas Gregorebe10102009-08-20 07:17:43 +00001092 /// \brief Build a new compound statement.
1093 ///
1094 /// By default, performs semantic analysis to build the new statement.
1095 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001096 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001097 MultiStmtArg Statements,
1098 SourceLocation RBraceLoc,
1099 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001100 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001101 IsStmtExpr);
1102 }
1103
1104 /// \brief Build a new case statement.
1105 ///
1106 /// By default, performs semantic analysis to build the new statement.
1107 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001108 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001109 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001110 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001111 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001112 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001113 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001114 ColonLoc);
1115 }
Mike Stump11289f42009-09-09 15:08:12 +00001116
Douglas Gregorebe10102009-08-20 07:17:43 +00001117 /// \brief Attach the body to a new case statement.
1118 ///
1119 /// By default, performs semantic analysis to build the new statement.
1120 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001121 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001122 getSema().ActOnCaseStmtBody(S, Body);
1123 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001124 }
Mike Stump11289f42009-09-09 15:08:12 +00001125
Douglas Gregorebe10102009-08-20 07:17:43 +00001126 /// \brief Build a new default statement.
1127 ///
1128 /// By default, performs semantic analysis to build the new statement.
1129 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001130 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001131 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001132 Stmt *SubStmt) {
1133 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001134 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001135 }
Mike Stump11289f42009-09-09 15:08:12 +00001136
Douglas Gregorebe10102009-08-20 07:17:43 +00001137 /// \brief Build a new label statement.
1138 ///
1139 /// By default, performs semantic analysis to build the new statement.
1140 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001141 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1142 SourceLocation ColonLoc, Stmt *SubStmt) {
1143 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001144 }
Mike Stump11289f42009-09-09 15:08:12 +00001145
Richard Smithc202b282012-04-14 00:33:13 +00001146 /// \brief Build a new label statement.
1147 ///
1148 /// By default, performs semantic analysis to build the new statement.
1149 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001150 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1151 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001152 Stmt *SubStmt) {
1153 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1154 }
1155
Douglas Gregorebe10102009-08-20 07:17:43 +00001156 /// \brief Build a new "if" statement.
1157 ///
1158 /// By default, performs semantic analysis to build the new statement.
1159 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001160 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001161 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001162 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001163 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001164 }
Mike Stump11289f42009-09-09 15:08:12 +00001165
Douglas Gregorebe10102009-08-20 07:17:43 +00001166 /// \brief Start building a new switch statement.
1167 ///
1168 /// By default, performs semantic analysis to build the new statement.
1169 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001170 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001171 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001172 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001173 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001174 }
Mike Stump11289f42009-09-09 15:08:12 +00001175
Douglas Gregorebe10102009-08-20 07:17:43 +00001176 /// \brief Attach the body to the switch statement.
1177 ///
1178 /// By default, performs semantic analysis to build the new statement.
1179 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001180 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001181 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001182 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001183 }
1184
1185 /// \brief Build a new while statement.
1186 ///
1187 /// By default, performs semantic analysis to build the new statement.
1188 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001189 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1190 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001191 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001192 }
Mike Stump11289f42009-09-09 15:08:12 +00001193
Douglas Gregorebe10102009-08-20 07:17:43 +00001194 /// \brief Build a new do-while statement.
1195 ///
1196 /// By default, performs semantic analysis to build the new statement.
1197 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001198 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001199 SourceLocation WhileLoc, SourceLocation LParenLoc,
1200 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001201 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1202 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001203 }
1204
1205 /// \brief Build a new for statement.
1206 ///
1207 /// By default, performs semantic analysis to build the new statement.
1208 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001209 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001210 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001211 VarDecl *CondVar, Sema::FullExprArg Inc,
1212 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001213 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001214 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001215 }
Mike Stump11289f42009-09-09 15:08:12 +00001216
Douglas Gregorebe10102009-08-20 07:17:43 +00001217 /// \brief Build a new goto statement.
1218 ///
1219 /// By default, performs semantic analysis to build the new statement.
1220 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001221 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1222 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001223 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001224 }
1225
1226 /// \brief Build a new indirect goto statement.
1227 ///
1228 /// By default, performs semantic analysis to build the new statement.
1229 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001230 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001231 SourceLocation StarLoc,
1232 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001233 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001234 }
Mike Stump11289f42009-09-09 15:08:12 +00001235
Douglas Gregorebe10102009-08-20 07:17:43 +00001236 /// \brief Build a new return statement.
1237 ///
1238 /// By default, performs semantic analysis to build the new statement.
1239 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001240 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001241 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001242 }
Mike Stump11289f42009-09-09 15:08:12 +00001243
Douglas Gregorebe10102009-08-20 07:17:43 +00001244 /// \brief Build a new declaration statement.
1245 ///
1246 /// By default, performs semantic analysis to build the new statement.
1247 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001248 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001249 SourceLocation StartLoc, SourceLocation EndLoc) {
1250 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001251 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001252 }
Mike Stump11289f42009-09-09 15:08:12 +00001253
Anders Carlssonaaeef072010-01-24 05:50:09 +00001254 /// \brief Build a new inline asm statement.
1255 ///
1256 /// By default, performs semantic analysis to build the new statement.
1257 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001258 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1259 bool IsVolatile, unsigned NumOutputs,
1260 unsigned NumInputs, IdentifierInfo **Names,
1261 MultiExprArg Constraints, MultiExprArg Exprs,
1262 Expr *AsmString, MultiExprArg Clobbers,
1263 SourceLocation RParenLoc) {
1264 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1265 NumInputs, Names, Constraints, Exprs,
1266 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001267 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001268
Chad Rosier32503022012-06-11 20:47:18 +00001269 /// \brief Build a new MS style inline asm statement.
1270 ///
1271 /// By default, performs semantic analysis to build the new statement.
1272 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001273 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001274 ArrayRef<Token> AsmToks,
1275 StringRef AsmString,
1276 unsigned NumOutputs, unsigned NumInputs,
1277 ArrayRef<StringRef> Constraints,
1278 ArrayRef<StringRef> Clobbers,
1279 ArrayRef<Expr*> Exprs,
1280 SourceLocation EndLoc) {
1281 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1282 NumOutputs, NumInputs,
1283 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001284 }
1285
James Dennett2a4d13c2012-06-15 07:13:21 +00001286 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001287 ///
1288 /// By default, performs semantic analysis to build the new statement.
1289 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001290 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001291 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001292 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001293 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001294 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001295 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001296 }
1297
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001298 /// \brief Rebuild an Objective-C exception declaration.
1299 ///
1300 /// By default, performs semantic analysis to build the new declaration.
1301 /// Subclasses may override this routine to provide different behavior.
1302 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1303 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001304 return getSema().BuildObjCExceptionDecl(TInfo, T,
1305 ExceptionDecl->getInnerLocStart(),
1306 ExceptionDecl->getLocation(),
1307 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001308 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001309
James Dennett2a4d13c2012-06-15 07:13:21 +00001310 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001311 ///
1312 /// By default, performs semantic analysis to build the new statement.
1313 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001314 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001315 SourceLocation RParenLoc,
1316 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001317 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001318 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001319 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001320 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001321
James Dennett2a4d13c2012-06-15 07:13:21 +00001322 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001323 ///
1324 /// By default, performs semantic analysis to build the new statement.
1325 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001326 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001327 Stmt *Body) {
1328 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001329 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001330
James Dennett2a4d13c2012-06-15 07:13:21 +00001331 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001332 ///
1333 /// By default, performs semantic analysis to build the new statement.
1334 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001335 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001336 Expr *Operand) {
1337 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001338 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001339
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001340 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001341 ///
1342 /// By default, performs semantic analysis to build the new statement.
1343 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001344 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001345 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001346 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001347 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001348 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001349 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001350 return getSema().ActOnOpenMPExecutableDirective(
1351 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001352 }
1353
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001354 /// \brief Build a new OpenMP 'if' clause.
1355 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001356 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001357 /// Subclasses may override this routine to provide different behavior.
1358 OMPClause *RebuildOMPIfClause(Expr *Condition,
1359 SourceLocation StartLoc,
1360 SourceLocation LParenLoc,
1361 SourceLocation EndLoc) {
1362 return getSema().ActOnOpenMPIfClause(Condition, StartLoc,
1363 LParenLoc, EndLoc);
1364 }
1365
Alexey Bataev3778b602014-07-17 07:32:53 +00001366 /// \brief Build a new OpenMP 'final' clause.
1367 ///
1368 /// By default, performs semantic analysis to build the new OpenMP clause.
1369 /// Subclasses may override this routine to provide different behavior.
1370 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1371 SourceLocation LParenLoc,
1372 SourceLocation EndLoc) {
1373 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1374 EndLoc);
1375 }
1376
Alexey Bataev568a8332014-03-06 06:15:19 +00001377 /// \brief Build a new OpenMP 'num_threads' clause.
1378 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001379 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001380 /// Subclasses may override this routine to provide different behavior.
1381 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1382 SourceLocation StartLoc,
1383 SourceLocation LParenLoc,
1384 SourceLocation EndLoc) {
1385 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1386 LParenLoc, EndLoc);
1387 }
1388
Alexey Bataev62c87d22014-03-21 04:51:18 +00001389 /// \brief Build a new OpenMP 'safelen' clause.
1390 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001391 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001392 /// Subclasses may override this routine to provide different behavior.
1393 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1394 SourceLocation LParenLoc,
1395 SourceLocation EndLoc) {
1396 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1397 }
1398
Alexey Bataev66b15b52015-08-21 11:14:16 +00001399 /// \brief Build a new OpenMP 'simdlen' clause.
1400 ///
1401 /// By default, performs semantic analysis to build the new OpenMP clause.
1402 /// Subclasses may override this routine to provide different behavior.
1403 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1404 SourceLocation LParenLoc,
1405 SourceLocation EndLoc) {
1406 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1407 }
1408
Alexander Musman8bd31e62014-05-27 15:12:19 +00001409 /// \brief Build a new OpenMP 'collapse' clause.
1410 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001411 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001412 /// Subclasses may override this routine to provide different behavior.
1413 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1414 SourceLocation LParenLoc,
1415 SourceLocation EndLoc) {
1416 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1417 EndLoc);
1418 }
1419
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001420 /// \brief Build a new OpenMP 'default' clause.
1421 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001422 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001423 /// Subclasses may override this routine to provide different behavior.
1424 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1425 SourceLocation KindKwLoc,
1426 SourceLocation StartLoc,
1427 SourceLocation LParenLoc,
1428 SourceLocation EndLoc) {
1429 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1430 StartLoc, LParenLoc, EndLoc);
1431 }
1432
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001433 /// \brief Build a new OpenMP 'proc_bind' clause.
1434 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001435 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001436 /// Subclasses may override this routine to provide different behavior.
1437 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1438 SourceLocation KindKwLoc,
1439 SourceLocation StartLoc,
1440 SourceLocation LParenLoc,
1441 SourceLocation EndLoc) {
1442 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1443 StartLoc, LParenLoc, EndLoc);
1444 }
1445
Alexey Bataev56dafe82014-06-20 07:16:17 +00001446 /// \brief Build a new OpenMP 'schedule' clause.
1447 ///
1448 /// By default, performs semantic analysis to build the new OpenMP clause.
1449 /// Subclasses may override this routine to provide different behavior.
1450 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1451 Expr *ChunkSize,
1452 SourceLocation StartLoc,
1453 SourceLocation LParenLoc,
1454 SourceLocation KindLoc,
1455 SourceLocation CommaLoc,
1456 SourceLocation EndLoc) {
1457 return getSema().ActOnOpenMPScheduleClause(
1458 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1459 }
1460
Alexey Bataev10e775f2015-07-30 11:36:16 +00001461 /// \brief Build a new OpenMP 'ordered' clause.
1462 ///
1463 /// By default, performs semantic analysis to build the new OpenMP clause.
1464 /// Subclasses may override this routine to provide different behavior.
1465 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1466 SourceLocation EndLoc,
1467 SourceLocation LParenLoc, Expr *Num) {
1468 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1469 }
1470
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001471 /// \brief Build a new OpenMP 'private' clause.
1472 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001473 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001474 /// Subclasses may override this routine to provide different behavior.
1475 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1476 SourceLocation StartLoc,
1477 SourceLocation LParenLoc,
1478 SourceLocation EndLoc) {
1479 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1480 EndLoc);
1481 }
1482
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001483 /// \brief Build a new OpenMP 'firstprivate' clause.
1484 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001485 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001486 /// Subclasses may override this routine to provide different behavior.
1487 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1488 SourceLocation StartLoc,
1489 SourceLocation LParenLoc,
1490 SourceLocation EndLoc) {
1491 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1492 EndLoc);
1493 }
1494
Alexander Musman1bb328c2014-06-04 13:06:39 +00001495 /// \brief Build a new OpenMP 'lastprivate' clause.
1496 ///
1497 /// By default, performs semantic analysis to build the new OpenMP clause.
1498 /// Subclasses may override this routine to provide different behavior.
1499 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1500 SourceLocation StartLoc,
1501 SourceLocation LParenLoc,
1502 SourceLocation EndLoc) {
1503 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1504 EndLoc);
1505 }
1506
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001507 /// \brief Build a new OpenMP 'shared' clause.
1508 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001509 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001510 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001511 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1512 SourceLocation StartLoc,
1513 SourceLocation LParenLoc,
1514 SourceLocation EndLoc) {
1515 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1516 EndLoc);
1517 }
1518
Alexey Bataevc5e02582014-06-16 07:08:35 +00001519 /// \brief Build a new OpenMP 'reduction' clause.
1520 ///
1521 /// By default, performs semantic analysis to build the new statement.
1522 /// Subclasses may override this routine to provide different behavior.
1523 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1524 SourceLocation StartLoc,
1525 SourceLocation LParenLoc,
1526 SourceLocation ColonLoc,
1527 SourceLocation EndLoc,
1528 CXXScopeSpec &ReductionIdScopeSpec,
1529 const DeclarationNameInfo &ReductionId) {
1530 return getSema().ActOnOpenMPReductionClause(
1531 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1532 ReductionId);
1533 }
1534
Alexander Musman8dba6642014-04-22 13:09:42 +00001535 /// \brief Build a new OpenMP 'linear' clause.
1536 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001537 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001538 /// Subclasses may override this routine to provide different behavior.
1539 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1540 SourceLocation StartLoc,
1541 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001542 OpenMPLinearClauseKind Modifier,
1543 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001544 SourceLocation ColonLoc,
1545 SourceLocation EndLoc) {
1546 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001547 Modifier, ModifierLoc, ColonLoc,
1548 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001549 }
1550
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001551 /// \brief Build a new OpenMP 'aligned' clause.
1552 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001553 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001554 /// Subclasses may override this routine to provide different behavior.
1555 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1556 SourceLocation StartLoc,
1557 SourceLocation LParenLoc,
1558 SourceLocation ColonLoc,
1559 SourceLocation EndLoc) {
1560 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1561 LParenLoc, ColonLoc, EndLoc);
1562 }
1563
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001564 /// \brief Build a new OpenMP 'copyin' clause.
1565 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001566 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001567 /// Subclasses may override this routine to provide different behavior.
1568 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1569 SourceLocation StartLoc,
1570 SourceLocation LParenLoc,
1571 SourceLocation EndLoc) {
1572 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1573 EndLoc);
1574 }
1575
Alexey Bataevbae9a792014-06-27 10:37:06 +00001576 /// \brief Build a new OpenMP 'copyprivate' clause.
1577 ///
1578 /// By default, performs semantic analysis to build the new OpenMP clause.
1579 /// Subclasses may override this routine to provide different behavior.
1580 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1581 SourceLocation StartLoc,
1582 SourceLocation LParenLoc,
1583 SourceLocation EndLoc) {
1584 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1585 EndLoc);
1586 }
1587
Alexey Bataev6125da92014-07-21 11:26:11 +00001588 /// \brief Build a new OpenMP 'flush' pseudo clause.
1589 ///
1590 /// By default, performs semantic analysis to build the new OpenMP clause.
1591 /// Subclasses may override this routine to provide different behavior.
1592 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1593 SourceLocation StartLoc,
1594 SourceLocation LParenLoc,
1595 SourceLocation EndLoc) {
1596 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1597 EndLoc);
1598 }
1599
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001600 /// \brief Build a new OpenMP 'depend' pseudo clause.
1601 ///
1602 /// By default, performs semantic analysis to build the new OpenMP clause.
1603 /// Subclasses may override this routine to provide different behavior.
1604 OMPClause *
1605 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1606 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1607 SourceLocation StartLoc, SourceLocation LParenLoc,
1608 SourceLocation EndLoc) {
1609 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1610 StartLoc, LParenLoc, EndLoc);
1611 }
1612
Michael Wonge710d542015-08-07 16:16:36 +00001613 /// \brief Build a new OpenMP 'device' clause.
1614 ///
1615 /// By default, performs semantic analysis to build the new statement.
1616 /// Subclasses may override this routine to provide different behavior.
1617 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1618 SourceLocation LParenLoc,
1619 SourceLocation EndLoc) {
1620 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
1621 EndLoc);
1622 }
1623
James Dennett2a4d13c2012-06-15 07:13:21 +00001624 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001625 ///
1626 /// By default, performs semantic analysis to build the new statement.
1627 /// Subclasses may override this routine to provide different behavior.
1628 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1629 Expr *object) {
1630 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1631 }
1632
James Dennett2a4d13c2012-06-15 07:13:21 +00001633 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001634 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001635 /// By default, performs semantic analysis to build the new statement.
1636 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001637 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001638 Expr *Object, Stmt *Body) {
1639 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001640 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001641
James Dennett2a4d13c2012-06-15 07:13:21 +00001642 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001643 ///
1644 /// By default, performs semantic analysis to build the new statement.
1645 /// Subclasses may override this routine to provide different behavior.
1646 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1647 Stmt *Body) {
1648 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1649 }
John McCall53848232011-07-27 01:07:15 +00001650
Douglas Gregorf68a5082010-04-22 23:10:45 +00001651 /// \brief Build a new Objective-C fast enumeration statement.
1652 ///
1653 /// By default, performs semantic analysis to build the new statement.
1654 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001655 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001656 Stmt *Element,
1657 Expr *Collection,
1658 SourceLocation RParenLoc,
1659 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001660 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001661 Element,
John McCallb268a282010-08-23 23:25:46 +00001662 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001663 RParenLoc);
1664 if (ForEachStmt.isInvalid())
1665 return StmtError();
1666
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001667 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001668 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001669
Douglas Gregorebe10102009-08-20 07:17:43 +00001670 /// \brief Build a new C++ exception declaration.
1671 ///
1672 /// By default, performs semantic analysis to build the new decaration.
1673 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001674 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001675 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001676 SourceLocation StartLoc,
1677 SourceLocation IdLoc,
1678 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001679 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001680 StartLoc, IdLoc, Id);
1681 if (Var)
1682 getSema().CurContext->addDecl(Var);
1683 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001684 }
1685
1686 /// \brief Build a new C++ catch statement.
1687 ///
1688 /// By default, performs semantic analysis to build the new statement.
1689 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001690 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001691 VarDecl *ExceptionDecl,
1692 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001693 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1694 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001695 }
Mike Stump11289f42009-09-09 15:08:12 +00001696
Douglas Gregorebe10102009-08-20 07:17:43 +00001697 /// \brief Build a new C++ try statement.
1698 ///
1699 /// By default, performs semantic analysis to build the new statement.
1700 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001701 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1702 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001703 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001704 }
Mike Stump11289f42009-09-09 15:08:12 +00001705
Richard Smith02e85f32011-04-14 22:09:26 +00001706 /// \brief Build a new C++0x range-based for statement.
1707 ///
1708 /// By default, performs semantic analysis to build the new statement.
1709 /// Subclasses may override this routine to provide different behavior.
1710 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1711 SourceLocation ColonLoc,
1712 Stmt *Range, Stmt *BeginEnd,
1713 Expr *Cond, Expr *Inc,
1714 Stmt *LoopVar,
1715 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001716 // If we've just learned that the range is actually an Objective-C
1717 // collection, treat this as an Objective-C fast enumeration loop.
1718 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1719 if (RangeStmt->isSingleDecl()) {
1720 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001721 if (RangeVar->isInvalidDecl())
1722 return StmtError();
1723
Douglas Gregorf7106af2013-04-08 18:40:13 +00001724 Expr *RangeExpr = RangeVar->getInit();
1725 if (!RangeExpr->isTypeDependent() &&
1726 RangeExpr->getType()->isObjCObjectPointerType())
1727 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1728 RParenLoc);
1729 }
1730 }
1731 }
1732
Richard Smith02e85f32011-04-14 22:09:26 +00001733 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001734 Cond, Inc, LoopVar, RParenLoc,
1735 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001736 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001737
1738 /// \brief Build a new C++0x range-based for statement.
1739 ///
1740 /// By default, performs semantic analysis to build the new statement.
1741 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001742 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001743 bool IsIfExists,
1744 NestedNameSpecifierLoc QualifierLoc,
1745 DeclarationNameInfo NameInfo,
1746 Stmt *Nested) {
1747 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1748 QualifierLoc, NameInfo, Nested);
1749 }
1750
Richard Smith02e85f32011-04-14 22:09:26 +00001751 /// \brief Attach body to a C++0x range-based for statement.
1752 ///
1753 /// By default, performs semantic analysis to finish the new statement.
1754 /// Subclasses may override this routine to provide different behavior.
1755 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1756 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1757 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001758
David Majnemerfad8f482013-10-15 09:33:02 +00001759 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001760 Stmt *TryBlock, Stmt *Handler) {
1761 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001762 }
1763
David Majnemerfad8f482013-10-15 09:33:02 +00001764 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001765 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001766 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001767 }
1768
David Majnemerfad8f482013-10-15 09:33:02 +00001769 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001770 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001771 }
1772
Alexey Bataevec474782014-10-09 08:45:04 +00001773 /// \brief Build a new predefined expression.
1774 ///
1775 /// By default, performs semantic analysis to build the new expression.
1776 /// Subclasses may override this routine to provide different behavior.
1777 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1778 PredefinedExpr::IdentType IT) {
1779 return getSema().BuildPredefinedExpr(Loc, IT);
1780 }
1781
Douglas Gregora16548e2009-08-11 05:31:07 +00001782 /// \brief Build a new expression that references a declaration.
1783 ///
1784 /// By default, performs semantic analysis to build the new expression.
1785 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001786 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001787 LookupResult &R,
1788 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001789 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1790 }
1791
1792
1793 /// \brief Build a new expression that references a declaration.
1794 ///
1795 /// By default, performs semantic analysis to build the new expression.
1796 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001797 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001798 ValueDecl *VD,
1799 const DeclarationNameInfo &NameInfo,
1800 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001801 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001802 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001803
1804 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001805
1806 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001807 }
Mike Stump11289f42009-09-09 15:08:12 +00001808
Douglas Gregora16548e2009-08-11 05:31:07 +00001809 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001810 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001811 /// By default, performs semantic analysis to build the new expression.
1812 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001813 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001814 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001815 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001816 }
1817
Douglas Gregorad8a3362009-09-04 17:36:40 +00001818 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001819 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001820 /// By default, performs semantic analysis to build the new expression.
1821 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001822 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001823 SourceLocation OperatorLoc,
1824 bool isArrow,
1825 CXXScopeSpec &SS,
1826 TypeSourceInfo *ScopeType,
1827 SourceLocation CCLoc,
1828 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001829 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001830
Douglas Gregora16548e2009-08-11 05:31:07 +00001831 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001832 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001833 /// By default, performs semantic analysis to build the new expression.
1834 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001835 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001836 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001837 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001838 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001839 }
Mike Stump11289f42009-09-09 15:08:12 +00001840
Douglas Gregor882211c2010-04-28 22:16:22 +00001841 /// \brief Build a new builtin offsetof expression.
1842 ///
1843 /// By default, performs semantic analysis to build the new expression.
1844 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001845 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Douglas Gregor882211c2010-04-28 22:16:22 +00001846 TypeSourceInfo *Type,
John McCallfaf5fb42010-08-26 23:41:50 +00001847 Sema::OffsetOfComponent *Components,
Douglas Gregor882211c2010-04-28 22:16:22 +00001848 unsigned NumComponents,
1849 SourceLocation RParenLoc) {
1850 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
1851 NumComponents, RParenLoc);
1852 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001853
1854 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001855 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001856 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001857 /// By default, performs semantic analysis to build the new expression.
1858 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001859 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1860 SourceLocation OpLoc,
1861 UnaryExprOrTypeTrait ExprKind,
1862 SourceRange R) {
1863 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001864 }
1865
Peter Collingbournee190dee2011-03-11 19:24:49 +00001866 /// \brief Build a new sizeof, alignof or vec step expression with an
1867 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001868 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001869 /// By default, performs semantic analysis to build the new expression.
1870 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001871 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1872 UnaryExprOrTypeTrait ExprKind,
1873 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001874 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001875 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001876 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001877 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001878
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001879 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001880 }
Mike Stump11289f42009-09-09 15:08:12 +00001881
Douglas Gregora16548e2009-08-11 05:31:07 +00001882 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001883 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001884 /// By default, performs semantic analysis to build the new expression.
1885 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001886 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001887 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001888 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001889 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001890 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001891 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001892 RBracketLoc);
1893 }
1894
Alexey Bataev1a3320e2015-08-25 14:24:04 +00001895 /// \brief Build a new array section expression.
1896 ///
1897 /// By default, performs semantic analysis to build the new expression.
1898 /// Subclasses may override this routine to provide different behavior.
1899 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
1900 Expr *LowerBound,
1901 SourceLocation ColonLoc, Expr *Length,
1902 SourceLocation RBracketLoc) {
1903 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
1904 ColonLoc, Length, RBracketLoc);
1905 }
1906
Douglas Gregora16548e2009-08-11 05:31:07 +00001907 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001908 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001909 /// By default, performs semantic analysis to build the new expression.
1910 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001911 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001912 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001913 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001914 Expr *ExecConfig = nullptr) {
1915 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001916 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001917 }
1918
1919 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001920 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001921 /// By default, performs semantic analysis to build the new expression.
1922 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001923 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001924 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001925 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001926 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001927 const DeclarationNameInfo &MemberNameInfo,
1928 ValueDecl *Member,
1929 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001930 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001931 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001932 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1933 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001934 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001935 // We have a reference to an unnamed field. This is always the
1936 // base of an anonymous struct/union member access, i.e. the
1937 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001938 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001939 assert(Member->getType()->isRecordType() &&
1940 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001941
Richard Smithcab9a7d2011-10-26 19:06:56 +00001942 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001943 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001944 QualifierLoc.getNestedNameSpecifier(),
1945 FoundDecl, Member);
1946 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001947 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001948 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001949 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00001950 MemberExpr *ME = new (getSema().Context)
1951 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
1952 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001953 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001954 }
Mike Stump11289f42009-09-09 15:08:12 +00001955
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001956 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001957 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001958
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001959 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001960 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001961
John McCall16df1e52010-03-30 21:47:33 +00001962 // FIXME: this involves duplicating earlier analysis in a lot of
1963 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001964 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001965 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001966 R.resolveKind();
1967
John McCallb268a282010-08-23 23:25:46 +00001968 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001969 SS, TemplateKWLoc,
1970 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00001971 R, ExplicitTemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00001972 }
Mike Stump11289f42009-09-09 15:08:12 +00001973
Douglas Gregora16548e2009-08-11 05:31:07 +00001974 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001975 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001976 /// By default, performs semantic analysis to build the new expression.
1977 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001978 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001979 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001980 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001981 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001982 }
1983
1984 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001985 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001986 /// By default, performs semantic analysis to build the new expression.
1987 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001988 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001989 SourceLocation QuestionLoc,
1990 Expr *LHS,
1991 SourceLocation ColonLoc,
1992 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00001993 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
1994 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001995 }
1996
Douglas Gregora16548e2009-08-11 05:31:07 +00001997 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00001998 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001999 /// By default, performs semantic analysis to build the new expression.
2000 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002001 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002002 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002003 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002004 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002005 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002006 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002007 }
Mike Stump11289f42009-09-09 15:08:12 +00002008
Douglas Gregora16548e2009-08-11 05:31:07 +00002009 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002010 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002011 /// By default, performs semantic analysis to build the new expression.
2012 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002013 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002014 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002015 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002016 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002017 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002018 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002019 }
Mike Stump11289f42009-09-09 15:08:12 +00002020
Douglas Gregora16548e2009-08-11 05:31:07 +00002021 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002022 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002023 /// By default, performs semantic analysis to build the new expression.
2024 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002025 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002026 SourceLocation OpLoc,
2027 SourceLocation AccessorLoc,
2028 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002029
John McCall10eae182009-11-30 22:42:35 +00002030 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002031 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002032 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002033 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002034 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002035 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002036 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002037 /* TemplateArgs */ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002038 }
Mike Stump11289f42009-09-09 15:08:12 +00002039
Douglas Gregora16548e2009-08-11 05:31:07 +00002040 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002041 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002042 /// By default, performs semantic analysis to build the new expression.
2043 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002044 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002045 MultiExprArg Inits,
2046 SourceLocation RBraceLoc,
2047 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002048 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002049 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002050 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002051 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002052
Douglas Gregord3d93062009-11-09 17:16:50 +00002053 // Patch in the result type we were given, which may have been computed
2054 // when the initial InitListExpr was built.
2055 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2056 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002057 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002058 }
Mike Stump11289f42009-09-09 15:08:12 +00002059
Douglas Gregora16548e2009-08-11 05:31:07 +00002060 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002061 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002062 /// By default, performs semantic analysis to build the new expression.
2063 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002064 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002065 MultiExprArg ArrayExprs,
2066 SourceLocation EqualOrColonLoc,
2067 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002068 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002069 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002070 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002071 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002072 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002073 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002074
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002075 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002076 }
Mike Stump11289f42009-09-09 15:08:12 +00002077
Douglas Gregora16548e2009-08-11 05:31:07 +00002078 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002079 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002080 /// By default, builds the implicit value initialization without performing
2081 /// any semantic analysis. Subclasses may override this routine to provide
2082 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002083 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002084 return new (SemaRef.Context) ImplicitValueInitExpr(T);
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 \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002088 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002089 /// By default, performs semantic analysis to build the new expression.
2090 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002091 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002092 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002093 SourceLocation RParenLoc) {
2094 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002095 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002096 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002097 }
2098
2099 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002100 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002101 /// By default, performs semantic analysis to build the new expression.
2102 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002103 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002104 MultiExprArg SubExprs,
2105 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002106 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002107 }
Mike Stump11289f42009-09-09 15:08:12 +00002108
Douglas Gregora16548e2009-08-11 05:31:07 +00002109 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002110 ///
2111 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002112 /// rather than attempting to map the label statement itself.
2113 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002114 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002115 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002116 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002117 }
Mike Stump11289f42009-09-09 15:08:12 +00002118
Douglas Gregora16548e2009-08-11 05:31:07 +00002119 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002120 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002121 /// By default, performs semantic analysis to build the new expression.
2122 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002123 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002124 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002125 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002126 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002127 }
Mike Stump11289f42009-09-09 15:08:12 +00002128
Douglas Gregora16548e2009-08-11 05:31:07 +00002129 /// \brief Build a new __builtin_choose_expr expression.
2130 ///
2131 /// By default, performs semantic analysis to build the new expression.
2132 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002133 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002134 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002135 SourceLocation RParenLoc) {
2136 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002137 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002138 RParenLoc);
2139 }
Mike Stump11289f42009-09-09 15:08:12 +00002140
Peter Collingbourne91147592011-04-15 00:35:48 +00002141 /// \brief Build a new generic selection expression.
2142 ///
2143 /// By default, performs semantic analysis to build the new expression.
2144 /// Subclasses may override this routine to provide different behavior.
2145 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2146 SourceLocation DefaultLoc,
2147 SourceLocation RParenLoc,
2148 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002149 ArrayRef<TypeSourceInfo *> Types,
2150 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002151 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002152 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002153 }
2154
Douglas Gregora16548e2009-08-11 05:31:07 +00002155 /// \brief Build a new overloaded operator call expression.
2156 ///
2157 /// By default, performs semantic analysis to build the new expression.
2158 /// The semantic analysis provides the behavior of template instantiation,
2159 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002160 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002161 /// argument-dependent lookup, etc. Subclasses may override this routine to
2162 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002163 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002164 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002165 Expr *Callee,
2166 Expr *First,
2167 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002168
2169 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002170 /// reinterpret_cast.
2171 ///
2172 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002173 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002174 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002175 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002176 Stmt::StmtClass Class,
2177 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002178 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002179 SourceLocation RAngleLoc,
2180 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002181 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002182 SourceLocation RParenLoc) {
2183 switch (Class) {
2184 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002185 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002186 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002187 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002188
2189 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002190 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002191 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002192 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002193
Douglas Gregora16548e2009-08-11 05:31:07 +00002194 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002195 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002196 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002197 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002198 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002199
Douglas Gregora16548e2009-08-11 05:31:07 +00002200 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002201 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002202 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002203 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002204
Douglas Gregora16548e2009-08-11 05:31:07 +00002205 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002206 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002207 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002208 }
Mike Stump11289f42009-09-09 15:08:12 +00002209
Douglas Gregora16548e2009-08-11 05:31:07 +00002210 /// \brief Build a new C++ static_cast expression.
2211 ///
2212 /// By default, performs semantic analysis to build the new expression.
2213 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002214 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002215 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002216 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002217 SourceLocation RAngleLoc,
2218 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002219 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002220 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002221 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002222 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002223 SourceRange(LAngleLoc, RAngleLoc),
2224 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002225 }
2226
2227 /// \brief Build a new C++ dynamic_cast expression.
2228 ///
2229 /// By default, performs semantic analysis to build the new expression.
2230 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002231 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002232 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002233 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002234 SourceLocation RAngleLoc,
2235 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002236 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002237 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002238 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002239 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002240 SourceRange(LAngleLoc, RAngleLoc),
2241 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002242 }
2243
2244 /// \brief Build a new C++ reinterpret_cast expression.
2245 ///
2246 /// By default, performs semantic analysis to build the new expression.
2247 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002248 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002249 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002250 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002251 SourceLocation RAngleLoc,
2252 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002253 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002254 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002255 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002256 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002257 SourceRange(LAngleLoc, RAngleLoc),
2258 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002259 }
2260
2261 /// \brief Build a new C++ const_cast expression.
2262 ///
2263 /// By default, performs semantic analysis to build the new expression.
2264 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002265 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002266 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002267 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002268 SourceLocation RAngleLoc,
2269 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002270 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002271 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002272 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002273 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002274 SourceRange(LAngleLoc, RAngleLoc),
2275 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002276 }
Mike Stump11289f42009-09-09 15:08:12 +00002277
Douglas Gregora16548e2009-08-11 05:31:07 +00002278 /// \brief Build a new C++ functional-style cast expression.
2279 ///
2280 /// By default, performs semantic analysis to build the new expression.
2281 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002282 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2283 SourceLocation LParenLoc,
2284 Expr *Sub,
2285 SourceLocation RParenLoc) {
2286 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002287 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002288 RParenLoc);
2289 }
Mike Stump11289f42009-09-09 15:08:12 +00002290
Douglas Gregora16548e2009-08-11 05:31:07 +00002291 /// \brief Build a new C++ typeid(type) expression.
2292 ///
2293 /// By default, performs semantic analysis to build the new expression.
2294 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002295 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002296 SourceLocation TypeidLoc,
2297 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002298 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002299 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002300 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002301 }
Mike Stump11289f42009-09-09 15:08:12 +00002302
Francois Pichet9f4f2072010-09-08 12:20:18 +00002303
Douglas Gregora16548e2009-08-11 05:31:07 +00002304 /// \brief Build a new C++ typeid(expr) expression.
2305 ///
2306 /// By default, performs semantic analysis to build the new expression.
2307 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002308 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002309 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002310 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002311 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002312 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002313 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002314 }
2315
Francois Pichet9f4f2072010-09-08 12:20:18 +00002316 /// \brief Build a new C++ __uuidof(type) expression.
2317 ///
2318 /// By default, performs semantic analysis to build the new expression.
2319 /// Subclasses may override this routine to provide different behavior.
2320 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2321 SourceLocation TypeidLoc,
2322 TypeSourceInfo *Operand,
2323 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002324 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002325 RParenLoc);
2326 }
2327
2328 /// \brief Build a new C++ __uuidof(expr) expression.
2329 ///
2330 /// By default, performs semantic analysis to build the new expression.
2331 /// Subclasses may override this routine to provide different behavior.
2332 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2333 SourceLocation TypeidLoc,
2334 Expr *Operand,
2335 SourceLocation RParenLoc) {
2336 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2337 RParenLoc);
2338 }
2339
Douglas Gregora16548e2009-08-11 05:31:07 +00002340 /// \brief Build a new C++ "this" expression.
2341 ///
2342 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002343 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002344 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002345 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002346 QualType ThisType,
2347 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002348 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002349 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002350 }
2351
2352 /// \brief Build a new C++ throw expression.
2353 ///
2354 /// By default, performs semantic analysis to build the new expression.
2355 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002356 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2357 bool IsThrownVariableInScope) {
2358 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002359 }
2360
2361 /// \brief Build a new C++ default-argument expression.
2362 ///
2363 /// By default, builds a new default-argument expression, which does not
2364 /// require any semantic analysis. Subclasses may override this routine to
2365 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002366 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002367 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002368 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002369 }
2370
Richard Smith852c9db2013-04-20 22:23:05 +00002371 /// \brief Build a new C++11 default-initialization expression.
2372 ///
2373 /// By default, builds a new default field initialization expression, which
2374 /// does not require any semantic analysis. Subclasses may override this
2375 /// routine to provide different behavior.
2376 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2377 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002378 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002379 }
2380
Douglas Gregora16548e2009-08-11 05:31:07 +00002381 /// \brief Build a new C++ zero-initialization expression.
2382 ///
2383 /// By default, performs semantic analysis to build the new expression.
2384 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002385 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2386 SourceLocation LParenLoc,
2387 SourceLocation RParenLoc) {
2388 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002389 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002390 }
Mike Stump11289f42009-09-09 15:08:12 +00002391
Douglas Gregora16548e2009-08-11 05:31:07 +00002392 /// \brief Build a new C++ "new" expression.
2393 ///
2394 /// By default, performs semantic analysis to build the new expression.
2395 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002396 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002397 bool UseGlobal,
2398 SourceLocation PlacementLParen,
2399 MultiExprArg PlacementArgs,
2400 SourceLocation PlacementRParen,
2401 SourceRange TypeIdParens,
2402 QualType AllocatedType,
2403 TypeSourceInfo *AllocatedTypeInfo,
2404 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002405 SourceRange DirectInitRange,
2406 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002407 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002408 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002409 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002410 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002411 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002412 AllocatedType,
2413 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002414 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002415 DirectInitRange,
2416 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002417 }
Mike Stump11289f42009-09-09 15:08:12 +00002418
Douglas Gregora16548e2009-08-11 05:31:07 +00002419 /// \brief Build a new C++ "delete" expression.
2420 ///
2421 /// By default, performs semantic analysis to build the new expression.
2422 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002423 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002424 bool IsGlobalDelete,
2425 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002426 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002427 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002428 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002429 }
Mike Stump11289f42009-09-09 15:08:12 +00002430
Douglas Gregor29c42f22012-02-24 07:38:34 +00002431 /// \brief Build a new type trait expression.
2432 ///
2433 /// By default, performs semantic analysis to build the new expression.
2434 /// Subclasses may override this routine to provide different behavior.
2435 ExprResult RebuildTypeTrait(TypeTrait Trait,
2436 SourceLocation StartLoc,
2437 ArrayRef<TypeSourceInfo *> Args,
2438 SourceLocation RParenLoc) {
2439 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2440 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002441
John Wiegley6242b6a2011-04-28 00:16:57 +00002442 /// \brief Build a new array type trait expression.
2443 ///
2444 /// By default, performs semantic analysis to build the new expression.
2445 /// Subclasses may override this routine to provide different behavior.
2446 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2447 SourceLocation StartLoc,
2448 TypeSourceInfo *TSInfo,
2449 Expr *DimExpr,
2450 SourceLocation RParenLoc) {
2451 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2452 }
2453
John Wiegleyf9f65842011-04-25 06:54:41 +00002454 /// \brief Build a new expression trait expression.
2455 ///
2456 /// By default, performs semantic analysis to build the new expression.
2457 /// Subclasses may override this routine to provide different behavior.
2458 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2459 SourceLocation StartLoc,
2460 Expr *Queried,
2461 SourceLocation RParenLoc) {
2462 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2463 }
2464
Mike Stump11289f42009-09-09 15:08:12 +00002465 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002466 /// expression.
2467 ///
2468 /// By default, performs semantic analysis to build the new expression.
2469 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002470 ExprResult RebuildDependentScopeDeclRefExpr(
2471 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002472 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002473 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002474 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002475 bool IsAddressOfOperand,
2476 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002477 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002478 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002479
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002480 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002481 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2482 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002483
Reid Kleckner32506ed2014-06-12 23:03:48 +00002484 return getSema().BuildQualifiedDeclarationNameExpr(
2485 SS, NameInfo, IsAddressOfOperand, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002486 }
2487
2488 /// \brief Build a new template-id expression.
2489 ///
2490 /// By default, performs semantic analysis to build the new expression.
2491 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002492 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002493 SourceLocation TemplateKWLoc,
2494 LookupResult &R,
2495 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002496 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002497 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2498 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002499 }
2500
2501 /// \brief Build a new object-construction expression.
2502 ///
2503 /// By default, performs semantic analysis to build the new expression.
2504 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002505 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002506 SourceLocation Loc,
2507 CXXConstructorDecl *Constructor,
2508 bool IsElidable,
2509 MultiExprArg Args,
2510 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002511 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002512 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002513 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002514 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002515 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002516 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002517 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002518 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002519 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002520
Douglas Gregordb121ba2009-12-14 16:27:04 +00002521 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002522 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002523 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002524 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002525 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002526 RequiresZeroInit, ConstructKind,
2527 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002528 }
2529
2530 /// \brief Build a new object-construction expression.
2531 ///
2532 /// By default, performs semantic analysis to build the new expression.
2533 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002534 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2535 SourceLocation LParenLoc,
2536 MultiExprArg Args,
2537 SourceLocation RParenLoc) {
2538 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002539 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002540 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002541 RParenLoc);
2542 }
2543
2544 /// \brief Build a new object-construction expression.
2545 ///
2546 /// By default, performs semantic analysis to build the new expression.
2547 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002548 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2549 SourceLocation LParenLoc,
2550 MultiExprArg Args,
2551 SourceLocation RParenLoc) {
2552 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002553 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002554 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002555 RParenLoc);
2556 }
Mike Stump11289f42009-09-09 15:08:12 +00002557
Douglas Gregora16548e2009-08-11 05:31:07 +00002558 /// \brief Build a new member reference expression.
2559 ///
2560 /// By default, performs semantic analysis to build the new expression.
2561 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002562 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002563 QualType BaseType,
2564 bool IsArrow,
2565 SourceLocation OperatorLoc,
2566 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002567 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002568 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002569 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002570 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002571 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002572 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002573
John McCallb268a282010-08-23 23:25:46 +00002574 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002575 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002576 SS, TemplateKWLoc,
2577 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002578 MemberNameInfo,
2579 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002580 }
2581
John McCall10eae182009-11-30 22:42:35 +00002582 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002583 ///
2584 /// By default, performs semantic analysis to build the new expression.
2585 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002586 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2587 SourceLocation OperatorLoc,
2588 bool IsArrow,
2589 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002590 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002591 NamedDecl *FirstQualifierInScope,
2592 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002593 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002594 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002595 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002596
John McCallb268a282010-08-23 23:25:46 +00002597 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002598 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002599 SS, TemplateKWLoc,
2600 FirstQualifierInScope,
John McCall38836f02010-01-15 08:34:02 +00002601 R, TemplateArgs);
Douglas Gregor308047d2009-09-09 00:23:06 +00002602 }
Mike Stump11289f42009-09-09 15:08:12 +00002603
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002604 /// \brief Build a new noexcept expression.
2605 ///
2606 /// By default, performs semantic analysis to build the new expression.
2607 /// Subclasses may override this routine to provide different behavior.
2608 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2609 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2610 }
2611
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002612 /// \brief Build a new expression to compute the length of a parameter pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00002613 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc, NamedDecl *Pack,
2614 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002615 SourceLocation RParenLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002616 Optional<unsigned> Length) {
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002617 if (Length)
Chad Rosier1dcde962012-08-08 18:46:20 +00002618 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2619 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002620 RParenLoc, *Length);
Chad Rosier1dcde962012-08-08 18:46:20 +00002621
2622 return new (SemaRef.Context) SizeOfPackExpr(SemaRef.Context.getSizeType(),
2623 OperatorLoc, Pack, PackLoc,
Douglas Gregorab96bcf2011-10-10 18:59:29 +00002624 RParenLoc);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002625 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002626
Patrick Beard0caa3942012-04-19 00:25:12 +00002627 /// \brief Build a new Objective-C boxed expression.
2628 ///
2629 /// By default, performs semantic analysis to build the new expression.
2630 /// Subclasses may override this routine to provide different behavior.
2631 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2632 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2633 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002634
Ted Kremeneke65b0862012-03-06 20:05:56 +00002635 /// \brief Build a new Objective-C array literal.
2636 ///
2637 /// By default, performs semantic analysis to build the new expression.
2638 /// Subclasses may override this routine to provide different behavior.
2639 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2640 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002641 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002642 MultiExprArg(Elements, NumElements));
2643 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002644
2645 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002646 Expr *Base, Expr *Key,
2647 ObjCMethodDecl *getterMethod,
2648 ObjCMethodDecl *setterMethod) {
2649 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2650 getterMethod, setterMethod);
2651 }
2652
2653 /// \brief Build a new Objective-C dictionary literal.
2654 ///
2655 /// By default, performs semantic analysis to build the new expression.
2656 /// Subclasses may override this routine to provide different behavior.
2657 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2658 ObjCDictionaryElement *Elements,
2659 unsigned NumElements) {
2660 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2661 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002662
James Dennett2a4d13c2012-06-15 07:13:21 +00002663 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002664 ///
2665 /// By default, performs semantic analysis to build the new expression.
2666 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002667 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002668 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002669 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002670 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002671 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002672
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002673 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002674 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002675 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002676 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002677 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002678 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002679 MultiExprArg Args,
2680 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002681 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2682 ReceiverTypeInfo->getType(),
2683 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002684 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002685 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002686 }
2687
2688 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002689 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002690 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002691 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002692 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002693 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002694 MultiExprArg Args,
2695 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002696 return SemaRef.BuildInstanceMessage(Receiver,
2697 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002698 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002699 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002700 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002701 }
2702
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002703 /// \brief Build a new Objective-C instance/class message to 'super'.
2704 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2705 Selector Sel,
2706 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002707 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002708 ObjCMethodDecl *Method,
2709 SourceLocation LBracLoc,
2710 MultiExprArg Args,
2711 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002712 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002713 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002714 SuperLoc,
2715 Sel, Method, LBracLoc, SelectorLocs,
2716 RBracLoc, Args)
2717 : SemaRef.BuildClassMessage(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
2723
2724 }
2725
Douglas Gregord51d90d2010-04-26 20:11:03 +00002726 /// \brief Build a new Objective-C ivar reference expression.
2727 ///
2728 /// By default, performs semantic analysis to build the new expression.
2729 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002730 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002731 SourceLocation IvarLoc,
2732 bool IsArrow, bool IsFreeIvar) {
2733 // FIXME: We lose track of the IsFreeIvar bit.
2734 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002735 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2736 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002737 /*FIXME:*/IvarLoc, IsArrow,
2738 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002739 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002740 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002741 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002742 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002743
2744 /// \brief Build a new Objective-C property reference expression.
2745 ///
2746 /// By default, performs semantic analysis to build the new expression.
2747 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002748 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002749 ObjCPropertyDecl *Property,
2750 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002751 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002752 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2753 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2754 /*FIXME:*/PropertyLoc,
2755 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002756 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002757 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002758 NameInfo,
2759 /*TemplateArgs=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002760 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002761
John McCallb7bd14f2010-12-02 01:19:52 +00002762 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002763 ///
2764 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002765 /// Subclasses may override this routine to provide different behavior.
2766 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2767 ObjCMethodDecl *Getter,
2768 ObjCMethodDecl *Setter,
2769 SourceLocation PropertyLoc) {
2770 // Since these expressions can only be value-dependent, we do not
2771 // need to perform semantic analysis again.
2772 return Owned(
2773 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2774 VK_LValue, OK_ObjCProperty,
2775 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002776 }
2777
Douglas Gregord51d90d2010-04-26 20:11:03 +00002778 /// \brief Build a new Objective-C "isa" expression.
2779 ///
2780 /// By default, performs semantic analysis to build the new expression.
2781 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002782 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002783 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002784 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002785 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2786 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002787 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002788 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002789 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002790 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00002791 /*TemplateArgs=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002792 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002793
Douglas Gregora16548e2009-08-11 05:31:07 +00002794 /// \brief Build a new shuffle vector expression.
2795 ///
2796 /// By default, performs semantic analysis to build the new expression.
2797 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002798 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002799 MultiExprArg SubExprs,
2800 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002801 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002802 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002803 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2804 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2805 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002806 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002807
Douglas Gregora16548e2009-08-11 05:31:07 +00002808 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002809 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002810 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2811 SemaRef.Context.BuiltinFnTy,
2812 VK_RValue, BuiltinLoc);
2813 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2814 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002815 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002816
2817 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002818 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002819 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002820 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002821
Douglas Gregora16548e2009-08-11 05:31:07 +00002822 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002823 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002824 }
John McCall31f82722010-11-12 08:19:04 +00002825
Hal Finkelc4d7c822013-09-18 03:29:45 +00002826 /// \brief Build a new convert vector expression.
2827 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2828 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2829 SourceLocation RParenLoc) {
2830 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2831 BuiltinLoc, RParenLoc);
2832 }
2833
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002834 /// \brief Build a new template argument pack expansion.
2835 ///
2836 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002837 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002838 /// different behavior.
2839 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002840 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002841 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002842 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002843 case TemplateArgument::Expression: {
2844 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002845 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2846 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002847 if (Result.isInvalid())
2848 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002849
Douglas Gregor98318c22011-01-03 21:37:45 +00002850 return TemplateArgumentLoc(Result.get(), Result.get());
2851 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002852
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002853 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002854 return TemplateArgumentLoc(TemplateArgument(
2855 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002856 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002857 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002858 Pattern.getTemplateNameLoc(),
2859 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002860
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002861 case TemplateArgument::Null:
2862 case TemplateArgument::Integral:
2863 case TemplateArgument::Declaration:
2864 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002865 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002866 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002867 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002868
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002869 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002870 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002871 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002872 EllipsisLoc,
2873 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002874 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2875 Expansion);
2876 break;
2877 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002878
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002879 return TemplateArgumentLoc();
2880 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002881
Douglas Gregor968f23a2011-01-03 19:31:53 +00002882 /// \brief Build a new expression pack expansion.
2883 ///
2884 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002885 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002886 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002887 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002888 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002889 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002890 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002891
Richard Smith0f0af192014-11-08 05:07:16 +00002892 /// \brief Build a new C++1z fold-expression.
2893 ///
2894 /// By default, performs semantic analysis in order to build a new fold
2895 /// expression.
2896 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
2897 BinaryOperatorKind Operator,
2898 SourceLocation EllipsisLoc, Expr *RHS,
2899 SourceLocation RParenLoc) {
2900 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
2901 RHS, RParenLoc);
2902 }
2903
2904 /// \brief Build an empty C++1z fold-expression with the given operator.
2905 ///
2906 /// By default, produces the fallback value for the fold-expression, or
2907 /// produce an error if there is no fallback value.
2908 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
2909 BinaryOperatorKind Operator) {
2910 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
2911 }
2912
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002913 /// \brief Build a new atomic operation expression.
2914 ///
2915 /// By default, performs semantic analysis to build the new expression.
2916 /// Subclasses may override this routine to provide different behavior.
2917 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2918 MultiExprArg SubExprs,
2919 QualType RetTy,
2920 AtomicExpr::AtomicOp Op,
2921 SourceLocation RParenLoc) {
2922 // Just create the expression; there is not any interesting semantic
2923 // analysis here because we can't actually build an AtomicExpr until
2924 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002925 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002926 RParenLoc);
2927 }
2928
John McCall31f82722010-11-12 08:19:04 +00002929private:
Douglas Gregor14454802011-02-25 02:25:35 +00002930 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2931 QualType ObjectType,
2932 NamedDecl *FirstQualifierInScope,
2933 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002934
2935 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2936 QualType ObjectType,
2937 NamedDecl *FirstQualifierInScope,
2938 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002939
2940 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2941 NamedDecl *FirstQualifierInScope,
2942 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002943};
Douglas Gregora16548e2009-08-11 05:31:07 +00002944
Douglas Gregorebe10102009-08-20 07:17:43 +00002945template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002946StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002947 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002948 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002949
Douglas Gregorebe10102009-08-20 07:17:43 +00002950 switch (S->getStmtClass()) {
2951 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002952
Douglas Gregorebe10102009-08-20 07:17:43 +00002953 // Transform individual statement nodes
2954#define STMT(Node, Parent) \
2955 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002956#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002957#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002958#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002959
Douglas Gregorebe10102009-08-20 07:17:43 +00002960 // Transform expressions by calling TransformExpr.
2961#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002962#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002963#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002964#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002965 {
John McCalldadc5752010-08-24 06:29:42 +00002966 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002967 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002968 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002969
Richard Smith945f8d32013-01-14 22:39:08 +00002970 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002971 }
Mike Stump11289f42009-09-09 15:08:12 +00002972 }
2973
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002974 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002975}
Mike Stump11289f42009-09-09 15:08:12 +00002976
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002977template<typename Derived>
2978OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2979 if (!S)
2980 return S;
2981
2982 switch (S->getClauseKind()) {
2983 default: break;
2984 // Transform individual clause nodes
2985#define OPENMP_CLAUSE(Name, Class) \
2986 case OMPC_ ## Name : \
2987 return getDerived().Transform ## Class(cast<Class>(S));
2988#include "clang/Basic/OpenMPKinds.def"
2989 }
2990
2991 return S;
2992}
2993
Mike Stump11289f42009-09-09 15:08:12 +00002994
Douglas Gregore922c772009-08-04 22:27:00 +00002995template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002996ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002997 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002998 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00002999
3000 switch (E->getStmtClass()) {
3001 case Stmt::NoStmtClass: break;
3002#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003003#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003004#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003005 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003006#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003007 }
3008
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003009 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003010}
3011
3012template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003013ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003014 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003015 // Initializers are instantiated like expressions, except that various outer
3016 // layers are stripped.
3017 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003018 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003019
3020 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3021 Init = ExprTemp->getSubExpr();
3022
Richard Smithe6ca4752013-05-30 22:40:16 +00003023 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3024 Init = MTE->GetTemporaryExpr();
3025
Richard Smithd59b8322012-12-19 01:39:02 +00003026 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3027 Init = Binder->getSubExpr();
3028
3029 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3030 Init = ICE->getSubExprAsWritten();
3031
Richard Smithcc1b96d2013-06-12 22:31:48 +00003032 if (CXXStdInitializerListExpr *ILE =
3033 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003034 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003035
Richard Smithc6abd962014-07-25 01:12:44 +00003036 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003037 // InitListExprs. Other forms of copy-initialization will be a no-op if
3038 // the initializer is already the right type.
3039 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003040 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003041 return getDerived().TransformExpr(Init);
3042
3043 // Revert value-initialization back to empty parens.
3044 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3045 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003046 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003047 Parens.getEnd());
3048 }
3049
3050 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3051 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003052 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003053 SourceLocation());
3054
3055 // Revert initialization by constructor back to a parenthesized or braced list
3056 // of expressions. Any other form of initializer can just be reused directly.
3057 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003058 return getDerived().TransformExpr(Init);
3059
Richard Smithf8adcdc2014-07-17 05:12:35 +00003060 // If the initialization implicitly converted an initializer list to a
3061 // std::initializer_list object, unwrap the std::initializer_list too.
3062 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003063 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003064
Richard Smithd59b8322012-12-19 01:39:02 +00003065 SmallVector<Expr*, 8> NewArgs;
3066 bool ArgChanged = false;
3067 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003068 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003069 return ExprError();
3070
3071 // If this was list initialization, revert to list form.
3072 if (Construct->isListInitialization())
3073 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3074 Construct->getLocEnd(),
3075 Construct->getType());
3076
Richard Smithd59b8322012-12-19 01:39:02 +00003077 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003078 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003079 if (Parens.isInvalid()) {
3080 // This was a variable declaration's initialization for which no initializer
3081 // was specified.
3082 assert(NewArgs.empty() &&
3083 "no parens or braces but have direct init with arguments?");
3084 return ExprEmpty();
3085 }
Richard Smithd59b8322012-12-19 01:39:02 +00003086 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3087 Parens.getEnd());
3088}
3089
3090template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00003091bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
3092 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003093 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003094 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003095 bool *ArgChanged) {
3096 for (unsigned I = 0; I != NumInputs; ++I) {
3097 // If requested, drop call arguments that need to be dropped.
3098 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3099 if (ArgChanged)
3100 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003101
Douglas Gregora3efea12011-01-03 19:04:46 +00003102 break;
3103 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003104
Douglas Gregor968f23a2011-01-03 19:31:53 +00003105 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3106 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003107
Chris Lattner01cf8db2011-07-20 06:58:45 +00003108 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003109 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3110 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003111
Douglas Gregor968f23a2011-01-03 19:31:53 +00003112 // Determine whether the set of unexpanded parameter packs can and should
3113 // be expanded.
3114 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003115 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003116 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3117 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003118 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3119 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003120 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003121 Expand, RetainExpansion,
3122 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003123 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003124
Douglas Gregor968f23a2011-01-03 19:31:53 +00003125 if (!Expand) {
3126 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003127 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003128 // expansion.
3129 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3130 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3131 if (OutPattern.isInvalid())
3132 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003133
3134 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003135 Expansion->getEllipsisLoc(),
3136 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003137 if (Out.isInvalid())
3138 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003139
Douglas Gregor968f23a2011-01-03 19:31:53 +00003140 if (ArgChanged)
3141 *ArgChanged = true;
3142 Outputs.push_back(Out.get());
3143 continue;
3144 }
John McCall542e7c62011-07-06 07:30:07 +00003145
3146 // Record right away that the argument was changed. This needs
3147 // to happen even if the array expands to nothing.
3148 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003149
Douglas Gregor968f23a2011-01-03 19:31:53 +00003150 // The transform has determined that we should perform an elementwise
3151 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003152 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003153 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3154 ExprResult Out = getDerived().TransformExpr(Pattern);
3155 if (Out.isInvalid())
3156 return true;
3157
Richard Smith9467be42014-06-06 17:33:35 +00003158 // FIXME: Can this happen? We should not try to expand the pack
3159 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003160 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003161 Out = getDerived().RebuildPackExpansion(
3162 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003163 if (Out.isInvalid())
3164 return true;
3165 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003166
Douglas Gregor968f23a2011-01-03 19:31:53 +00003167 Outputs.push_back(Out.get());
3168 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003169
Richard Smith9467be42014-06-06 17:33:35 +00003170 // If we're supposed to retain a pack expansion, do so by temporarily
3171 // forgetting the partially-substituted parameter pack.
3172 if (RetainExpansion) {
3173 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3174
3175 ExprResult Out = getDerived().TransformExpr(Pattern);
3176 if (Out.isInvalid())
3177 return true;
3178
3179 Out = getDerived().RebuildPackExpansion(
3180 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3181 if (Out.isInvalid())
3182 return true;
3183
3184 Outputs.push_back(Out.get());
3185 }
3186
Douglas Gregor968f23a2011-01-03 19:31:53 +00003187 continue;
3188 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003189
Richard Smithd59b8322012-12-19 01:39:02 +00003190 ExprResult Result =
3191 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3192 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003193 if (Result.isInvalid())
3194 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003195
Douglas Gregora3efea12011-01-03 19:04:46 +00003196 if (Result.get() != Inputs[I] && ArgChanged)
3197 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003198
3199 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003200 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003201
Douglas Gregora3efea12011-01-03 19:04:46 +00003202 return false;
3203}
3204
3205template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003206NestedNameSpecifierLoc
3207TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3208 NestedNameSpecifierLoc NNS,
3209 QualType ObjectType,
3210 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003211 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003212 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003213 Qualifier = Qualifier.getPrefix())
3214 Qualifiers.push_back(Qualifier);
3215
3216 CXXScopeSpec SS;
3217 while (!Qualifiers.empty()) {
3218 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3219 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003220
Douglas Gregor14454802011-02-25 02:25:35 +00003221 switch (QNNS->getKind()) {
3222 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003223 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003224 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003225 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003226 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003227 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003228 FirstQualifierInScope, false))
3229 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003230
Douglas Gregor14454802011-02-25 02:25:35 +00003231 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003232
Douglas Gregor14454802011-02-25 02:25:35 +00003233 case NestedNameSpecifier::Namespace: {
3234 NamespaceDecl *NS
3235 = cast_or_null<NamespaceDecl>(
3236 getDerived().TransformDecl(
3237 Q.getLocalBeginLoc(),
3238 QNNS->getAsNamespace()));
3239 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3240 break;
3241 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003242
Douglas Gregor14454802011-02-25 02:25:35 +00003243 case NestedNameSpecifier::NamespaceAlias: {
3244 NamespaceAliasDecl *Alias
3245 = cast_or_null<NamespaceAliasDecl>(
3246 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3247 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003248 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003249 Q.getLocalEndLoc());
3250 break;
3251 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003252
Douglas Gregor14454802011-02-25 02:25:35 +00003253 case NestedNameSpecifier::Global:
3254 // There is no meaningful transformation that one could perform on the
3255 // global scope.
3256 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3257 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003258
Nikola Smiljanic67860242014-09-26 00:28:20 +00003259 case NestedNameSpecifier::Super: {
3260 CXXRecordDecl *RD =
3261 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3262 SourceLocation(), QNNS->getAsRecordDecl()));
3263 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3264 break;
3265 }
3266
Douglas Gregor14454802011-02-25 02:25:35 +00003267 case NestedNameSpecifier::TypeSpecWithTemplate:
3268 case NestedNameSpecifier::TypeSpec: {
3269 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3270 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003271
Douglas Gregor14454802011-02-25 02:25:35 +00003272 if (!TL)
3273 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003274
Douglas Gregor14454802011-02-25 02:25:35 +00003275 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003276 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003277 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003278 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003279 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003280 if (TL.getType()->isEnumeralType())
3281 SemaRef.Diag(TL.getBeginLoc(),
3282 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003283 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3284 Q.getLocalEndLoc());
3285 break;
3286 }
Richard Trieude756fb2011-05-07 01:36:37 +00003287 // If the nested-name-specifier is an invalid type def, don't emit an
3288 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003289 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3290 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003291 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003292 << TL.getType() << SS.getRange();
3293 }
Douglas Gregor14454802011-02-25 02:25:35 +00003294 return NestedNameSpecifierLoc();
3295 }
Douglas Gregore16af532011-02-28 18:50:33 +00003296 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003297
Douglas Gregore16af532011-02-28 18:50:33 +00003298 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003299 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003300 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003301 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003302
Douglas Gregor14454802011-02-25 02:25:35 +00003303 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003304 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003305 !getDerived().AlwaysRebuild())
3306 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003307
3308 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003309 // nested-name-specifier, do so.
3310 if (SS.location_size() == NNS.getDataLength() &&
3311 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3312 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3313
3314 // Allocate new nested-name-specifier location information.
3315 return SS.getWithLocInContext(SemaRef.Context);
3316}
3317
3318template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003319DeclarationNameInfo
3320TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003321::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003322 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003323 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003324 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003325
3326 switch (Name.getNameKind()) {
3327 case DeclarationName::Identifier:
3328 case DeclarationName::ObjCZeroArgSelector:
3329 case DeclarationName::ObjCOneArgSelector:
3330 case DeclarationName::ObjCMultiArgSelector:
3331 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003332 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003333 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003334 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003335
Douglas Gregorf816bd72009-09-03 22:13:48 +00003336 case DeclarationName::CXXConstructorName:
3337 case DeclarationName::CXXDestructorName:
3338 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003339 TypeSourceInfo *NewTInfo;
3340 CanQualType NewCanTy;
3341 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003342 NewTInfo = getDerived().TransformType(OldTInfo);
3343 if (!NewTInfo)
3344 return DeclarationNameInfo();
3345 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003346 }
3347 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003348 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003349 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003350 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003351 if (NewT.isNull())
3352 return DeclarationNameInfo();
3353 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3354 }
Mike Stump11289f42009-09-09 15:08:12 +00003355
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003356 DeclarationName NewName
3357 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3358 NewCanTy);
3359 DeclarationNameInfo NewNameInfo(NameInfo);
3360 NewNameInfo.setName(NewName);
3361 NewNameInfo.setNamedTypeInfo(NewTInfo);
3362 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003363 }
Mike Stump11289f42009-09-09 15:08:12 +00003364 }
3365
David Blaikie83d382b2011-09-23 05:06:16 +00003366 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003367}
3368
3369template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003370TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003371TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3372 TemplateName Name,
3373 SourceLocation NameLoc,
3374 QualType ObjectType,
3375 NamedDecl *FirstQualifierInScope) {
3376 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3377 TemplateDecl *Template = QTN->getTemplateDecl();
3378 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003379
Douglas Gregor9db53502011-03-02 18:07:45 +00003380 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003381 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003382 Template));
3383 if (!TransTemplate)
3384 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003385
Douglas Gregor9db53502011-03-02 18:07:45 +00003386 if (!getDerived().AlwaysRebuild() &&
3387 SS.getScopeRep() == QTN->getQualifier() &&
3388 TransTemplate == Template)
3389 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003390
Douglas Gregor9db53502011-03-02 18:07:45 +00003391 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3392 TransTemplate);
3393 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003394
Douglas Gregor9db53502011-03-02 18:07:45 +00003395 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3396 if (SS.getScopeRep()) {
3397 // These apply to the scope specifier, not the template.
3398 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003399 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003400 }
3401
Douglas Gregor9db53502011-03-02 18:07:45 +00003402 if (!getDerived().AlwaysRebuild() &&
3403 SS.getScopeRep() == DTN->getQualifier() &&
3404 ObjectType.isNull())
3405 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003406
Douglas Gregor9db53502011-03-02 18:07:45 +00003407 if (DTN->isIdentifier()) {
3408 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003409 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003410 NameLoc,
3411 ObjectType,
3412 FirstQualifierInScope);
3413 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003414
Douglas Gregor9db53502011-03-02 18:07:45 +00003415 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3416 ObjectType);
3417 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003418
Douglas Gregor9db53502011-03-02 18:07:45 +00003419 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3420 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003421 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003422 Template));
3423 if (!TransTemplate)
3424 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003425
Douglas Gregor9db53502011-03-02 18:07:45 +00003426 if (!getDerived().AlwaysRebuild() &&
3427 TransTemplate == Template)
3428 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003429
Douglas Gregor9db53502011-03-02 18:07:45 +00003430 return TemplateName(TransTemplate);
3431 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003432
Douglas Gregor9db53502011-03-02 18:07:45 +00003433 if (SubstTemplateTemplateParmPackStorage *SubstPack
3434 = Name.getAsSubstTemplateTemplateParmPack()) {
3435 TemplateTemplateParmDecl *TransParam
3436 = cast_or_null<TemplateTemplateParmDecl>(
3437 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3438 if (!TransParam)
3439 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003440
Douglas Gregor9db53502011-03-02 18:07:45 +00003441 if (!getDerived().AlwaysRebuild() &&
3442 TransParam == SubstPack->getParameterPack())
3443 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003444
3445 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003446 SubstPack->getArgumentPack());
3447 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003448
Douglas Gregor9db53502011-03-02 18:07:45 +00003449 // These should be getting filtered out before they reach the AST.
3450 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003451}
3452
3453template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003454void TreeTransform<Derived>::InventTemplateArgumentLoc(
3455 const TemplateArgument &Arg,
3456 TemplateArgumentLoc &Output) {
3457 SourceLocation Loc = getDerived().getBaseLocation();
3458 switch (Arg.getKind()) {
3459 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003460 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003461 break;
3462
3463 case TemplateArgument::Type:
3464 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003465 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003466
John McCall0ad16662009-10-29 08:12:44 +00003467 break;
3468
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003469 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003470 case TemplateArgument::TemplateExpansion: {
3471 NestedNameSpecifierLocBuilder Builder;
3472 TemplateName Template = Arg.getAsTemplate();
3473 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3474 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3475 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3476 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003477
Douglas Gregor9d802122011-03-02 17:09:35 +00003478 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003479 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003480 Builder.getWithLocInContext(SemaRef.Context),
3481 Loc);
3482 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003483 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003484 Builder.getWithLocInContext(SemaRef.Context),
3485 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003486
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003487 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003488 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003489
John McCall0ad16662009-10-29 08:12:44 +00003490 case TemplateArgument::Expression:
3491 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3492 break;
3493
3494 case TemplateArgument::Declaration:
3495 case TemplateArgument::Integral:
3496 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003497 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003498 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003499 break;
3500 }
3501}
3502
3503template<typename Derived>
3504bool TreeTransform<Derived>::TransformTemplateArgument(
3505 const TemplateArgumentLoc &Input,
3506 TemplateArgumentLoc &Output) {
3507 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003508 switch (Arg.getKind()) {
3509 case TemplateArgument::Null:
3510 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003511 case TemplateArgument::Pack:
3512 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003513 case TemplateArgument::NullPtr:
3514 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003515
Douglas Gregore922c772009-08-04 22:27:00 +00003516 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003517 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003518 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003519 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003520
3521 DI = getDerived().TransformType(DI);
3522 if (!DI) return true;
3523
3524 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3525 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003526 }
Mike Stump11289f42009-09-09 15:08:12 +00003527
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003528 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003529 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3530 if (QualifierLoc) {
3531 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3532 if (!QualifierLoc)
3533 return true;
3534 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003535
Douglas Gregordf846d12011-03-02 18:46:51 +00003536 CXXScopeSpec SS;
3537 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003538 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003539 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3540 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003541 if (Template.isNull())
3542 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003543
Douglas Gregor9d802122011-03-02 17:09:35 +00003544 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003545 Input.getTemplateNameLoc());
3546 return false;
3547 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003548
3549 case TemplateArgument::TemplateExpansion:
3550 llvm_unreachable("Caller should expand pack expansions");
3551
Douglas Gregore922c772009-08-04 22:27:00 +00003552 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003553 // Template argument expressions are constant expressions.
Mike Stump11289f42009-09-09 15:08:12 +00003554 EnterExpressionEvaluationContext Unevaluated(getSema(),
Richard Smith764d2fe2011-12-20 02:08:33 +00003555 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003556
John McCall0ad16662009-10-29 08:12:44 +00003557 Expr *InputExpr = Input.getSourceExpression();
3558 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3559
Chris Lattnercdb591a2011-04-25 20:37:58 +00003560 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003561 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003562 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003563 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003564 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003565 }
Douglas Gregore922c772009-08-04 22:27:00 +00003566 }
Mike Stump11289f42009-09-09 15:08:12 +00003567
Douglas Gregore922c772009-08-04 22:27:00 +00003568 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003569 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003570}
3571
Douglas Gregorfe921a72010-12-20 23:36:19 +00003572/// \brief Iterator adaptor that invents template argument location information
3573/// for each of the template arguments in its underlying iterator.
3574template<typename Derived, typename InputIterator>
3575class TemplateArgumentLocInventIterator {
3576 TreeTransform<Derived> &Self;
3577 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003578
Douglas Gregorfe921a72010-12-20 23:36:19 +00003579public:
3580 typedef TemplateArgumentLoc value_type;
3581 typedef TemplateArgumentLoc reference;
3582 typedef typename std::iterator_traits<InputIterator>::difference_type
3583 difference_type;
3584 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003585
Douglas Gregorfe921a72010-12-20 23:36:19 +00003586 class pointer {
3587 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003588
Douglas Gregorfe921a72010-12-20 23:36:19 +00003589 public:
3590 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003591
Douglas Gregorfe921a72010-12-20 23:36:19 +00003592 const TemplateArgumentLoc *operator->() const { return &Arg; }
3593 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003594
Douglas Gregorfe921a72010-12-20 23:36:19 +00003595 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003596
Douglas Gregorfe921a72010-12-20 23:36:19 +00003597 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3598 InputIterator Iter)
3599 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003600
Douglas Gregorfe921a72010-12-20 23:36:19 +00003601 TemplateArgumentLocInventIterator &operator++() {
3602 ++Iter;
3603 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003604 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003605
Douglas Gregorfe921a72010-12-20 23:36:19 +00003606 TemplateArgumentLocInventIterator operator++(int) {
3607 TemplateArgumentLocInventIterator Old(*this);
3608 ++(*this);
3609 return Old;
3610 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003611
Douglas Gregorfe921a72010-12-20 23:36:19 +00003612 reference operator*() const {
3613 TemplateArgumentLoc Result;
3614 Self.InventTemplateArgumentLoc(*Iter, Result);
3615 return Result;
3616 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003617
Douglas Gregorfe921a72010-12-20 23:36:19 +00003618 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003619
Douglas Gregorfe921a72010-12-20 23:36:19 +00003620 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3621 const TemplateArgumentLocInventIterator &Y) {
3622 return X.Iter == Y.Iter;
3623 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003624
Douglas Gregorfe921a72010-12-20 23:36:19 +00003625 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3626 const TemplateArgumentLocInventIterator &Y) {
3627 return X.Iter != Y.Iter;
3628 }
3629};
Chad Rosier1dcde962012-08-08 18:46:20 +00003630
Douglas Gregor42cafa82010-12-20 17:42:22 +00003631template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003632template<typename InputIterator>
3633bool TreeTransform<Derived>::TransformTemplateArguments(InputIterator First,
3634 InputIterator Last,
Douglas Gregor42cafa82010-12-20 17:42:22 +00003635 TemplateArgumentListInfo &Outputs) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003636 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003637 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003638 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003639
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003640 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3641 // Unpack argument packs, which we translate them into separate
3642 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003643 // FIXME: We could do much better if we could guarantee that the
3644 // TemplateArgumentLocInfo for the pack expansion would be usable for
3645 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003646 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003647 TemplateArgument::pack_iterator>
3648 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003649 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003650 In.getArgument().pack_begin()),
3651 PackLocIterator(*this,
3652 In.getArgument().pack_end()),
3653 Outputs))
3654 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003655
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003656 continue;
3657 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003658
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003659 if (In.getArgument().isPackExpansion()) {
3660 // We have a pack expansion, for which we will be substituting into
3661 // the pattern.
3662 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003663 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003664 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003665 = getSema().getTemplateArgumentPackExpansionPattern(
3666 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003667
Chris Lattner01cf8db2011-07-20 06:58:45 +00003668 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003669 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3670 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003671
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003672 // Determine whether the set of unexpanded parameter packs can and should
3673 // be expanded.
3674 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003675 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003676 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003677 if (getDerived().TryExpandParameterPacks(Ellipsis,
3678 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003679 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003680 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003681 RetainExpansion,
3682 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003683 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003684
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003685 if (!Expand) {
3686 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003687 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003688 // expansion.
3689 TemplateArgumentLoc OutPattern;
3690 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3691 if (getDerived().TransformTemplateArgument(Pattern, OutPattern))
3692 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003693
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003694 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3695 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003696 if (Out.getArgument().isNull())
3697 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003698
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003699 Outputs.addArgument(Out);
3700 continue;
3701 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003702
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003703 // The transform has determined that we should perform an elementwise
3704 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003705 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003706 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3707
3708 if (getDerived().TransformTemplateArgument(Pattern, Out))
3709 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003710
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003711 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003712 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3713 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003714 if (Out.getArgument().isNull())
3715 return true;
3716 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003717
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003718 Outputs.addArgument(Out);
3719 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003720
Douglas Gregor48d24112011-01-10 20:53:55 +00003721 // If we're supposed to retain a pack expansion, do so by temporarily
3722 // forgetting the partially-substituted parameter pack.
3723 if (RetainExpansion) {
3724 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003725
Douglas Gregor48d24112011-01-10 20:53:55 +00003726 if (getDerived().TransformTemplateArgument(Pattern, Out))
3727 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003728
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003729 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3730 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003731 if (Out.getArgument().isNull())
3732 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003733
Douglas Gregor48d24112011-01-10 20:53:55 +00003734 Outputs.addArgument(Out);
3735 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003736
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003737 continue;
3738 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003739
3740 // The simple case:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003741 if (getDerived().TransformTemplateArgument(In, Out))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003742 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003743
Douglas Gregor42cafa82010-12-20 17:42:22 +00003744 Outputs.addArgument(Out);
3745 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003746
Douglas Gregor42cafa82010-12-20 17:42:22 +00003747 return false;
3748
3749}
3750
Douglas Gregord6ff3322009-08-04 16:50:30 +00003751//===----------------------------------------------------------------------===//
3752// Type transformation
3753//===----------------------------------------------------------------------===//
3754
3755template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003756QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003757 if (getDerived().AlreadyTransformed(T))
3758 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003759
John McCall550e0c22009-10-21 00:40:46 +00003760 // Temporary workaround. All of these transformations should
3761 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003762 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3763 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003764
John McCall31f82722010-11-12 08:19:04 +00003765 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003766
John McCall550e0c22009-10-21 00:40:46 +00003767 if (!NewDI)
3768 return QualType();
3769
3770 return NewDI->getType();
3771}
3772
3773template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003774TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003775 // Refine the base location to the type's location.
3776 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3777 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003778 if (getDerived().AlreadyTransformed(DI->getType()))
3779 return DI;
3780
3781 TypeLocBuilder TLB;
3782
3783 TypeLoc TL = DI->getTypeLoc();
3784 TLB.reserve(TL.getFullDataSize());
3785
John McCall31f82722010-11-12 08:19:04 +00003786 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003787 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003788 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003789
John McCallbcd03502009-12-07 02:54:59 +00003790 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003791}
3792
3793template<typename Derived>
3794QualType
John McCall31f82722010-11-12 08:19:04 +00003795TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003796 switch (T.getTypeLocClass()) {
3797#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003798#define TYPELOC(CLASS, PARENT) \
3799 case TypeLoc::CLASS: \
3800 return getDerived().Transform##CLASS##Type(TLB, \
3801 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003802#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003803 }
Mike Stump11289f42009-09-09 15:08:12 +00003804
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003805 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003806}
3807
3808/// FIXME: By default, this routine adds type qualifiers only to types
3809/// that can have qualifiers, and silently suppresses those qualifiers
3810/// that are not permitted (e.g., qualifiers on reference or function
3811/// types). This is the right thing for template instantiation, but
3812/// probably not for other clients.
3813template<typename Derived>
3814QualType
3815TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003816 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003817 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003818
John McCall31f82722010-11-12 08:19:04 +00003819 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003820 if (Result.isNull())
3821 return QualType();
3822
3823 // Silently suppress qualifiers if the result type can't be qualified.
3824 // FIXME: this is the right thing for template instantiation, but
3825 // probably not for other clients.
3826 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003827 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003828
John McCall31168b02011-06-15 23:02:42 +00003829 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003830 // resulting type.
3831 if (Quals.hasObjCLifetime()) {
3832 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3833 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003834 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003835 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003836 // A lifetime qualifier applied to a substituted template parameter
3837 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003838 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003839 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003840 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3841 QualType Replacement = SubstTypeParam->getReplacementType();
3842 Qualifiers Qs = Replacement.getQualifiers();
3843 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003844 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003845 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3846 Qs);
3847 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003848 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003849 Replacement);
3850 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003851 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3852 // 'auto' types behave the same way as template parameters.
3853 QualType Deduced = AutoTy->getDeducedType();
3854 Qualifiers Qs = Deduced.getQualifiers();
3855 Qs.removeObjCLifetime();
3856 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3857 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003858 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3859 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003860 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003861 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003862 // Otherwise, complain about the addition of a qualifier to an
3863 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003864 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003865 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003866 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003867
Douglas Gregore46db902011-06-17 22:11:49 +00003868 Quals.removeObjCLifetime();
3869 }
3870 }
3871 }
John McCallcb0f89a2010-06-05 06:41:15 +00003872 if (!Quals.empty()) {
3873 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003874 // BuildQualifiedType might not add qualifiers if they are invalid.
3875 if (Result.hasLocalQualifiers())
3876 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003877 // No location information to preserve.
3878 }
John McCall550e0c22009-10-21 00:40:46 +00003879
3880 return Result;
3881}
3882
Douglas Gregor14454802011-02-25 02:25:35 +00003883template<typename Derived>
3884TypeLoc
3885TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3886 QualType ObjectType,
3887 NamedDecl *UnqualLookup,
3888 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003889 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003890 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003891
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003892 TypeSourceInfo *TSI =
3893 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3894 if (TSI)
3895 return TSI->getTypeLoc();
3896 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003897}
3898
Douglas Gregor579c15f2011-03-02 18:32:08 +00003899template<typename Derived>
3900TypeSourceInfo *
3901TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3902 QualType ObjectType,
3903 NamedDecl *UnqualLookup,
3904 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003905 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003906 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003907
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003908 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3909 UnqualLookup, SS);
3910}
3911
3912template <typename Derived>
3913TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3914 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3915 CXXScopeSpec &SS) {
3916 QualType T = TL.getType();
3917 assert(!getDerived().AlreadyTransformed(T));
3918
Douglas Gregor579c15f2011-03-02 18:32:08 +00003919 TypeLocBuilder TLB;
3920 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003921
Douglas Gregor579c15f2011-03-02 18:32:08 +00003922 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003923 TemplateSpecializationTypeLoc SpecTL =
3924 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003925
Douglas Gregor579c15f2011-03-02 18:32:08 +00003926 TemplateName Template
3927 = getDerived().TransformTemplateName(SS,
3928 SpecTL.getTypePtr()->getTemplateName(),
3929 SpecTL.getTemplateNameLoc(),
3930 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003931 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003932 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003933
3934 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003935 Template);
3936 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003937 DependentTemplateSpecializationTypeLoc SpecTL =
3938 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003939
Douglas Gregor579c15f2011-03-02 18:32:08 +00003940 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003941 = getDerived().RebuildTemplateName(SS,
3942 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003943 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003944 ObjectType, UnqualLookup);
3945 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003946 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003947
3948 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003949 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003950 Template,
3951 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003952 } else {
3953 // Nothing special needs to be done for these.
3954 Result = getDerived().TransformType(TLB, TL);
3955 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003956
3957 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003958 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003959
Douglas Gregor579c15f2011-03-02 18:32:08 +00003960 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3961}
3962
John McCall550e0c22009-10-21 00:40:46 +00003963template <class TyLoc> static inline
3964QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3965 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3966 NewT.setNameLoc(T.getNameLoc());
3967 return T.getType();
3968}
3969
John McCall550e0c22009-10-21 00:40:46 +00003970template<typename Derived>
3971QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003972 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003973 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3974 NewT.setBuiltinLoc(T.getBuiltinLoc());
3975 if (T.needsExtraLocalData())
3976 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3977 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003978}
Mike Stump11289f42009-09-09 15:08:12 +00003979
Douglas Gregord6ff3322009-08-04 16:50:30 +00003980template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003981QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003982 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003983 // FIXME: recurse?
3984 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003985}
Mike Stump11289f42009-09-09 15:08:12 +00003986
Reid Kleckner0503a872013-12-05 01:23:43 +00003987template <typename Derived>
3988QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3989 AdjustedTypeLoc TL) {
3990 // Adjustments applied during transformation are handled elsewhere.
3991 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3992}
3993
Douglas Gregord6ff3322009-08-04 16:50:30 +00003994template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00003995QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
3996 DecayedTypeLoc TL) {
3997 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
3998 if (OriginalType.isNull())
3999 return QualType();
4000
4001 QualType Result = TL.getType();
4002 if (getDerived().AlwaysRebuild() ||
4003 OriginalType != TL.getOriginalLoc().getType())
4004 Result = SemaRef.Context.getDecayedType(OriginalType);
4005 TLB.push<DecayedTypeLoc>(Result);
4006 // Nothing to set for DecayedTypeLoc.
4007 return Result;
4008}
4009
4010template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004011QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004012 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004013 QualType PointeeType
4014 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004015 if (PointeeType.isNull())
4016 return QualType();
4017
4018 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004019 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004020 // A dependent pointer type 'T *' has is being transformed such
4021 // that an Objective-C class type is being replaced for 'T'. The
4022 // resulting pointer type is an ObjCObjectPointerType, not a
4023 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004024 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004025
John McCall8b07ec22010-05-15 11:32:37 +00004026 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4027 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004028 return Result;
4029 }
John McCall31f82722010-11-12 08:19:04 +00004030
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004031 if (getDerived().AlwaysRebuild() ||
4032 PointeeType != TL.getPointeeLoc().getType()) {
4033 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4034 if (Result.isNull())
4035 return QualType();
4036 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004037
John McCall31168b02011-06-15 23:02:42 +00004038 // Objective-C ARC can add lifetime qualifiers to the type that we're
4039 // pointing to.
4040 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004041
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004042 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4043 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004044 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004045}
Mike Stump11289f42009-09-09 15:08:12 +00004046
4047template<typename Derived>
4048QualType
John McCall550e0c22009-10-21 00:40:46 +00004049TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004050 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004051 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004052 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4053 if (PointeeType.isNull())
4054 return QualType();
4055
4056 QualType Result = TL.getType();
4057 if (getDerived().AlwaysRebuild() ||
4058 PointeeType != TL.getPointeeLoc().getType()) {
4059 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004060 TL.getSigilLoc());
4061 if (Result.isNull())
4062 return QualType();
4063 }
4064
Douglas Gregor049211a2010-04-22 16:50:51 +00004065 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004066 NewT.setSigilLoc(TL.getSigilLoc());
4067 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004068}
4069
John McCall70dd5f62009-10-30 00:06:24 +00004070/// Transforms a reference type. Note that somewhat paradoxically we
4071/// don't care whether the type itself is an l-value type or an r-value
4072/// type; we only care if the type was *written* as an l-value type
4073/// or an r-value type.
4074template<typename Derived>
4075QualType
4076TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004077 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004078 const ReferenceType *T = TL.getTypePtr();
4079
4080 // Note that this works with the pointee-as-written.
4081 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4082 if (PointeeType.isNull())
4083 return QualType();
4084
4085 QualType Result = TL.getType();
4086 if (getDerived().AlwaysRebuild() ||
4087 PointeeType != T->getPointeeTypeAsWritten()) {
4088 Result = getDerived().RebuildReferenceType(PointeeType,
4089 T->isSpelledAsLValue(),
4090 TL.getSigilLoc());
4091 if (Result.isNull())
4092 return QualType();
4093 }
4094
John McCall31168b02011-06-15 23:02:42 +00004095 // Objective-C ARC can add lifetime qualifiers to the type that we're
4096 // referring to.
4097 TLB.TypeWasModifiedSafely(
4098 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4099
John McCall70dd5f62009-10-30 00:06:24 +00004100 // r-value references can be rebuilt as l-value references.
4101 ReferenceTypeLoc NewTL;
4102 if (isa<LValueReferenceType>(Result))
4103 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4104 else
4105 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4106 NewTL.setSigilLoc(TL.getSigilLoc());
4107
4108 return Result;
4109}
4110
Mike Stump11289f42009-09-09 15:08:12 +00004111template<typename Derived>
4112QualType
John McCall550e0c22009-10-21 00:40:46 +00004113TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004114 LValueReferenceTypeLoc TL) {
4115 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004116}
4117
Mike Stump11289f42009-09-09 15:08:12 +00004118template<typename Derived>
4119QualType
John McCall550e0c22009-10-21 00:40:46 +00004120TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004121 RValueReferenceTypeLoc TL) {
4122 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004123}
Mike Stump11289f42009-09-09 15:08:12 +00004124
Douglas Gregord6ff3322009-08-04 16:50:30 +00004125template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004126QualType
John McCall550e0c22009-10-21 00:40:46 +00004127TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004128 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004129 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004130 if (PointeeType.isNull())
4131 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004132
Abramo Bagnara509357842011-03-05 14:42:21 +00004133 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004134 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004135 if (OldClsTInfo) {
4136 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4137 if (!NewClsTInfo)
4138 return QualType();
4139 }
4140
4141 const MemberPointerType *T = TL.getTypePtr();
4142 QualType OldClsType = QualType(T->getClass(), 0);
4143 QualType NewClsType;
4144 if (NewClsTInfo)
4145 NewClsType = NewClsTInfo->getType();
4146 else {
4147 NewClsType = getDerived().TransformType(OldClsType);
4148 if (NewClsType.isNull())
4149 return QualType();
4150 }
Mike Stump11289f42009-09-09 15:08:12 +00004151
John McCall550e0c22009-10-21 00:40:46 +00004152 QualType Result = TL.getType();
4153 if (getDerived().AlwaysRebuild() ||
4154 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004155 NewClsType != OldClsType) {
4156 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004157 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004158 if (Result.isNull())
4159 return QualType();
4160 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004161
Reid Kleckner0503a872013-12-05 01:23:43 +00004162 // If we had to adjust the pointee type when building a member pointer, make
4163 // sure to push TypeLoc info for it.
4164 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4165 if (MPT && PointeeType != MPT->getPointeeType()) {
4166 assert(isa<AdjustedType>(MPT->getPointeeType()));
4167 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4168 }
4169
John McCall550e0c22009-10-21 00:40:46 +00004170 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4171 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004172 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004173
4174 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004175}
4176
Mike Stump11289f42009-09-09 15:08:12 +00004177template<typename Derived>
4178QualType
John McCall550e0c22009-10-21 00:40:46 +00004179TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004180 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004181 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004182 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004183 if (ElementType.isNull())
4184 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004185
John McCall550e0c22009-10-21 00:40:46 +00004186 QualType Result = TL.getType();
4187 if (getDerived().AlwaysRebuild() ||
4188 ElementType != T->getElementType()) {
4189 Result = getDerived().RebuildConstantArrayType(ElementType,
4190 T->getSizeModifier(),
4191 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004192 T->getIndexTypeCVRQualifiers(),
4193 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004194 if (Result.isNull())
4195 return QualType();
4196 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004197
4198 // We might have either a ConstantArrayType or a VariableArrayType now:
4199 // a ConstantArrayType is allowed to have an element type which is a
4200 // VariableArrayType if the type is dependent. Fortunately, all array
4201 // types have the same location layout.
4202 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004203 NewTL.setLBracketLoc(TL.getLBracketLoc());
4204 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004205
John McCall550e0c22009-10-21 00:40:46 +00004206 Expr *Size = TL.getSizeExpr();
4207 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004208 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4209 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004210 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4211 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004212 }
4213 NewTL.setSizeExpr(Size);
4214
4215 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004216}
Mike Stump11289f42009-09-09 15:08:12 +00004217
Douglas Gregord6ff3322009-08-04 16:50:30 +00004218template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004219QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004220 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004221 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004222 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004223 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004224 if (ElementType.isNull())
4225 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004226
John McCall550e0c22009-10-21 00:40:46 +00004227 QualType Result = TL.getType();
4228 if (getDerived().AlwaysRebuild() ||
4229 ElementType != T->getElementType()) {
4230 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004231 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004232 T->getIndexTypeCVRQualifiers(),
4233 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004234 if (Result.isNull())
4235 return QualType();
4236 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004237
John McCall550e0c22009-10-21 00:40:46 +00004238 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4239 NewTL.setLBracketLoc(TL.getLBracketLoc());
4240 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004241 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004242
4243 return Result;
4244}
4245
4246template<typename Derived>
4247QualType
4248TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004249 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004250 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004251 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4252 if (ElementType.isNull())
4253 return QualType();
4254
John McCalldadc5752010-08-24 06:29:42 +00004255 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004256 = getDerived().TransformExpr(T->getSizeExpr());
4257 if (SizeResult.isInvalid())
4258 return QualType();
4259
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004260 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004261
4262 QualType Result = TL.getType();
4263 if (getDerived().AlwaysRebuild() ||
4264 ElementType != T->getElementType() ||
4265 Size != T->getSizeExpr()) {
4266 Result = getDerived().RebuildVariableArrayType(ElementType,
4267 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004268 Size,
John McCall550e0c22009-10-21 00:40:46 +00004269 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004270 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004271 if (Result.isNull())
4272 return QualType();
4273 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004274
Serge Pavlov774c6d02014-02-06 03:49:11 +00004275 // We might have constant size array now, but fortunately it has the same
4276 // location layout.
4277 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004278 NewTL.setLBracketLoc(TL.getLBracketLoc());
4279 NewTL.setRBracketLoc(TL.getRBracketLoc());
4280 NewTL.setSizeExpr(Size);
4281
4282 return Result;
4283}
4284
4285template<typename Derived>
4286QualType
4287TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004288 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004289 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004290 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4291 if (ElementType.isNull())
4292 return QualType();
4293
Richard Smith764d2fe2011-12-20 02:08:33 +00004294 // Array bounds are constant expressions.
4295 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4296 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004297
John McCall33ddac02011-01-19 10:06:00 +00004298 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4299 Expr *origSize = TL.getSizeExpr();
4300 if (!origSize) origSize = T->getSizeExpr();
4301
4302 ExprResult sizeResult
4303 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004304 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004305 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004306 return QualType();
4307
John McCall33ddac02011-01-19 10:06:00 +00004308 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004309
4310 QualType Result = TL.getType();
4311 if (getDerived().AlwaysRebuild() ||
4312 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004313 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004314 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4315 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004316 size,
John McCall550e0c22009-10-21 00:40:46 +00004317 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004318 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004319 if (Result.isNull())
4320 return QualType();
4321 }
John McCall550e0c22009-10-21 00:40:46 +00004322
4323 // We might have any sort of array type now, but fortunately they
4324 // all have the same location layout.
4325 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4326 NewTL.setLBracketLoc(TL.getLBracketLoc());
4327 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004328 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004329
4330 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004331}
Mike Stump11289f42009-09-09 15:08:12 +00004332
4333template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004334QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004335 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004336 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004337 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004338
4339 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004340 QualType ElementType = getDerived().TransformType(T->getElementType());
4341 if (ElementType.isNull())
4342 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004343
Richard Smith764d2fe2011-12-20 02:08:33 +00004344 // Vector sizes are constant expressions.
4345 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4346 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004347
John McCalldadc5752010-08-24 06:29:42 +00004348 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004349 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004350 if (Size.isInvalid())
4351 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004352
John McCall550e0c22009-10-21 00:40:46 +00004353 QualType Result = TL.getType();
4354 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004355 ElementType != T->getElementType() ||
4356 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004357 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004358 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004359 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004360 if (Result.isNull())
4361 return QualType();
4362 }
John McCall550e0c22009-10-21 00:40:46 +00004363
4364 // Result might be dependent or not.
4365 if (isa<DependentSizedExtVectorType>(Result)) {
4366 DependentSizedExtVectorTypeLoc NewTL
4367 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4368 NewTL.setNameLoc(TL.getNameLoc());
4369 } else {
4370 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4371 NewTL.setNameLoc(TL.getNameLoc());
4372 }
4373
4374 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004375}
Mike Stump11289f42009-09-09 15:08:12 +00004376
4377template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004378QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004379 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004380 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004381 QualType ElementType = getDerived().TransformType(T->getElementType());
4382 if (ElementType.isNull())
4383 return QualType();
4384
John McCall550e0c22009-10-21 00:40:46 +00004385 QualType Result = TL.getType();
4386 if (getDerived().AlwaysRebuild() ||
4387 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004388 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004389 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004390 if (Result.isNull())
4391 return QualType();
4392 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004393
John McCall550e0c22009-10-21 00:40:46 +00004394 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4395 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004396
John McCall550e0c22009-10-21 00:40:46 +00004397 return Result;
4398}
4399
4400template<typename Derived>
4401QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004402 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004403 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004404 QualType ElementType = getDerived().TransformType(T->getElementType());
4405 if (ElementType.isNull())
4406 return QualType();
4407
4408 QualType Result = TL.getType();
4409 if (getDerived().AlwaysRebuild() ||
4410 ElementType != T->getElementType()) {
4411 Result = getDerived().RebuildExtVectorType(ElementType,
4412 T->getNumElements(),
4413 /*FIXME*/ SourceLocation());
4414 if (Result.isNull())
4415 return QualType();
4416 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004417
John McCall550e0c22009-10-21 00:40:46 +00004418 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4419 NewTL.setNameLoc(TL.getNameLoc());
4420
4421 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004422}
Mike Stump11289f42009-09-09 15:08:12 +00004423
David Blaikie05785d12013-02-20 22:23:23 +00004424template <typename Derived>
4425ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4426 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4427 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004428 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004429 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004430
Douglas Gregor715e4612011-01-14 22:40:04 +00004431 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004432 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004433 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004434 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004435 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004436
Douglas Gregor715e4612011-01-14 22:40:04 +00004437 TypeLocBuilder TLB;
4438 TypeLoc NewTL = OldDI->getTypeLoc();
4439 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004440
4441 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004442 OldExpansionTL.getPatternLoc());
4443 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004444 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004445
4446 Result = RebuildPackExpansionType(Result,
4447 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004448 OldExpansionTL.getEllipsisLoc(),
4449 NumExpansions);
4450 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004451 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004452
Douglas Gregor715e4612011-01-14 22:40:04 +00004453 PackExpansionTypeLoc NewExpansionTL
4454 = TLB.push<PackExpansionTypeLoc>(Result);
4455 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4456 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4457 } else
4458 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004459 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004460 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004461
John McCall8fb0d9d2011-05-01 22:35:37 +00004462 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004463 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004464
4465 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4466 OldParm->getDeclContext(),
4467 OldParm->getInnerLocStart(),
4468 OldParm->getLocation(),
4469 OldParm->getIdentifier(),
4470 NewDI->getType(),
4471 NewDI,
4472 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004473 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004474 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4475 OldParm->getFunctionScopeIndex() + indexAdjustment);
4476 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004477}
4478
4479template<typename Derived>
4480bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004481 TransformFunctionTypeParams(SourceLocation Loc,
4482 ParmVarDecl **Params, unsigned NumParams,
4483 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004484 SmallVectorImpl<QualType> &OutParamTypes,
4485 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004486 int indexAdjustment = 0;
4487
Douglas Gregordd472162011-01-07 00:20:55 +00004488 for (unsigned i = 0; i != NumParams; ++i) {
4489 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004490 assert(OldParm->getFunctionScopeIndex() == i);
4491
David Blaikie05785d12013-02-20 22:23:23 +00004492 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004493 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004494 if (OldParm->isParameterPack()) {
4495 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004496 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004497
Douglas Gregor5499af42011-01-05 23:12:31 +00004498 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004499 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004500 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004501 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4502 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004503 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4504
Douglas Gregor5499af42011-01-05 23:12:31 +00004505 // Determine whether we should expand the parameter packs.
4506 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004507 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004508 Optional<unsigned> OrigNumExpansions =
4509 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004510 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004511 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4512 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004513 Unexpanded,
4514 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004515 RetainExpansion,
4516 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004517 return true;
4518 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004519
Douglas Gregor5499af42011-01-05 23:12:31 +00004520 if (ShouldExpand) {
4521 // Expand the function parameter pack into multiple, separate
4522 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004523 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004524 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004525 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004526 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004527 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004528 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004529 OrigNumExpansions,
4530 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004531 if (!NewParm)
4532 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004533
Douglas Gregordd472162011-01-07 00:20:55 +00004534 OutParamTypes.push_back(NewParm->getType());
4535 if (PVars)
4536 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004537 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004538
4539 // If we're supposed to retain a pack expansion, do so by temporarily
4540 // forgetting the partially-substituted parameter pack.
4541 if (RetainExpansion) {
4542 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004543 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004544 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004545 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004546 OrigNumExpansions,
4547 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004548 if (!NewParm)
4549 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004550
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004551 OutParamTypes.push_back(NewParm->getType());
4552 if (PVars)
4553 PVars->push_back(NewParm);
4554 }
4555
John McCall8fb0d9d2011-05-01 22:35:37 +00004556 // The next parameter should have the same adjustment as the
4557 // last thing we pushed, but we post-incremented indexAdjustment
4558 // on every push. Also, if we push nothing, the adjustment should
4559 // go down by one.
4560 indexAdjustment--;
4561
Douglas Gregor5499af42011-01-05 23:12:31 +00004562 // We're done with the pack expansion.
4563 continue;
4564 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004565
4566 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004567 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004568 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4569 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004570 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004571 NumExpansions,
4572 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004573 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004574 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004575 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004576 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004577
John McCall58f10c32010-03-11 09:03:00 +00004578 if (!NewParm)
4579 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004580
Douglas Gregordd472162011-01-07 00:20:55 +00004581 OutParamTypes.push_back(NewParm->getType());
4582 if (PVars)
4583 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004584 continue;
4585 }
John McCall58f10c32010-03-11 09:03:00 +00004586
4587 // Deal with the possibility that we don't have a parameter
4588 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004589 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004590 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004591 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004592 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004593 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004594 = dyn_cast<PackExpansionType>(OldType)) {
4595 // We have a function parameter pack that may need to be expanded.
4596 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004597 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004598 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004599
Douglas Gregor5499af42011-01-05 23:12:31 +00004600 // Determine whether we should expand the parameter packs.
4601 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004602 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004603 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004604 Unexpanded,
4605 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004606 RetainExpansion,
4607 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004608 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004609 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004610
Douglas Gregor5499af42011-01-05 23:12:31 +00004611 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004612 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004613 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004614 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004615 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4616 QualType NewType = getDerived().TransformType(Pattern);
4617 if (NewType.isNull())
4618 return true;
John McCall58f10c32010-03-11 09:03:00 +00004619
Douglas Gregordd472162011-01-07 00:20:55 +00004620 OutParamTypes.push_back(NewType);
4621 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004622 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004623 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004624
Douglas Gregor5499af42011-01-05 23:12:31 +00004625 // We're done with the pack expansion.
4626 continue;
4627 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004628
Douglas Gregor48d24112011-01-10 20:53:55 +00004629 // If we're supposed to retain a pack expansion, do so by temporarily
4630 // forgetting the partially-substituted parameter pack.
4631 if (RetainExpansion) {
4632 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4633 QualType NewType = getDerived().TransformType(Pattern);
4634 if (NewType.isNull())
4635 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004636
Douglas Gregor48d24112011-01-10 20:53:55 +00004637 OutParamTypes.push_back(NewType);
4638 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004639 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004640 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004641
Chad Rosier1dcde962012-08-08 18:46:20 +00004642 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004643 // expansion.
4644 OldType = Expansion->getPattern();
4645 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004646 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4647 NewType = getDerived().TransformType(OldType);
4648 } else {
4649 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004650 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004651
Douglas Gregor5499af42011-01-05 23:12:31 +00004652 if (NewType.isNull())
4653 return true;
4654
4655 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004656 NewType = getSema().Context.getPackExpansionType(NewType,
4657 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004658
Douglas Gregordd472162011-01-07 00:20:55 +00004659 OutParamTypes.push_back(NewType);
4660 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004661 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004662 }
4663
John McCall8fb0d9d2011-05-01 22:35:37 +00004664#ifndef NDEBUG
4665 if (PVars) {
4666 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4667 if (ParmVarDecl *parm = (*PVars)[i])
4668 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004669 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004670#endif
4671
4672 return false;
4673}
John McCall58f10c32010-03-11 09:03:00 +00004674
4675template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004676QualType
John McCall550e0c22009-10-21 00:40:46 +00004677TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004678 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004679 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004680 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004681 return getDerived().TransformFunctionProtoType(
4682 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004683 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4684 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4685 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004686 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004687}
4688
Richard Smith2e321552014-11-12 02:00:47 +00004689template<typename Derived> template<typename Fn>
4690QualType TreeTransform<Derived>::TransformFunctionProtoType(
4691 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4692 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004693 // Transform the parameters and return type.
4694 //
Richard Smithf623c962012-04-17 00:58:00 +00004695 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004696 // When the function has a trailing return type, we instantiate the
4697 // parameters before the return type, since the return type can then refer
4698 // to the parameters themselves (via decltype, sizeof, etc.).
4699 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004700 SmallVector<QualType, 4> ParamTypes;
4701 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004702 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004703
Douglas Gregor7fb25412010-10-01 18:44:50 +00004704 QualType ResultType;
4705
Richard Smith1226c602012-08-14 22:51:13 +00004706 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004707 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004708 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004709 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004710 return QualType();
4711
Douglas Gregor3024f072012-04-16 07:05:22 +00004712 {
4713 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004714 // If a declaration declares a member function or member function
4715 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004716 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004717 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004718 // declarator.
4719 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004720
Alp Toker42a16a62014-01-25 23:51:36 +00004721 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004722 if (ResultType.isNull())
4723 return QualType();
4724 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004725 }
4726 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004727 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004728 if (ResultType.isNull())
4729 return QualType();
4730
Alp Toker9cacbab2014-01-20 20:26:09 +00004731 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004732 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004733 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004734 return QualType();
4735 }
4736
Richard Smith2e321552014-11-12 02:00:47 +00004737 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4738
4739 bool EPIChanged = false;
4740 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4741 return QualType();
4742
4743 // FIXME: Need to transform ConsumedParameters for variadic template
4744 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004745
John McCall550e0c22009-10-21 00:40:46 +00004746 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004747 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00004748 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00004749 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004750 if (Result.isNull())
4751 return QualType();
4752 }
Mike Stump11289f42009-09-09 15:08:12 +00004753
John McCall550e0c22009-10-21 00:40:46 +00004754 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004755 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004756 NewTL.setLParenLoc(TL.getLParenLoc());
4757 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004758 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004759 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4760 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004761
4762 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004763}
Mike Stump11289f42009-09-09 15:08:12 +00004764
Douglas Gregord6ff3322009-08-04 16:50:30 +00004765template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004766bool TreeTransform<Derived>::TransformExceptionSpec(
4767 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4768 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4769 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4770
4771 // Instantiate a dynamic noexcept expression, if any.
4772 if (ESI.Type == EST_ComputedNoexcept) {
4773 EnterExpressionEvaluationContext Unevaluated(getSema(),
4774 Sema::ConstantEvaluated);
4775 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4776 if (NoexceptExpr.isInvalid())
4777 return true;
4778
4779 NoexceptExpr = getSema().CheckBooleanCondition(
4780 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4781 if (NoexceptExpr.isInvalid())
4782 return true;
4783
4784 if (!NoexceptExpr.get()->isValueDependent()) {
4785 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4786 NoexceptExpr.get(), nullptr,
4787 diag::err_noexcept_needs_constant_expression,
4788 /*AllowFold*/false);
4789 if (NoexceptExpr.isInvalid())
4790 return true;
4791 }
4792
4793 if (ESI.NoexceptExpr != NoexceptExpr.get())
4794 Changed = true;
4795 ESI.NoexceptExpr = NoexceptExpr.get();
4796 }
4797
4798 if (ESI.Type != EST_Dynamic)
4799 return false;
4800
4801 // Instantiate a dynamic exception specification's type.
4802 for (QualType T : ESI.Exceptions) {
4803 if (const PackExpansionType *PackExpansion =
4804 T->getAs<PackExpansionType>()) {
4805 Changed = true;
4806
4807 // We have a pack expansion. Instantiate it.
4808 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4809 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4810 Unexpanded);
4811 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4812
4813 // Determine whether the set of unexpanded parameter packs can and
4814 // should
4815 // be expanded.
4816 bool Expand = false;
4817 bool RetainExpansion = false;
4818 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4819 // FIXME: Track the location of the ellipsis (and track source location
4820 // information for the types in the exception specification in general).
4821 if (getDerived().TryExpandParameterPacks(
4822 Loc, SourceRange(), Unexpanded, Expand,
4823 RetainExpansion, NumExpansions))
4824 return true;
4825
4826 if (!Expand) {
4827 // We can't expand this pack expansion into separate arguments yet;
4828 // just substitute into the pattern and create a new pack expansion
4829 // type.
4830 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4831 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4832 if (U.isNull())
4833 return true;
4834
4835 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4836 Exceptions.push_back(U);
4837 continue;
4838 }
4839
4840 // Substitute into the pack expansion pattern for each slice of the
4841 // pack.
4842 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4843 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4844
4845 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4846 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4847 return true;
4848
4849 Exceptions.push_back(U);
4850 }
4851 } else {
4852 QualType U = getDerived().TransformType(T);
4853 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4854 return true;
4855 if (T != U)
4856 Changed = true;
4857
4858 Exceptions.push_back(U);
4859 }
4860 }
4861
4862 ESI.Exceptions = Exceptions;
4863 return false;
4864}
4865
4866template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004867QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004868 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004869 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004870 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004871 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004872 if (ResultType.isNull())
4873 return QualType();
4874
4875 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004876 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004877 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4878
4879 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004880 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004881 NewTL.setLParenLoc(TL.getLParenLoc());
4882 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004883 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004884
4885 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004886}
Mike Stump11289f42009-09-09 15:08:12 +00004887
John McCallb96ec562009-12-04 22:46:56 +00004888template<typename Derived> QualType
4889TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004890 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004891 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004892 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004893 if (!D)
4894 return QualType();
4895
4896 QualType Result = TL.getType();
4897 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4898 Result = getDerived().RebuildUnresolvedUsingType(D);
4899 if (Result.isNull())
4900 return QualType();
4901 }
4902
4903 // We might get an arbitrary type spec type back. We should at
4904 // least always get a type spec type, though.
4905 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4906 NewTL.setNameLoc(TL.getNameLoc());
4907
4908 return Result;
4909}
4910
Douglas Gregord6ff3322009-08-04 16:50:30 +00004911template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004912QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004913 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004914 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004915 TypedefNameDecl *Typedef
4916 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4917 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004918 if (!Typedef)
4919 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004920
John McCall550e0c22009-10-21 00:40:46 +00004921 QualType Result = TL.getType();
4922 if (getDerived().AlwaysRebuild() ||
4923 Typedef != T->getDecl()) {
4924 Result = getDerived().RebuildTypedefType(Typedef);
4925 if (Result.isNull())
4926 return QualType();
4927 }
Mike Stump11289f42009-09-09 15:08:12 +00004928
John McCall550e0c22009-10-21 00:40:46 +00004929 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4930 NewTL.setNameLoc(TL.getNameLoc());
4931
4932 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004933}
Mike Stump11289f42009-09-09 15:08:12 +00004934
Douglas Gregord6ff3322009-08-04 16:50:30 +00004935template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004936QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004937 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004938 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004939 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4940 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004941
John McCalldadc5752010-08-24 06:29:42 +00004942 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004943 if (E.isInvalid())
4944 return QualType();
4945
Eli Friedmane4f22df2012-02-29 04:03:55 +00004946 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4947 if (E.isInvalid())
4948 return QualType();
4949
John McCall550e0c22009-10-21 00:40:46 +00004950 QualType Result = TL.getType();
4951 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004952 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004953 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004954 if (Result.isNull())
4955 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004956 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004957 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004958
John McCall550e0c22009-10-21 00:40:46 +00004959 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004960 NewTL.setTypeofLoc(TL.getTypeofLoc());
4961 NewTL.setLParenLoc(TL.getLParenLoc());
4962 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004963
4964 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004965}
Mike Stump11289f42009-09-09 15:08:12 +00004966
4967template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004968QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004969 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004970 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4971 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4972 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004973 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004974
John McCall550e0c22009-10-21 00:40:46 +00004975 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004976 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4977 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004978 if (Result.isNull())
4979 return QualType();
4980 }
Mike Stump11289f42009-09-09 15:08:12 +00004981
John McCall550e0c22009-10-21 00:40:46 +00004982 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004983 NewTL.setTypeofLoc(TL.getTypeofLoc());
4984 NewTL.setLParenLoc(TL.getLParenLoc());
4985 NewTL.setRParenLoc(TL.getRParenLoc());
4986 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004987
4988 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004989}
Mike Stump11289f42009-09-09 15:08:12 +00004990
4991template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004992QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004993 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004994 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004995
Douglas Gregore922c772009-08-04 22:27:00 +00004996 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00004997 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4998 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00004999
John McCalldadc5752010-08-24 06:29:42 +00005000 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005001 if (E.isInvalid())
5002 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005003
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005004 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005005 if (E.isInvalid())
5006 return QualType();
5007
John McCall550e0c22009-10-21 00:40:46 +00005008 QualType Result = TL.getType();
5009 if (getDerived().AlwaysRebuild() ||
5010 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005011 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005012 if (Result.isNull())
5013 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005014 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005015 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005016
John McCall550e0c22009-10-21 00:40:46 +00005017 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5018 NewTL.setNameLoc(TL.getNameLoc());
5019
5020 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005021}
5022
5023template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005024QualType TreeTransform<Derived>::TransformUnaryTransformType(
5025 TypeLocBuilder &TLB,
5026 UnaryTransformTypeLoc TL) {
5027 QualType Result = TL.getType();
5028 if (Result->isDependentType()) {
5029 const UnaryTransformType *T = TL.getTypePtr();
5030 QualType NewBase =
5031 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5032 Result = getDerived().RebuildUnaryTransformType(NewBase,
5033 T->getUTTKind(),
5034 TL.getKWLoc());
5035 if (Result.isNull())
5036 return QualType();
5037 }
5038
5039 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5040 NewTL.setKWLoc(TL.getKWLoc());
5041 NewTL.setParensRange(TL.getParensRange());
5042 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5043 return Result;
5044}
5045
5046template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005047QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5048 AutoTypeLoc TL) {
5049 const AutoType *T = TL.getTypePtr();
5050 QualType OldDeduced = T->getDeducedType();
5051 QualType NewDeduced;
5052 if (!OldDeduced.isNull()) {
5053 NewDeduced = getDerived().TransformType(OldDeduced);
5054 if (NewDeduced.isNull())
5055 return QualType();
5056 }
5057
5058 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005059 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5060 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00005061 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00005062 if (Result.isNull())
5063 return QualType();
5064 }
5065
5066 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5067 NewTL.setNameLoc(TL.getNameLoc());
5068
5069 return Result;
5070}
5071
5072template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005073QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005074 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005075 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005076 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005077 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5078 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005079 if (!Record)
5080 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005081
John McCall550e0c22009-10-21 00:40:46 +00005082 QualType Result = TL.getType();
5083 if (getDerived().AlwaysRebuild() ||
5084 Record != T->getDecl()) {
5085 Result = getDerived().RebuildRecordType(Record);
5086 if (Result.isNull())
5087 return QualType();
5088 }
Mike Stump11289f42009-09-09 15:08:12 +00005089
John McCall550e0c22009-10-21 00:40:46 +00005090 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5091 NewTL.setNameLoc(TL.getNameLoc());
5092
5093 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005094}
Mike Stump11289f42009-09-09 15:08:12 +00005095
5096template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005097QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005098 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005099 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005100 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005101 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5102 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005103 if (!Enum)
5104 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005105
John McCall550e0c22009-10-21 00:40:46 +00005106 QualType Result = TL.getType();
5107 if (getDerived().AlwaysRebuild() ||
5108 Enum != T->getDecl()) {
5109 Result = getDerived().RebuildEnumType(Enum);
5110 if (Result.isNull())
5111 return QualType();
5112 }
Mike Stump11289f42009-09-09 15:08:12 +00005113
John McCall550e0c22009-10-21 00:40:46 +00005114 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5115 NewTL.setNameLoc(TL.getNameLoc());
5116
5117 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005118}
John McCallfcc33b02009-09-05 00:15:47 +00005119
John McCalle78aac42010-03-10 03:28:59 +00005120template<typename Derived>
5121QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5122 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005123 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005124 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5125 TL.getTypePtr()->getDecl());
5126 if (!D) return QualType();
5127
5128 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5129 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5130 return T;
5131}
5132
Douglas Gregord6ff3322009-08-04 16:50:30 +00005133template<typename Derived>
5134QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005135 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005136 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005137 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005138}
5139
Mike Stump11289f42009-09-09 15:08:12 +00005140template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005141QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005142 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005143 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005144 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005145
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005146 // Substitute into the replacement type, which itself might involve something
5147 // that needs to be transformed. This only tends to occur with default
5148 // template arguments of template template parameters.
5149 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5150 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5151 if (Replacement.isNull())
5152 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005153
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005154 // Always canonicalize the replacement type.
5155 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5156 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005157 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005158 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005159
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005160 // Propagate type-source information.
5161 SubstTemplateTypeParmTypeLoc NewTL
5162 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5163 NewTL.setNameLoc(TL.getNameLoc());
5164 return Result;
5165
John McCallcebee162009-10-18 09:09:24 +00005166}
5167
5168template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005169QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5170 TypeLocBuilder &TLB,
5171 SubstTemplateTypeParmPackTypeLoc TL) {
5172 return TransformTypeSpecType(TLB, TL);
5173}
5174
5175template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005176QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005177 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005178 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005179 const TemplateSpecializationType *T = TL.getTypePtr();
5180
Douglas Gregordf846d12011-03-02 18:46:51 +00005181 // The nested-name-specifier never matters in a TemplateSpecializationType,
5182 // because we can't have a dependent nested-name-specifier anyway.
5183 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005184 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005185 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5186 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005187 if (Template.isNull())
5188 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005189
John McCall31f82722010-11-12 08:19:04 +00005190 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5191}
5192
Eli Friedman0dfb8892011-10-06 23:00:33 +00005193template<typename Derived>
5194QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5195 AtomicTypeLoc TL) {
5196 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5197 if (ValueType.isNull())
5198 return QualType();
5199
5200 QualType Result = TL.getType();
5201 if (getDerived().AlwaysRebuild() ||
5202 ValueType != TL.getValueLoc().getType()) {
5203 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5204 if (Result.isNull())
5205 return QualType();
5206 }
5207
5208 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5209 NewTL.setKWLoc(TL.getKWLoc());
5210 NewTL.setLParenLoc(TL.getLParenLoc());
5211 NewTL.setRParenLoc(TL.getRParenLoc());
5212
5213 return Result;
5214}
5215
Chad Rosier1dcde962012-08-08 18:46:20 +00005216 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005217 /// container that provides a \c getArgLoc() member function.
5218 ///
5219 /// This iterator is intended to be used with the iterator form of
5220 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5221 template<typename ArgLocContainer>
5222 class TemplateArgumentLocContainerIterator {
5223 ArgLocContainer *Container;
5224 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005225
Douglas Gregorfe921a72010-12-20 23:36:19 +00005226 public:
5227 typedef TemplateArgumentLoc value_type;
5228 typedef TemplateArgumentLoc reference;
5229 typedef int difference_type;
5230 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005231
Douglas Gregorfe921a72010-12-20 23:36:19 +00005232 class pointer {
5233 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005234
Douglas Gregorfe921a72010-12-20 23:36:19 +00005235 public:
5236 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005237
Douglas Gregorfe921a72010-12-20 23:36:19 +00005238 const TemplateArgumentLoc *operator->() const {
5239 return &Arg;
5240 }
5241 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005242
5243
Douglas Gregorfe921a72010-12-20 23:36:19 +00005244 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005245
Douglas Gregorfe921a72010-12-20 23:36:19 +00005246 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5247 unsigned Index)
5248 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005249
Douglas Gregorfe921a72010-12-20 23:36:19 +00005250 TemplateArgumentLocContainerIterator &operator++() {
5251 ++Index;
5252 return *this;
5253 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005254
Douglas Gregorfe921a72010-12-20 23:36:19 +00005255 TemplateArgumentLocContainerIterator operator++(int) {
5256 TemplateArgumentLocContainerIterator Old(*this);
5257 ++(*this);
5258 return Old;
5259 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005260
Douglas Gregorfe921a72010-12-20 23:36:19 +00005261 TemplateArgumentLoc operator*() const {
5262 return Container->getArgLoc(Index);
5263 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005264
Douglas Gregorfe921a72010-12-20 23:36:19 +00005265 pointer operator->() const {
5266 return pointer(Container->getArgLoc(Index));
5267 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005268
Douglas Gregorfe921a72010-12-20 23:36:19 +00005269 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005270 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005271 return X.Container == Y.Container && X.Index == Y.Index;
5272 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005273
Douglas Gregorfe921a72010-12-20 23:36:19 +00005274 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005275 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005276 return !(X == Y);
5277 }
5278 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005279
5280
John McCall31f82722010-11-12 08:19:04 +00005281template <typename Derived>
5282QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5283 TypeLocBuilder &TLB,
5284 TemplateSpecializationTypeLoc TL,
5285 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005286 TemplateArgumentListInfo NewTemplateArgs;
5287 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5288 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005289 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5290 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005291 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005292 ArgIterator(TL, TL.getNumArgs()),
5293 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005294 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005295
John McCall0ad16662009-10-29 08:12:44 +00005296 // FIXME: maybe don't rebuild if all the template arguments are the same.
5297
5298 QualType Result =
5299 getDerived().RebuildTemplateSpecializationType(Template,
5300 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005301 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005302
5303 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005304 // Specializations of template template parameters are represented as
5305 // TemplateSpecializationTypes, and substitution of type alias templates
5306 // within a dependent context can transform them into
5307 // DependentTemplateSpecializationTypes.
5308 if (isa<DependentTemplateSpecializationType>(Result)) {
5309 DependentTemplateSpecializationTypeLoc NewTL
5310 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005311 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005312 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005313 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005314 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005315 NewTL.setLAngleLoc(TL.getLAngleLoc());
5316 NewTL.setRAngleLoc(TL.getRAngleLoc());
5317 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5318 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5319 return Result;
5320 }
5321
John McCall0ad16662009-10-29 08:12:44 +00005322 TemplateSpecializationTypeLoc NewTL
5323 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005324 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005325 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5326 NewTL.setLAngleLoc(TL.getLAngleLoc());
5327 NewTL.setRAngleLoc(TL.getRAngleLoc());
5328 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5329 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005330 }
Mike Stump11289f42009-09-09 15:08:12 +00005331
John McCall0ad16662009-10-29 08:12:44 +00005332 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005333}
Mike Stump11289f42009-09-09 15:08:12 +00005334
Douglas Gregor5a064722011-02-28 17:23:35 +00005335template <typename Derived>
5336QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5337 TypeLocBuilder &TLB,
5338 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005339 TemplateName Template,
5340 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005341 TemplateArgumentListInfo NewTemplateArgs;
5342 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5343 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5344 typedef TemplateArgumentLocContainerIterator<
5345 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005346 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005347 ArgIterator(TL, TL.getNumArgs()),
5348 NewTemplateArgs))
5349 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005350
Douglas Gregor5a064722011-02-28 17:23:35 +00005351 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005352
Douglas Gregor5a064722011-02-28 17:23:35 +00005353 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5354 QualType Result
5355 = getSema().Context.getDependentTemplateSpecializationType(
5356 TL.getTypePtr()->getKeyword(),
5357 DTN->getQualifier(),
5358 DTN->getIdentifier(),
5359 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005360
Douglas Gregor5a064722011-02-28 17:23:35 +00005361 DependentTemplateSpecializationTypeLoc NewTL
5362 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005363 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005364 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005365 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005366 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005367 NewTL.setLAngleLoc(TL.getLAngleLoc());
5368 NewTL.setRAngleLoc(TL.getRAngleLoc());
5369 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5370 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5371 return Result;
5372 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005373
5374 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005375 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005376 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005377 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005378
Douglas Gregor5a064722011-02-28 17:23:35 +00005379 if (!Result.isNull()) {
5380 /// FIXME: Wrap this in an elaborated-type-specifier?
5381 TemplateSpecializationTypeLoc NewTL
5382 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005383 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005384 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005385 NewTL.setLAngleLoc(TL.getLAngleLoc());
5386 NewTL.setRAngleLoc(TL.getRAngleLoc());
5387 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5388 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5389 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005390
Douglas Gregor5a064722011-02-28 17:23:35 +00005391 return Result;
5392}
5393
Mike Stump11289f42009-09-09 15:08:12 +00005394template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005395QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005396TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005397 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005398 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005399
Douglas Gregor844cb502011-03-01 18:12:44 +00005400 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005401 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005402 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005403 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005404 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5405 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005406 return QualType();
5407 }
Mike Stump11289f42009-09-09 15:08:12 +00005408
John McCall31f82722010-11-12 08:19:04 +00005409 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5410 if (NamedT.isNull())
5411 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005412
Richard Smith3f1b5d02011-05-05 21:57:07 +00005413 // C++0x [dcl.type.elab]p2:
5414 // If the identifier resolves to a typedef-name or the simple-template-id
5415 // resolves to an alias template specialization, the
5416 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005417 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5418 if (const TemplateSpecializationType *TST =
5419 NamedT->getAs<TemplateSpecializationType>()) {
5420 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005421 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5422 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005423 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5424 diag::err_tag_reference_non_tag) << 4;
5425 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5426 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005427 }
5428 }
5429
John McCall550e0c22009-10-21 00:40:46 +00005430 QualType Result = TL.getType();
5431 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005432 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005433 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005434 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005435 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005436 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005437 if (Result.isNull())
5438 return QualType();
5439 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005440
Abramo Bagnara6150c882010-05-11 21:36:43 +00005441 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005442 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005443 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005444 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005445}
Mike Stump11289f42009-09-09 15:08:12 +00005446
5447template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005448QualType TreeTransform<Derived>::TransformAttributedType(
5449 TypeLocBuilder &TLB,
5450 AttributedTypeLoc TL) {
5451 const AttributedType *oldType = TL.getTypePtr();
5452 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5453 if (modifiedType.isNull())
5454 return QualType();
5455
5456 QualType result = TL.getType();
5457
5458 // FIXME: dependent operand expressions?
5459 if (getDerived().AlwaysRebuild() ||
5460 modifiedType != oldType->getModifiedType()) {
5461 // TODO: this is really lame; we should really be rebuilding the
5462 // equivalent type from first principles.
5463 QualType equivalentType
5464 = getDerived().TransformType(oldType->getEquivalentType());
5465 if (equivalentType.isNull())
5466 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005467
5468 // Check whether we can add nullability; it is only represented as
5469 // type sugar, and therefore cannot be diagnosed in any other way.
5470 if (auto nullability = oldType->getImmediateNullability()) {
5471 if (!modifiedType->canHaveNullability()) {
5472 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005473 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005474 return QualType();
5475 }
5476 }
5477
John McCall81904512011-01-06 01:58:22 +00005478 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5479 modifiedType,
5480 equivalentType);
5481 }
5482
5483 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5484 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5485 if (TL.hasAttrOperand())
5486 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5487 if (TL.hasAttrExprOperand())
5488 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5489 else if (TL.hasAttrEnumOperand())
5490 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5491
5492 return result;
5493}
5494
5495template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005496QualType
5497TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5498 ParenTypeLoc TL) {
5499 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5500 if (Inner.isNull())
5501 return QualType();
5502
5503 QualType Result = TL.getType();
5504 if (getDerived().AlwaysRebuild() ||
5505 Inner != TL.getInnerLoc().getType()) {
5506 Result = getDerived().RebuildParenType(Inner);
5507 if (Result.isNull())
5508 return QualType();
5509 }
5510
5511 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5512 NewTL.setLParenLoc(TL.getLParenLoc());
5513 NewTL.setRParenLoc(TL.getRParenLoc());
5514 return Result;
5515}
5516
5517template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005518QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005519 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005520 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005521
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005522 NestedNameSpecifierLoc QualifierLoc
5523 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5524 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005525 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005526
John McCallc392f372010-06-11 00:33:02 +00005527 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005528 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005529 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005530 QualifierLoc,
5531 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005532 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005533 if (Result.isNull())
5534 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005535
Abramo Bagnarad7548482010-05-19 21:37:53 +00005536 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5537 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005538 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5539
Abramo Bagnarad7548482010-05-19 21:37:53 +00005540 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005541 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005542 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005543 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005544 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005545 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005546 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005547 NewTL.setNameLoc(TL.getNameLoc());
5548 }
John McCall550e0c22009-10-21 00:40:46 +00005549 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005550}
Mike Stump11289f42009-09-09 15:08:12 +00005551
Douglas Gregord6ff3322009-08-04 16:50:30 +00005552template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005553QualType TreeTransform<Derived>::
5554 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005555 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005556 NestedNameSpecifierLoc QualifierLoc;
5557 if (TL.getQualifierLoc()) {
5558 QualifierLoc
5559 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5560 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005561 return QualType();
5562 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005563
John McCall31f82722010-11-12 08:19:04 +00005564 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005565 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005566}
5567
5568template<typename Derived>
5569QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005570TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5571 DependentTemplateSpecializationTypeLoc TL,
5572 NestedNameSpecifierLoc QualifierLoc) {
5573 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005574
Douglas Gregora7a795b2011-03-01 20:11:18 +00005575 TemplateArgumentListInfo NewTemplateArgs;
5576 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5577 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005578
Douglas Gregora7a795b2011-03-01 20:11:18 +00005579 typedef TemplateArgumentLocContainerIterator<
5580 DependentTemplateSpecializationTypeLoc> ArgIterator;
5581 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5582 ArgIterator(TL, TL.getNumArgs()),
5583 NewTemplateArgs))
5584 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005585
Douglas Gregora7a795b2011-03-01 20:11:18 +00005586 QualType Result
5587 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5588 QualifierLoc,
5589 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005590 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005591 NewTemplateArgs);
5592 if (Result.isNull())
5593 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005594
Douglas Gregora7a795b2011-03-01 20:11:18 +00005595 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5596 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005597
Douglas Gregora7a795b2011-03-01 20:11:18 +00005598 // Copy information relevant to the template specialization.
5599 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005600 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005601 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005602 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005603 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5604 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005605 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005606 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005607
Douglas Gregora7a795b2011-03-01 20:11:18 +00005608 // Copy information relevant to the elaborated type.
5609 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005610 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005611 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005612 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5613 DependentTemplateSpecializationTypeLoc SpecTL
5614 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005615 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005616 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005617 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005618 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005619 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5620 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005621 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005622 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005623 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005624 TemplateSpecializationTypeLoc SpecTL
5625 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005626 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005627 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005628 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5629 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005630 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005631 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005632 }
5633 return Result;
5634}
5635
5636template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005637QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5638 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005639 QualType Pattern
5640 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005641 if (Pattern.isNull())
5642 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005643
5644 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005645 if (getDerived().AlwaysRebuild() ||
5646 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005647 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005648 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005649 TL.getEllipsisLoc(),
5650 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005651 if (Result.isNull())
5652 return QualType();
5653 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005654
Douglas Gregor822d0302011-01-12 17:07:58 +00005655 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5656 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5657 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005658}
5659
5660template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005661QualType
5662TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005663 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005664 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005665 TLB.pushFullCopy(TL);
5666 return TL.getType();
5667}
5668
5669template<typename Derived>
5670QualType
5671TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005672 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005673 // Transform base type.
5674 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5675 if (BaseType.isNull())
5676 return QualType();
5677
5678 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5679
5680 // Transform type arguments.
5681 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5682 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5683 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5684 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5685 QualType TypeArg = TypeArgInfo->getType();
5686 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5687 AnyChanged = true;
5688
5689 // We have a pack expansion. Instantiate it.
5690 const auto *PackExpansion = PackExpansionLoc.getType()
5691 ->castAs<PackExpansionType>();
5692 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5693 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5694 Unexpanded);
5695 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5696
5697 // Determine whether the set of unexpanded parameter packs can
5698 // and should be expanded.
5699 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5700 bool Expand = false;
5701 bool RetainExpansion = false;
5702 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5703 if (getDerived().TryExpandParameterPacks(
5704 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5705 Unexpanded, Expand, RetainExpansion, NumExpansions))
5706 return QualType();
5707
5708 if (!Expand) {
5709 // We can't expand this pack expansion into separate arguments yet;
5710 // just substitute into the pattern and create a new pack expansion
5711 // type.
5712 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5713
5714 TypeLocBuilder TypeArgBuilder;
5715 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5716 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5717 PatternLoc);
5718 if (NewPatternType.isNull())
5719 return QualType();
5720
5721 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5722 NewPatternType, NumExpansions);
5723 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5724 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5725 NewTypeArgInfos.push_back(
5726 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5727 continue;
5728 }
5729
5730 // Substitute into the pack expansion pattern for each slice of the
5731 // pack.
5732 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5733 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5734
5735 TypeLocBuilder TypeArgBuilder;
5736 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5737
5738 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5739 PatternLoc);
5740 if (NewTypeArg.isNull())
5741 return QualType();
5742
5743 NewTypeArgInfos.push_back(
5744 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5745 }
5746
5747 continue;
5748 }
5749
5750 TypeLocBuilder TypeArgBuilder;
5751 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
5752 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
5753 if (NewTypeArg.isNull())
5754 return QualType();
5755
5756 // If nothing changed, just keep the old TypeSourceInfo.
5757 if (NewTypeArg == TypeArg) {
5758 NewTypeArgInfos.push_back(TypeArgInfo);
5759 continue;
5760 }
5761
5762 NewTypeArgInfos.push_back(
5763 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5764 AnyChanged = true;
5765 }
5766
5767 QualType Result = TL.getType();
5768 if (getDerived().AlwaysRebuild() || AnyChanged) {
5769 // Rebuild the type.
5770 Result = getDerived().RebuildObjCObjectType(
5771 BaseType,
5772 TL.getLocStart(),
5773 TL.getTypeArgsLAngleLoc(),
5774 NewTypeArgInfos,
5775 TL.getTypeArgsRAngleLoc(),
5776 TL.getProtocolLAngleLoc(),
5777 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5778 TL.getNumProtocols()),
5779 TL.getProtocolLocs(),
5780 TL.getProtocolRAngleLoc());
5781
5782 if (Result.isNull())
5783 return QualType();
5784 }
5785
5786 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
5787 assert(TL.hasBaseTypeAsWritten() && "Can't be dependent");
5788 NewT.setHasBaseTypeAsWritten(true);
5789 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
5790 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
5791 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
5792 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
5793 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5794 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5795 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
5796 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5797 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005798}
Mike Stump11289f42009-09-09 15:08:12 +00005799
5800template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005801QualType
5802TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005803 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005804 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5805 if (PointeeType.isNull())
5806 return QualType();
5807
5808 QualType Result = TL.getType();
5809 if (getDerived().AlwaysRebuild() ||
5810 PointeeType != TL.getPointeeLoc().getType()) {
5811 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
5812 TL.getStarLoc());
5813 if (Result.isNull())
5814 return QualType();
5815 }
5816
5817 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5818 NewT.setStarLoc(TL.getStarLoc());
5819 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005820}
5821
Douglas Gregord6ff3322009-08-04 16:50:30 +00005822//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005823// Statement transformation
5824//===----------------------------------------------------------------------===//
5825template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005826StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005827TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005828 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005829}
5830
5831template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005832StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005833TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5834 return getDerived().TransformCompoundStmt(S, false);
5835}
5836
5837template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005838StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005839TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005840 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005841 Sema::CompoundScopeRAII CompoundScope(getSema());
5842
John McCall1ababa62010-08-27 19:56:05 +00005843 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005844 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005845 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005846 for (auto *B : S->body()) {
5847 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005848 if (Result.isInvalid()) {
5849 // Immediately fail if this was a DeclStmt, since it's very
5850 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005851 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005852 return StmtError();
5853
5854 // Otherwise, just keep processing substatements and fail later.
5855 SubStmtInvalid = true;
5856 continue;
5857 }
Mike Stump11289f42009-09-09 15:08:12 +00005858
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005859 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005860 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005861 }
Mike Stump11289f42009-09-09 15:08:12 +00005862
John McCall1ababa62010-08-27 19:56:05 +00005863 if (SubStmtInvalid)
5864 return StmtError();
5865
Douglas Gregorebe10102009-08-20 07:17:43 +00005866 if (!getDerived().AlwaysRebuild() &&
5867 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005868 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005869
5870 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005871 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005872 S->getRBracLoc(),
5873 IsStmtExpr);
5874}
Mike Stump11289f42009-09-09 15:08:12 +00005875
Douglas Gregorebe10102009-08-20 07:17:43 +00005876template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005877StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005878TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005879 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005880 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005881 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5882 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005883
Eli Friedman06577382009-11-19 03:14:00 +00005884 // Transform the left-hand case value.
5885 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005886 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005887 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005888 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005889
Eli Friedman06577382009-11-19 03:14:00 +00005890 // Transform the right-hand case value (for the GNU case-range extension).
5891 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005892 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005893 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005894 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005895 }
Mike Stump11289f42009-09-09 15:08:12 +00005896
Douglas Gregorebe10102009-08-20 07:17:43 +00005897 // Build the case statement.
5898 // Case statements are always rebuilt so that they will attached to their
5899 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005900 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005901 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005902 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005903 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005904 S->getColonLoc());
5905 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005906 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005907
Douglas Gregorebe10102009-08-20 07:17:43 +00005908 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005909 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005910 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005911 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005912
Douglas Gregorebe10102009-08-20 07:17:43 +00005913 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005914 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005915}
5916
5917template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005918StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005919TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005920 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005921 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005922 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005923 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005924
Douglas Gregorebe10102009-08-20 07:17:43 +00005925 // Default statements are always rebuilt
5926 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005927 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005928}
Mike Stump11289f42009-09-09 15:08:12 +00005929
Douglas Gregorebe10102009-08-20 07:17:43 +00005930template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005931StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005932TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005933 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005934 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005935 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005936
Chris Lattnercab02a62011-02-17 20:34:02 +00005937 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5938 S->getDecl());
5939 if (!LD)
5940 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005941
5942
Douglas Gregorebe10102009-08-20 07:17:43 +00005943 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005944 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005945 cast<LabelDecl>(LD), SourceLocation(),
5946 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005947}
Mike Stump11289f42009-09-09 15:08:12 +00005948
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005949template <typename Derived>
5950const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
5951 if (!R)
5952 return R;
5953
5954 switch (R->getKind()) {
5955// Transform attributes with a pragma spelling by calling TransformXXXAttr.
5956#define ATTR(X)
5957#define PRAGMA_SPELLING_ATTR(X) \
5958 case attr::X: \
5959 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
5960#include "clang/Basic/AttrList.inc"
5961 default:
5962 return R;
5963 }
5964}
5965
5966template <typename Derived>
5967StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5968 bool AttrsChanged = false;
5969 SmallVector<const Attr *, 1> Attrs;
5970
5971 // Visit attributes and keep track if any are transformed.
5972 for (const auto *I : S->getAttrs()) {
5973 const Attr *R = getDerived().TransformAttr(I);
5974 AttrsChanged |= (I != R);
5975 Attrs.push_back(R);
5976 }
5977
Richard Smithc202b282012-04-14 00:33:13 +00005978 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5979 if (SubStmt.isInvalid())
5980 return StmtError();
5981
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005982 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00005983 return S;
5984
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005985 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00005986 SubStmt.get());
5987}
5988
5989template<typename Derived>
5990StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005991TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005992 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00005993 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00005994 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00005995 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005996 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00005997 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00005998 getDerived().TransformDefinition(
5999 S->getConditionVariable()->getLocation(),
6000 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00006001 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006002 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006003 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00006004 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006005
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006006 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006007 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006008
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006009 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00006010 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006011 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006012 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006013 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006014 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006015
John McCallb268a282010-08-23 23:25:46 +00006016 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006017 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006018 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006019
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006020 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006021 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006022 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006023
Douglas Gregorebe10102009-08-20 07:17:43 +00006024 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00006025 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00006026 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006027 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006028
Douglas Gregorebe10102009-08-20 07:17:43 +00006029 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00006030 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00006031 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006032 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006033
Douglas Gregorebe10102009-08-20 07:17:43 +00006034 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006035 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006036 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006037 Then.get() == S->getThen() &&
6038 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006039 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006040
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006041 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00006042 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00006043 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006044}
6045
6046template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006047StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006048TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006049 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00006050 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006051 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00006052 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006053 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00006054 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006055 getDerived().TransformDefinition(
6056 S->getConditionVariable()->getLocation(),
6057 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00006058 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006059 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006060 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00006061 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006062
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006063 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006064 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006065 }
Mike Stump11289f42009-09-09 15:08:12 +00006066
Douglas Gregorebe10102009-08-20 07:17:43 +00006067 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006068 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00006069 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00006070 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00006071 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006072 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006073
Douglas Gregorebe10102009-08-20 07:17:43 +00006074 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006075 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006076 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006077 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006078
Douglas Gregorebe10102009-08-20 07:17:43 +00006079 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006080 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6081 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006082}
Mike Stump11289f42009-09-09 15:08:12 +00006083
Douglas Gregorebe10102009-08-20 07:17:43 +00006084template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006085StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006086TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006087 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006088 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006089 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00006090 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006091 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00006092 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006093 getDerived().TransformDefinition(
6094 S->getConditionVariable()->getLocation(),
6095 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00006096 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006097 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006098 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00006099 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006100
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006101 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006102 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006103
6104 if (S->getCond()) {
6105 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006106 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6107 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006108 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006109 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006110 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00006111 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00006112 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006113 }
Mike Stump11289f42009-09-09 15:08:12 +00006114
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006115 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006116 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006117 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006118
Douglas Gregorebe10102009-08-20 07:17:43 +00006119 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006120 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006121 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006122 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006123
Douglas Gregorebe10102009-08-20 07:17:43 +00006124 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006125 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006126 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006127 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006128 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006129
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006130 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00006131 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006132}
Mike Stump11289f42009-09-09 15:08:12 +00006133
Douglas Gregorebe10102009-08-20 07:17:43 +00006134template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006135StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006136TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006137 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006138 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006139 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006140 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006141
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006142 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006143 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006144 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006145 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006146
Douglas Gregorebe10102009-08-20 07:17:43 +00006147 if (!getDerived().AlwaysRebuild() &&
6148 Cond.get() == S->getCond() &&
6149 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006150 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006151
John McCallb268a282010-08-23 23:25:46 +00006152 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6153 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006154 S->getRParenLoc());
6155}
Mike Stump11289f42009-09-09 15:08:12 +00006156
Douglas Gregorebe10102009-08-20 07:17:43 +00006157template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006158StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006159TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006160 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006161 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006162 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006163 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006164
Douglas Gregorebe10102009-08-20 07:17:43 +00006165 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006166 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006167 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006168 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006169 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006170 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006171 getDerived().TransformDefinition(
6172 S->getConditionVariable()->getLocation(),
6173 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006174 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006175 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006176 } else {
6177 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006178
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006179 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006180 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006181
6182 if (S->getCond()) {
6183 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006184 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6185 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006186 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006187 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006188 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006189
John McCallb268a282010-08-23 23:25:46 +00006190 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006191 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006192 }
Mike Stump11289f42009-09-09 15:08:12 +00006193
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006194 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006195 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006196 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006197
Douglas Gregorebe10102009-08-20 07:17:43 +00006198 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006199 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006200 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006201 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006202
Richard Smith945f8d32013-01-14 22:39:08 +00006203 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006204 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006205 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006206
Douglas Gregorebe10102009-08-20 07:17:43 +00006207 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006208 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006209 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006210 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006211
Douglas Gregorebe10102009-08-20 07:17:43 +00006212 if (!getDerived().AlwaysRebuild() &&
6213 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00006214 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006215 Inc.get() == S->getInc() &&
6216 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006217 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006218
Douglas Gregorebe10102009-08-20 07:17:43 +00006219 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006220 Init.get(), FullCond, ConditionVar,
6221 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006222}
6223
6224template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006225StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006226TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006227 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6228 S->getLabel());
6229 if (!LD)
6230 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006231
Douglas Gregorebe10102009-08-20 07:17:43 +00006232 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006233 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006234 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006235}
6236
6237template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006238StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006239TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006240 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006241 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006242 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006243 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006244
Douglas Gregorebe10102009-08-20 07:17:43 +00006245 if (!getDerived().AlwaysRebuild() &&
6246 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006247 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006248
6249 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006250 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006251}
6252
6253template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006254StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006255TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006256 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006257}
Mike Stump11289f42009-09-09 15:08:12 +00006258
Douglas Gregorebe10102009-08-20 07:17:43 +00006259template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006260StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006261TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006262 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006263}
Mike Stump11289f42009-09-09 15:08:12 +00006264
Douglas Gregorebe10102009-08-20 07:17:43 +00006265template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006266StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006267TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006268 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6269 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006270 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006271 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006272
Mike Stump11289f42009-09-09 15:08:12 +00006273 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006274 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006275 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006276}
Mike Stump11289f42009-09-09 15:08:12 +00006277
Douglas Gregorebe10102009-08-20 07:17:43 +00006278template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006279StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006280TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006281 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006282 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006283 for (auto *D : S->decls()) {
6284 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006285 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006286 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006287
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006288 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006289 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006290
Douglas Gregorebe10102009-08-20 07:17:43 +00006291 Decls.push_back(Transformed);
6292 }
Mike Stump11289f42009-09-09 15:08:12 +00006293
Douglas Gregorebe10102009-08-20 07:17:43 +00006294 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006295 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006296
Rafael Espindolaab417692013-07-09 12:05:01 +00006297 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006298}
Mike Stump11289f42009-09-09 15:08:12 +00006299
Douglas Gregorebe10102009-08-20 07:17:43 +00006300template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006301StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006302TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006303
Benjamin Kramerf0623432012-08-23 22:51:59 +00006304 SmallVector<Expr*, 8> Constraints;
6305 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006306 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006307
John McCalldadc5752010-08-24 06:29:42 +00006308 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006309 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006310
6311 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006312
Anders Carlssonaaeef072010-01-24 05:50:09 +00006313 // Go through the outputs.
6314 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006315 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006316
Anders Carlssonaaeef072010-01-24 05:50:09 +00006317 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006318 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006319
Anders Carlssonaaeef072010-01-24 05:50:09 +00006320 // Transform the output expr.
6321 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006322 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006323 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006324 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006325
Anders Carlssonaaeef072010-01-24 05:50:09 +00006326 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006327
John McCallb268a282010-08-23 23:25:46 +00006328 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006329 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006330
Anders Carlssonaaeef072010-01-24 05:50:09 +00006331 // Go through the inputs.
6332 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006333 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006334
Anders Carlssonaaeef072010-01-24 05:50:09 +00006335 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006336 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006337
Anders Carlssonaaeef072010-01-24 05:50:09 +00006338 // Transform the input expr.
6339 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006340 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006341 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006342 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006343
Anders Carlssonaaeef072010-01-24 05:50:09 +00006344 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006345
John McCallb268a282010-08-23 23:25:46 +00006346 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006347 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006348
Anders Carlssonaaeef072010-01-24 05:50:09 +00006349 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006350 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006351
6352 // Go through the clobbers.
6353 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006354 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006355
6356 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006357 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006358 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6359 S->isVolatile(), S->getNumOutputs(),
6360 S->getNumInputs(), Names.data(),
6361 Constraints, Exprs, AsmString.get(),
6362 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006363}
6364
Chad Rosier32503022012-06-11 20:47:18 +00006365template<typename Derived>
6366StmtResult
6367TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006368 ArrayRef<Token> AsmToks =
6369 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006370
John McCallf413f5e2013-05-03 00:10:13 +00006371 bool HadError = false, HadChange = false;
6372
6373 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6374 SmallVector<Expr*, 8> TransformedExprs;
6375 TransformedExprs.reserve(SrcExprs.size());
6376 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6377 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6378 if (!Result.isUsable()) {
6379 HadError = true;
6380 } else {
6381 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006382 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006383 }
6384 }
6385
6386 if (HadError) return StmtError();
6387 if (!HadChange && !getDerived().AlwaysRebuild())
6388 return Owned(S);
6389
Chad Rosierb6f46c12012-08-15 16:53:30 +00006390 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006391 AsmToks, S->getAsmString(),
6392 S->getNumOutputs(), S->getNumInputs(),
6393 S->getAllConstraints(), S->getClobbers(),
6394 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006395}
Douglas Gregorebe10102009-08-20 07:17:43 +00006396
6397template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006398StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006399TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006400 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006401 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006402 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006403 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006404
Douglas Gregor96c79492010-04-23 22:50:49 +00006405 // Transform the @catch statements (if present).
6406 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006407 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006408 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006409 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006410 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006411 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006412 if (Catch.get() != S->getCatchStmt(I))
6413 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006414 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006415 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006416
Douglas Gregor306de2f2010-04-22 23:59:56 +00006417 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006418 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006419 if (S->getFinallyStmt()) {
6420 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6421 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006422 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006423 }
6424
6425 // If nothing changed, just retain this statement.
6426 if (!getDerived().AlwaysRebuild() &&
6427 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006428 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006429 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006430 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006431
Douglas Gregor306de2f2010-04-22 23:59:56 +00006432 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006433 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006434 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006435}
Mike Stump11289f42009-09-09 15:08:12 +00006436
Douglas Gregorebe10102009-08-20 07:17:43 +00006437template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006438StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006439TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006440 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006441 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006442 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006443 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006444 if (FromVar->getTypeSourceInfo()) {
6445 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6446 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006447 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006448 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006449
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006450 QualType T;
6451 if (TSInfo)
6452 T = TSInfo->getType();
6453 else {
6454 T = getDerived().TransformType(FromVar->getType());
6455 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006456 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006457 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006458
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006459 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6460 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006461 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006462 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006463
John McCalldadc5752010-08-24 06:29:42 +00006464 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006465 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006466 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006467
6468 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006469 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006470 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006471}
Mike Stump11289f42009-09-09 15:08:12 +00006472
Douglas Gregorebe10102009-08-20 07:17:43 +00006473template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006474StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006475TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006476 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006477 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006478 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006479 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006480
Douglas Gregor306de2f2010-04-22 23:59:56 +00006481 // If nothing changed, just retain this statement.
6482 if (!getDerived().AlwaysRebuild() &&
6483 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006484 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006485
6486 // Build a new statement.
6487 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006488 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006489}
Mike Stump11289f42009-09-09 15:08:12 +00006490
Douglas Gregorebe10102009-08-20 07:17:43 +00006491template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006492StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006493TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006494 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006495 if (S->getThrowExpr()) {
6496 Operand = getDerived().TransformExpr(S->getThrowExpr());
6497 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006498 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006499 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006500
Douglas Gregor2900c162010-04-22 21:44:01 +00006501 if (!getDerived().AlwaysRebuild() &&
6502 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006503 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006504
John McCallb268a282010-08-23 23:25:46 +00006505 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006506}
Mike Stump11289f42009-09-09 15:08:12 +00006507
Douglas Gregorebe10102009-08-20 07:17:43 +00006508template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006509StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006510TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006511 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006512 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006513 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006514 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006515 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006516 Object =
6517 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6518 Object.get());
6519 if (Object.isInvalid())
6520 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006521
Douglas Gregor6148de72010-04-22 22:01:21 +00006522 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006523 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006524 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006525 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006526
Douglas Gregor6148de72010-04-22 22:01:21 +00006527 // If nothing change, just retain the current statement.
6528 if (!getDerived().AlwaysRebuild() &&
6529 Object.get() == S->getSynchExpr() &&
6530 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006531 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006532
6533 // Build a new statement.
6534 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006535 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006536}
6537
6538template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006539StmtResult
John McCall31168b02011-06-15 23:02:42 +00006540TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6541 ObjCAutoreleasePoolStmt *S) {
6542 // Transform the body.
6543 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6544 if (Body.isInvalid())
6545 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006546
John McCall31168b02011-06-15 23:02:42 +00006547 // If nothing changed, just retain this statement.
6548 if (!getDerived().AlwaysRebuild() &&
6549 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006550 return S;
John McCall31168b02011-06-15 23:02:42 +00006551
6552 // Build a new statement.
6553 return getDerived().RebuildObjCAutoreleasePoolStmt(
6554 S->getAtLoc(), Body.get());
6555}
6556
6557template<typename Derived>
6558StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006559TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006560 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006561 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006562 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006563 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006564 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006565
Douglas Gregorf68a5082010-04-22 23:10:45 +00006566 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006567 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006568 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006569 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006570
Douglas Gregorf68a5082010-04-22 23:10:45 +00006571 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006572 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006573 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006574 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006575
Douglas Gregorf68a5082010-04-22 23:10:45 +00006576 // If nothing changed, just retain this statement.
6577 if (!getDerived().AlwaysRebuild() &&
6578 Element.get() == S->getElement() &&
6579 Collection.get() == S->getCollection() &&
6580 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006581 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006582
Douglas Gregorf68a5082010-04-22 23:10:45 +00006583 // Build a new statement.
6584 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006585 Element.get(),
6586 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006587 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006588 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006589}
6590
David Majnemer5f7efef2013-10-15 09:50:08 +00006591template <typename Derived>
6592StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006593 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006594 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006595 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6596 TypeSourceInfo *T =
6597 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006598 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006599 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006600
David Majnemer5f7efef2013-10-15 09:50:08 +00006601 Var = getDerived().RebuildExceptionDecl(
6602 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6603 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006604 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006605 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006606 }
Mike Stump11289f42009-09-09 15:08:12 +00006607
Douglas Gregorebe10102009-08-20 07:17:43 +00006608 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006609 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006610 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006611 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006612
David Majnemer5f7efef2013-10-15 09:50:08 +00006613 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006614 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006615 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006616
David Majnemer5f7efef2013-10-15 09:50:08 +00006617 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006618}
Mike Stump11289f42009-09-09 15:08:12 +00006619
David Majnemer5f7efef2013-10-15 09:50:08 +00006620template <typename Derived>
6621StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006622 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006623 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006624 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006625 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006626
Douglas Gregorebe10102009-08-20 07:17:43 +00006627 // Transform the handlers.
6628 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006629 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006630 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006631 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006632 if (Handler.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 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006636 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006637 }
Mike Stump11289f42009-09-09 15:08:12 +00006638
David Majnemer5f7efef2013-10-15 09:50:08 +00006639 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006640 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006641 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006642
John McCallb268a282010-08-23 23:25:46 +00006643 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006644 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006645}
Mike Stump11289f42009-09-09 15:08:12 +00006646
Richard Smith02e85f32011-04-14 22:09:26 +00006647template<typename Derived>
6648StmtResult
6649TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6650 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6651 if (Range.isInvalid())
6652 return StmtError();
6653
6654 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6655 if (BeginEnd.isInvalid())
6656 return StmtError();
6657
6658 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6659 if (Cond.isInvalid())
6660 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006661 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006662 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006663 if (Cond.isInvalid())
6664 return StmtError();
6665 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006666 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006667
6668 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6669 if (Inc.isInvalid())
6670 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006671 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006672 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006673
6674 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6675 if (LoopVar.isInvalid())
6676 return StmtError();
6677
6678 StmtResult NewStmt = S;
6679 if (getDerived().AlwaysRebuild() ||
6680 Range.get() != S->getRangeStmt() ||
6681 BeginEnd.get() != S->getBeginEndStmt() ||
6682 Cond.get() != S->getCond() ||
6683 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006684 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006685 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6686 S->getColonLoc(), Range.get(),
6687 BeginEnd.get(), Cond.get(),
6688 Inc.get(), LoopVar.get(),
6689 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006690 if (NewStmt.isInvalid())
6691 return StmtError();
6692 }
Richard Smith02e85f32011-04-14 22:09:26 +00006693
6694 StmtResult Body = getDerived().TransformStmt(S->getBody());
6695 if (Body.isInvalid())
6696 return StmtError();
6697
6698 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6699 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006700 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006701 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6702 S->getColonLoc(), Range.get(),
6703 BeginEnd.get(), Cond.get(),
6704 Inc.get(), LoopVar.get(),
6705 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006706 if (NewStmt.isInvalid())
6707 return StmtError();
6708 }
Richard Smith02e85f32011-04-14 22:09:26 +00006709
6710 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006711 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006712
6713 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6714}
6715
John Wiegley1c0675e2011-04-28 01:08:34 +00006716template<typename Derived>
6717StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006718TreeTransform<Derived>::TransformMSDependentExistsStmt(
6719 MSDependentExistsStmt *S) {
6720 // Transform the nested-name-specifier, if any.
6721 NestedNameSpecifierLoc QualifierLoc;
6722 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006723 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006724 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6725 if (!QualifierLoc)
6726 return StmtError();
6727 }
6728
6729 // Transform the declaration name.
6730 DeclarationNameInfo NameInfo = S->getNameInfo();
6731 if (NameInfo.getName()) {
6732 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6733 if (!NameInfo.getName())
6734 return StmtError();
6735 }
6736
6737 // Check whether anything changed.
6738 if (!getDerived().AlwaysRebuild() &&
6739 QualifierLoc == S->getQualifierLoc() &&
6740 NameInfo.getName() == S->getNameInfo().getName())
6741 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006742
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006743 // Determine whether this name exists, if we can.
6744 CXXScopeSpec SS;
6745 SS.Adopt(QualifierLoc);
6746 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006747 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006748 case Sema::IER_Exists:
6749 if (S->isIfExists())
6750 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006751
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006752 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6753
6754 case Sema::IER_DoesNotExist:
6755 if (S->isIfNotExists())
6756 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006757
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006758 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006759
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006760 case Sema::IER_Dependent:
6761 Dependent = true;
6762 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006763
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006764 case Sema::IER_Error:
6765 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006766 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006767
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006768 // We need to continue with the instantiation, so do so now.
6769 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6770 if (SubStmt.isInvalid())
6771 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006772
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006773 // If we have resolved the name, just transform to the substatement.
6774 if (!Dependent)
6775 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006776
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006777 // The name is still dependent, so build a dependent expression again.
6778 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6779 S->isIfExists(),
6780 QualifierLoc,
6781 NameInfo,
6782 SubStmt.get());
6783}
6784
6785template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006786ExprResult
6787TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6788 NestedNameSpecifierLoc QualifierLoc;
6789 if (E->getQualifierLoc()) {
6790 QualifierLoc
6791 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6792 if (!QualifierLoc)
6793 return ExprError();
6794 }
6795
6796 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6797 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6798 if (!PD)
6799 return ExprError();
6800
6801 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6802 if (Base.isInvalid())
6803 return ExprError();
6804
6805 return new (SemaRef.getASTContext())
6806 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6807 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6808 QualifierLoc, E->getMemberLoc());
6809}
6810
David Majnemerfad8f482013-10-15 09:33:02 +00006811template <typename Derived>
6812StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006813 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006814 if (TryBlock.isInvalid())
6815 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006816
6817 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006818 if (Handler.isInvalid())
6819 return StmtError();
6820
David Majnemerfad8f482013-10-15 09:33:02 +00006821 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6822 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006823 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006824
Warren Huntf6be4cb2014-07-25 20:52:51 +00006825 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6826 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006827}
6828
David Majnemerfad8f482013-10-15 09:33:02 +00006829template <typename Derived>
6830StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006831 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006832 if (Block.isInvalid())
6833 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006834
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006835 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006836}
6837
David Majnemerfad8f482013-10-15 09:33:02 +00006838template <typename Derived>
6839StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006840 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006841 if (FilterExpr.isInvalid())
6842 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006843
David Majnemer7e755502013-10-15 09:30:14 +00006844 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006845 if (Block.isInvalid())
6846 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006847
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006848 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6849 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006850}
6851
David Majnemerfad8f482013-10-15 09:33:02 +00006852template <typename Derived>
6853StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6854 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006855 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6856 else
6857 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6858}
6859
Nico Weber9b982072014-07-07 00:12:30 +00006860template<typename Derived>
6861StmtResult
6862TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6863 return S;
6864}
6865
Alexander Musman64d33f12014-06-04 07:53:32 +00006866//===----------------------------------------------------------------------===//
6867// OpenMP directive transformation
6868//===----------------------------------------------------------------------===//
6869template <typename Derived>
6870StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6871 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006872
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006873 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006874 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006875 ArrayRef<OMPClause *> Clauses = D->clauses();
6876 TClauses.reserve(Clauses.size());
6877 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6878 I != E; ++I) {
6879 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00006880 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006881 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00006882 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00006883 if (Clause)
6884 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006885 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006886 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006887 }
6888 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006889 StmtResult AssociatedStmt;
6890 if (D->hasAssociatedStmt()) {
6891 if (!D->getAssociatedStmt()) {
6892 return StmtError();
6893 }
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00006894 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
6895 /*CurScope=*/nullptr);
6896 StmtResult Body;
6897 {
6898 Sema::CompoundScopeRAII CompoundScope(getSema());
6899 Body = getDerived().TransformStmt(
6900 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
6901 }
6902 AssociatedStmt =
6903 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00006904 if (AssociatedStmt.isInvalid()) {
6905 return StmtError();
6906 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006907 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006908 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006909 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006910 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006911
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006912 // Transform directive name for 'omp critical' directive.
6913 DeclarationNameInfo DirName;
6914 if (D->getDirectiveKind() == OMPD_critical) {
6915 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6916 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6917 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006918 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
6919 if (D->getDirectiveKind() == OMPD_cancellation_point) {
6920 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00006921 } else if (D->getDirectiveKind() == OMPD_cancel) {
6922 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006923 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006924
Alexander Musman64d33f12014-06-04 07:53:32 +00006925 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006926 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
6927 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006928}
6929
Alexander Musman64d33f12014-06-04 07:53:32 +00006930template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006931StmtResult
6932TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6933 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006934 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6935 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006936 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6937 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6938 return Res;
6939}
6940
Alexander Musman64d33f12014-06-04 07:53:32 +00006941template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006942StmtResult
6943TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6944 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006945 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6946 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006947 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6948 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006949 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006950}
6951
Alexey Bataevf29276e2014-06-18 04:14:57 +00006952template <typename Derived>
6953StmtResult
6954TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6955 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006956 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6957 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006958 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6959 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6960 return Res;
6961}
6962
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006963template <typename Derived>
6964StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00006965TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
6966 DeclarationNameInfo DirName;
6967 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
6968 D->getLocStart());
6969 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6970 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6971 return Res;
6972}
6973
6974template <typename Derived>
6975StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006976TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6977 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006978 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6979 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006980 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6981 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6982 return Res;
6983}
6984
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006985template <typename Derived>
6986StmtResult
6987TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6988 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006989 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6990 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006991 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6992 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6993 return Res;
6994}
6995
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00006996template <typename Derived>
6997StmtResult
6998TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
6999 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007000 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7001 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007002 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7003 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7004 return Res;
7005}
7006
Alexey Bataev4acb8592014-07-07 13:01:15 +00007007template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007008StmtResult
7009TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7010 DeclarationNameInfo DirName;
7011 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7012 D->getLocStart());
7013 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7014 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7015 return Res;
7016}
7017
7018template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007019StmtResult
7020TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7021 getDerived().getSema().StartOpenMPDSABlock(
7022 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7023 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7024 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7025 return Res;
7026}
7027
7028template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007029StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7030 OMPParallelForDirective *D) {
7031 DeclarationNameInfo DirName;
7032 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7033 nullptr, D->getLocStart());
7034 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7035 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7036 return Res;
7037}
7038
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007039template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007040StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7041 OMPParallelForSimdDirective *D) {
7042 DeclarationNameInfo DirName;
7043 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7044 nullptr, D->getLocStart());
7045 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7046 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7047 return Res;
7048}
7049
7050template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007051StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7052 OMPParallelSectionsDirective *D) {
7053 DeclarationNameInfo DirName;
7054 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7055 nullptr, D->getLocStart());
7056 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7057 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7058 return Res;
7059}
7060
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007061template <typename Derived>
7062StmtResult
7063TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7064 DeclarationNameInfo DirName;
7065 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7066 D->getLocStart());
7067 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7068 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7069 return Res;
7070}
7071
Alexey Bataev68446b72014-07-18 07:47:19 +00007072template <typename Derived>
7073StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7074 OMPTaskyieldDirective *D) {
7075 DeclarationNameInfo DirName;
7076 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7077 D->getLocStart());
7078 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7079 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7080 return Res;
7081}
7082
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007083template <typename Derived>
7084StmtResult
7085TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7086 DeclarationNameInfo DirName;
7087 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7088 D->getLocStart());
7089 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7090 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7091 return Res;
7092}
7093
Alexey Bataev2df347a2014-07-18 10:17:07 +00007094template <typename Derived>
7095StmtResult
7096TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7097 DeclarationNameInfo DirName;
7098 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7099 D->getLocStart());
7100 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7101 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7102 return Res;
7103}
7104
Alexey Bataev6125da92014-07-21 11:26:11 +00007105template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007106StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7107 OMPTaskgroupDirective *D) {
7108 DeclarationNameInfo DirName;
7109 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7110 D->getLocStart());
7111 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7112 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7113 return Res;
7114}
7115
7116template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007117StmtResult
7118TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7119 DeclarationNameInfo DirName;
7120 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7121 D->getLocStart());
7122 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7123 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7124 return Res;
7125}
7126
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007127template <typename Derived>
7128StmtResult
7129TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7130 DeclarationNameInfo DirName;
7131 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7132 D->getLocStart());
7133 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7134 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7135 return Res;
7136}
7137
Alexey Bataev0162e452014-07-22 10:10:35 +00007138template <typename Derived>
7139StmtResult
7140TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7141 DeclarationNameInfo DirName;
7142 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7143 D->getLocStart());
7144 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7145 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7146 return Res;
7147}
7148
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007149template <typename Derived>
7150StmtResult
7151TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7152 DeclarationNameInfo DirName;
7153 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7154 D->getLocStart());
7155 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7156 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7157 return Res;
7158}
7159
Alexey Bataev13314bf2014-10-09 04:18:56 +00007160template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007161StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7162 OMPTargetDataDirective *D) {
7163 DeclarationNameInfo DirName;
7164 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7165 D->getLocStart());
7166 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7167 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7168 return Res;
7169}
7170
7171template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007172StmtResult
7173TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7174 DeclarationNameInfo DirName;
7175 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7176 D->getLocStart());
7177 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7178 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7179 return Res;
7180}
7181
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007182template <typename Derived>
7183StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7184 OMPCancellationPointDirective *D) {
7185 DeclarationNameInfo DirName;
7186 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7187 nullptr, D->getLocStart());
7188 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7189 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7190 return Res;
7191}
7192
Alexey Bataev80909872015-07-02 11:25:17 +00007193template <typename Derived>
7194StmtResult
7195TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7196 DeclarationNameInfo DirName;
7197 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7198 D->getLocStart());
7199 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7200 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7201 return Res;
7202}
7203
Alexander Musman64d33f12014-06-04 07:53:32 +00007204//===----------------------------------------------------------------------===//
7205// OpenMP clause transformation
7206//===----------------------------------------------------------------------===//
7207template <typename Derived>
7208OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007209 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7210 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007211 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007212 return getDerived().RebuildOMPIfClause(Cond.get(), C->getLocStart(),
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007213 C->getLParenLoc(), C->getLocEnd());
7214}
7215
Alexander Musman64d33f12014-06-04 07:53:32 +00007216template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007217OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7218 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7219 if (Cond.isInvalid())
7220 return nullptr;
7221 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7222 C->getLParenLoc(), C->getLocEnd());
7223}
7224
7225template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007226OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007227TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7228 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7229 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007230 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007231 return getDerived().RebuildOMPNumThreadsClause(
7232 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007233}
7234
Alexey Bataev62c87d22014-03-21 04:51:18 +00007235template <typename Derived>
7236OMPClause *
7237TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7238 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7239 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007240 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007241 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007242 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007243}
7244
Alexander Musman8bd31e62014-05-27 15:12:19 +00007245template <typename Derived>
7246OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007247TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7248 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7249 if (E.isInvalid())
7250 return nullptr;
7251 return getDerived().RebuildOMPSimdlenClause(
7252 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7253}
7254
7255template <typename Derived>
7256OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007257TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7258 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7259 if (E.isInvalid())
7260 return 0;
7261 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007262 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007263}
7264
Alexander Musman64d33f12014-06-04 07:53:32 +00007265template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007266OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007267TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007268 return getDerived().RebuildOMPDefaultClause(
7269 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7270 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007271}
7272
Alexander Musman64d33f12014-06-04 07:53:32 +00007273template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007274OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007275TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007276 return getDerived().RebuildOMPProcBindClause(
7277 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7278 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007279}
7280
Alexander Musman64d33f12014-06-04 07:53:32 +00007281template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007282OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007283TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7284 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7285 if (E.isInvalid())
7286 return nullptr;
7287 return getDerived().RebuildOMPScheduleClause(
7288 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7289 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7290}
7291
7292template <typename Derived>
7293OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007294TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007295 ExprResult E;
7296 if (auto *Num = C->getNumForLoops()) {
7297 E = getDerived().TransformExpr(Num);
7298 if (E.isInvalid())
7299 return nullptr;
7300 }
7301 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7302 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007303}
7304
7305template <typename Derived>
7306OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007307TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7308 // No need to rebuild this clause, no template-dependent parameters.
7309 return C;
7310}
7311
7312template <typename Derived>
7313OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007314TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7315 // No need to rebuild this clause, no template-dependent parameters.
7316 return C;
7317}
7318
7319template <typename Derived>
7320OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007321TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7322 // No need to rebuild this clause, no template-dependent parameters.
7323 return C;
7324}
7325
7326template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007327OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7328 // No need to rebuild this clause, no template-dependent parameters.
7329 return C;
7330}
7331
7332template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007333OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7334 // No need to rebuild this clause, no template-dependent parameters.
7335 return C;
7336}
7337
7338template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007339OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007340TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7341 // No need to rebuild this clause, no template-dependent parameters.
7342 return C;
7343}
7344
7345template <typename Derived>
7346OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007347TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7348 // No need to rebuild this clause, no template-dependent parameters.
7349 return C;
7350}
7351
7352template <typename Derived>
7353OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007354TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7355 // No need to rebuild this clause, no template-dependent parameters.
7356 return C;
7357}
7358
7359template <typename Derived>
7360OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007361TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007362 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007363 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007364 for (auto *VE : C->varlists()) {
7365 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007366 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007367 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007368 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007369 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007370 return getDerived().RebuildOMPPrivateClause(
7371 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007372}
7373
Alexander Musman64d33f12014-06-04 07:53:32 +00007374template <typename Derived>
7375OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7376 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007377 llvm::SmallVector<Expr *, 16> Vars;
7378 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007379 for (auto *VE : C->varlists()) {
7380 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007381 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007382 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007383 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007384 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007385 return getDerived().RebuildOMPFirstprivateClause(
7386 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007387}
7388
Alexander Musman64d33f12014-06-04 07:53:32 +00007389template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007390OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007391TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7392 llvm::SmallVector<Expr *, 16> Vars;
7393 Vars.reserve(C->varlist_size());
7394 for (auto *VE : C->varlists()) {
7395 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7396 if (EVar.isInvalid())
7397 return nullptr;
7398 Vars.push_back(EVar.get());
7399 }
7400 return getDerived().RebuildOMPLastprivateClause(
7401 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7402}
7403
7404template <typename Derived>
7405OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007406TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7407 llvm::SmallVector<Expr *, 16> Vars;
7408 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007409 for (auto *VE : C->varlists()) {
7410 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007411 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007412 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007413 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007414 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007415 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7416 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007417}
7418
Alexander Musman64d33f12014-06-04 07:53:32 +00007419template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007420OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007421TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7422 llvm::SmallVector<Expr *, 16> Vars;
7423 Vars.reserve(C->varlist_size());
7424 for (auto *VE : C->varlists()) {
7425 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7426 if (EVar.isInvalid())
7427 return nullptr;
7428 Vars.push_back(EVar.get());
7429 }
7430 CXXScopeSpec ReductionIdScopeSpec;
7431 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7432
7433 DeclarationNameInfo NameInfo = C->getNameInfo();
7434 if (NameInfo.getName()) {
7435 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7436 if (!NameInfo.getName())
7437 return nullptr;
7438 }
7439 return getDerived().RebuildOMPReductionClause(
7440 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7441 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7442}
7443
7444template <typename Derived>
7445OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007446TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7447 llvm::SmallVector<Expr *, 16> Vars;
7448 Vars.reserve(C->varlist_size());
7449 for (auto *VE : C->varlists()) {
7450 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7451 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007452 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007453 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007454 }
7455 ExprResult Step = getDerived().TransformExpr(C->getStep());
7456 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007457 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007458 return getDerived().RebuildOMPLinearClause(
7459 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7460 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007461}
7462
Alexander Musman64d33f12014-06-04 07:53:32 +00007463template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007464OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007465TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7466 llvm::SmallVector<Expr *, 16> Vars;
7467 Vars.reserve(C->varlist_size());
7468 for (auto *VE : C->varlists()) {
7469 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7470 if (EVar.isInvalid())
7471 return nullptr;
7472 Vars.push_back(EVar.get());
7473 }
7474 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7475 if (Alignment.isInvalid())
7476 return nullptr;
7477 return getDerived().RebuildOMPAlignedClause(
7478 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7479 C->getColonLoc(), C->getLocEnd());
7480}
7481
Alexander Musman64d33f12014-06-04 07:53:32 +00007482template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007483OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007484TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7485 llvm::SmallVector<Expr *, 16> Vars;
7486 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007487 for (auto *VE : C->varlists()) {
7488 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007489 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007490 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007491 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007492 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007493 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7494 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007495}
7496
Alexey Bataevbae9a792014-06-27 10:37:06 +00007497template <typename Derived>
7498OMPClause *
7499TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7500 llvm::SmallVector<Expr *, 16> Vars;
7501 Vars.reserve(C->varlist_size());
7502 for (auto *VE : C->varlists()) {
7503 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7504 if (EVar.isInvalid())
7505 return nullptr;
7506 Vars.push_back(EVar.get());
7507 }
7508 return getDerived().RebuildOMPCopyprivateClause(
7509 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7510}
7511
Alexey Bataev6125da92014-07-21 11:26:11 +00007512template <typename Derived>
7513OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7514 llvm::SmallVector<Expr *, 16> Vars;
7515 Vars.reserve(C->varlist_size());
7516 for (auto *VE : C->varlists()) {
7517 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7518 if (EVar.isInvalid())
7519 return nullptr;
7520 Vars.push_back(EVar.get());
7521 }
7522 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7523 C->getLParenLoc(), C->getLocEnd());
7524}
7525
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007526template <typename Derived>
7527OMPClause *
7528TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7529 llvm::SmallVector<Expr *, 16> Vars;
7530 Vars.reserve(C->varlist_size());
7531 for (auto *VE : C->varlists()) {
7532 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7533 if (EVar.isInvalid())
7534 return nullptr;
7535 Vars.push_back(EVar.get());
7536 }
7537 return getDerived().RebuildOMPDependClause(
7538 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7539 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7540}
7541
Michael Wonge710d542015-08-07 16:16:36 +00007542template <typename Derived>
7543OMPClause *
7544TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7545 ExprResult E = getDerived().TransformExpr(C->getDevice());
7546 if (E.isInvalid())
7547 return nullptr;
7548 return getDerived().RebuildOMPDeviceClause(
7549 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7550}
7551
Douglas Gregorebe10102009-08-20 07:17:43 +00007552//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007553// Expression transformation
7554//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007555template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007556ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007557TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007558 if (!E->isTypeDependent())
7559 return E;
7560
7561 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7562 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007563}
Mike Stump11289f42009-09-09 15:08:12 +00007564
7565template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007566ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007567TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007568 NestedNameSpecifierLoc QualifierLoc;
7569 if (E->getQualifierLoc()) {
7570 QualifierLoc
7571 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7572 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007573 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007574 }
John McCallce546572009-12-08 09:08:17 +00007575
7576 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007577 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7578 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007579 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007580 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007581
John McCall815039a2010-08-17 21:27:17 +00007582 DeclarationNameInfo NameInfo = E->getNameInfo();
7583 if (NameInfo.getName()) {
7584 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7585 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007586 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007587 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007588
7589 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007590 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007591 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007592 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007593 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007594
7595 // Mark it referenced in the new context regardless.
7596 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007597 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007598
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007599 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007600 }
John McCallce546572009-12-08 09:08:17 +00007601
Craig Topperc3ec1492014-05-26 06:22:03 +00007602 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007603 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007604 TemplateArgs = &TransArgs;
7605 TransArgs.setLAngleLoc(E->getLAngleLoc());
7606 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007607 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7608 E->getNumTemplateArgs(),
7609 TransArgs))
7610 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007611 }
7612
Chad Rosier1dcde962012-08-08 18:46:20 +00007613 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007614 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007615}
Mike Stump11289f42009-09-09 15:08:12 +00007616
Douglas Gregora16548e2009-08-11 05:31:07 +00007617template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007618ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007619TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007620 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007621}
Mike Stump11289f42009-09-09 15:08:12 +00007622
Douglas Gregora16548e2009-08-11 05:31:07 +00007623template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007624ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007625TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007626 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007627}
Mike Stump11289f42009-09-09 15:08:12 +00007628
Douglas Gregora16548e2009-08-11 05:31:07 +00007629template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007630ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007631TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007632 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007633}
Mike Stump11289f42009-09-09 15:08:12 +00007634
Douglas Gregora16548e2009-08-11 05:31:07 +00007635template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007636ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007637TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007638 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007639}
Mike Stump11289f42009-09-09 15:08:12 +00007640
Douglas Gregora16548e2009-08-11 05:31:07 +00007641template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007642ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007643TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007644 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007645}
7646
7647template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007648ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007649TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007650 if (FunctionDecl *FD = E->getDirectCallee())
7651 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007652 return SemaRef.MaybeBindToTemporary(E);
7653}
7654
7655template<typename Derived>
7656ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007657TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7658 ExprResult ControllingExpr =
7659 getDerived().TransformExpr(E->getControllingExpr());
7660 if (ControllingExpr.isInvalid())
7661 return ExprError();
7662
Chris Lattner01cf8db2011-07-20 06:58:45 +00007663 SmallVector<Expr *, 4> AssocExprs;
7664 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007665 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7666 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7667 if (TS) {
7668 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7669 if (!AssocType)
7670 return ExprError();
7671 AssocTypes.push_back(AssocType);
7672 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007673 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007674 }
7675
7676 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7677 if (AssocExpr.isInvalid())
7678 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007679 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007680 }
7681
7682 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7683 E->getDefaultLoc(),
7684 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007685 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007686 AssocTypes,
7687 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007688}
7689
7690template<typename Derived>
7691ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007692TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007693 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007694 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007695 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007696
Douglas Gregora16548e2009-08-11 05:31:07 +00007697 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007698 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007699
John McCallb268a282010-08-23 23:25:46 +00007700 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007701 E->getRParen());
7702}
7703
Richard Smithdb2630f2012-10-21 03:28:35 +00007704/// \brief The operand of a unary address-of operator has special rules: it's
7705/// allowed to refer to a non-static member of a class even if there's no 'this'
7706/// object available.
7707template<typename Derived>
7708ExprResult
7709TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7710 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007711 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007712 else
7713 return getDerived().TransformExpr(E);
7714}
7715
Mike Stump11289f42009-09-09 15:08:12 +00007716template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007717ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007718TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007719 ExprResult SubExpr;
7720 if (E->getOpcode() == UO_AddrOf)
7721 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7722 else
7723 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007724 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007725 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007726
Douglas Gregora16548e2009-08-11 05:31:07 +00007727 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007728 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007729
Douglas Gregora16548e2009-08-11 05:31:07 +00007730 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7731 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007732 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007733}
Mike Stump11289f42009-09-09 15:08:12 +00007734
Douglas Gregora16548e2009-08-11 05:31:07 +00007735template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007736ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007737TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7738 // Transform the type.
7739 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7740 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007741 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007742
Douglas Gregor882211c2010-04-28 22:16:22 +00007743 // Transform all of the components into components similar to what the
7744 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007745 // FIXME: It would be slightly more efficient in the non-dependent case to
7746 // just map FieldDecls, rather than requiring the rebuilder to look for
7747 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007748 // template code that we don't care.
7749 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007750 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007751 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007752 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007753 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7754 const Node &ON = E->getComponent(I);
7755 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007756 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007757 Comp.LocStart = ON.getSourceRange().getBegin();
7758 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007759 switch (ON.getKind()) {
7760 case Node::Array: {
7761 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007762 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007763 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007764 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007765
Douglas Gregor882211c2010-04-28 22:16:22 +00007766 ExprChanged = ExprChanged || Index.get() != FromIndex;
7767 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007768 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007769 break;
7770 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007771
Douglas Gregor882211c2010-04-28 22:16:22 +00007772 case Node::Field:
7773 case Node::Identifier:
7774 Comp.isBrackets = false;
7775 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007776 if (!Comp.U.IdentInfo)
7777 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007778
Douglas Gregor882211c2010-04-28 22:16:22 +00007779 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007780
Douglas Gregord1702062010-04-29 00:18:15 +00007781 case Node::Base:
7782 // Will be recomputed during the rebuild.
7783 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007784 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007785
Douglas Gregor882211c2010-04-28 22:16:22 +00007786 Components.push_back(Comp);
7787 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007788
Douglas Gregor882211c2010-04-28 22:16:22 +00007789 // If nothing changed, retain the existing expression.
7790 if (!getDerived().AlwaysRebuild() &&
7791 Type == E->getTypeSourceInfo() &&
7792 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007793 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007794
Douglas Gregor882211c2010-04-28 22:16:22 +00007795 // Build a new offsetof expression.
7796 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
7797 Components.data(), Components.size(),
7798 E->getRParenLoc());
7799}
7800
7801template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007802ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007803TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
7804 assert(getDerived().AlreadyTransformed(E->getType()) &&
7805 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007806 return E;
John McCall8d69a212010-11-15 23:31:06 +00007807}
7808
7809template<typename Derived>
7810ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00007811TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
7812 return E;
7813}
7814
7815template<typename Derived>
7816ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007817TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007818 // Rebuild the syntactic form. The original syntactic form has
7819 // opaque-value expressions in it, so strip those away and rebuild
7820 // the result. This is a really awful way of doing this, but the
7821 // better solution (rebuilding the semantic expressions and
7822 // rebinding OVEs as necessary) doesn't work; we'd need
7823 // TreeTransform to not strip away implicit conversions.
7824 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7825 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007826 if (result.isInvalid()) return ExprError();
7827
7828 // If that gives us a pseudo-object result back, the pseudo-object
7829 // expression must have been an lvalue-to-rvalue conversion which we
7830 // should reapply.
7831 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007832 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007833
7834 return result;
7835}
7836
7837template<typename Derived>
7838ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007839TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7840 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007841 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007842 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007843
John McCallbcd03502009-12-07 02:54:59 +00007844 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007845 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007846 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007847
John McCall4c98fd82009-11-04 07:28:41 +00007848 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007849 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007850
Peter Collingbournee190dee2011-03-11 19:24:49 +00007851 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7852 E->getKind(),
7853 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007854 }
Mike Stump11289f42009-09-09 15:08:12 +00007855
Eli Friedmane4f22df2012-02-29 04:03:55 +00007856 // C++0x [expr.sizeof]p1:
7857 // The operand is either an expression, which is an unevaluated operand
7858 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007859 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7860 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007861
Reid Kleckner32506ed2014-06-12 23:03:48 +00007862 // Try to recover if we have something like sizeof(T::X) where X is a type.
7863 // Notably, there must be *exactly* one set of parens if X is a type.
7864 TypeSourceInfo *RecoveryTSI = nullptr;
7865 ExprResult SubExpr;
7866 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7867 if (auto *DRE =
7868 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7869 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7870 PE, DRE, false, &RecoveryTSI);
7871 else
7872 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7873
7874 if (RecoveryTSI) {
7875 return getDerived().RebuildUnaryExprOrTypeTrait(
7876 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7877 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007878 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007879
Eli Friedmane4f22df2012-02-29 04:03:55 +00007880 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007881 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007882
Peter Collingbournee190dee2011-03-11 19:24:49 +00007883 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7884 E->getOperatorLoc(),
7885 E->getKind(),
7886 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007887}
Mike Stump11289f42009-09-09 15:08:12 +00007888
Douglas Gregora16548e2009-08-11 05:31:07 +00007889template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007890ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007891TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007892 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007893 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007894 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007895
John McCalldadc5752010-08-24 06:29:42 +00007896 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007897 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007898 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007899
7900
Douglas Gregora16548e2009-08-11 05:31:07 +00007901 if (!getDerived().AlwaysRebuild() &&
7902 LHS.get() == E->getLHS() &&
7903 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007904 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007905
John McCallb268a282010-08-23 23:25:46 +00007906 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007907 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007908 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007909 E->getRBracketLoc());
7910}
Mike Stump11289f42009-09-09 15:08:12 +00007911
Alexey Bataev1a3320e2015-08-25 14:24:04 +00007912template <typename Derived>
7913ExprResult
7914TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
7915 ExprResult Base = getDerived().TransformExpr(E->getBase());
7916 if (Base.isInvalid())
7917 return ExprError();
7918
7919 ExprResult LowerBound;
7920 if (E->getLowerBound()) {
7921 LowerBound = getDerived().TransformExpr(E->getLowerBound());
7922 if (LowerBound.isInvalid())
7923 return ExprError();
7924 }
7925
7926 ExprResult Length;
7927 if (E->getLength()) {
7928 Length = getDerived().TransformExpr(E->getLength());
7929 if (Length.isInvalid())
7930 return ExprError();
7931 }
7932
7933 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
7934 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
7935 return E;
7936
7937 return getDerived().RebuildOMPArraySectionExpr(
7938 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
7939 Length.get(), E->getRBracketLoc());
7940}
7941
Mike Stump11289f42009-09-09 15:08:12 +00007942template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007943ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007944TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007945 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007946 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007947 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007948 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007949
7950 // Transform arguments.
7951 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007952 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007953 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007954 &ArgChanged))
7955 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007956
Douglas Gregora16548e2009-08-11 05:31:07 +00007957 if (!getDerived().AlwaysRebuild() &&
7958 Callee.get() == E->getCallee() &&
7959 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007960 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007961
Douglas Gregora16548e2009-08-11 05:31:07 +00007962 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007963 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007964 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007965 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007966 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007967 E->getRParenLoc());
7968}
Mike Stump11289f42009-09-09 15:08:12 +00007969
7970template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007971ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007972TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007973 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007974 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007975 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007976
Douglas Gregorea972d32011-02-28 21:54:11 +00007977 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007978 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007979 QualifierLoc
7980 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00007981
Douglas Gregorea972d32011-02-28 21:54:11 +00007982 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007983 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007984 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00007985 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00007986
Eli Friedman2cfcef62009-12-04 06:40:45 +00007987 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007988 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
7989 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007990 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00007991 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007992
John McCall16df1e52010-03-30 21:47:33 +00007993 NamedDecl *FoundDecl = E->getFoundDecl();
7994 if (FoundDecl == E->getMemberDecl()) {
7995 FoundDecl = Member;
7996 } else {
7997 FoundDecl = cast_or_null<NamedDecl>(
7998 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
7999 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008000 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008001 }
8002
Douglas Gregora16548e2009-08-11 05:31:07 +00008003 if (!getDerived().AlwaysRebuild() &&
8004 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008005 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008006 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008007 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008008 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008009
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008010 // Mark it referenced in the new context regardless.
8011 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008012 SemaRef.MarkMemberReferenced(E);
8013
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008014 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008015 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008016
John McCall6b51f282009-11-23 01:53:49 +00008017 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008018 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008019 TransArgs.setLAngleLoc(E->getLAngleLoc());
8020 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008021 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8022 E->getNumTemplateArgs(),
8023 TransArgs))
8024 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008025 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008026
Douglas Gregora16548e2009-08-11 05:31:07 +00008027 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008028 SourceLocation FakeOperatorLoc =
8029 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008030
John McCall38836f02010-01-15 08:34:02 +00008031 // FIXME: to do this check properly, we will need to preserve the
8032 // first-qualifier-in-scope here, just in case we had a dependent
8033 // base (and therefore couldn't do the check) and a
8034 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008035 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008036
John McCallb268a282010-08-23 23:25:46 +00008037 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008038 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008039 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008040 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008041 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008042 Member,
John McCall16df1e52010-03-30 21:47:33 +00008043 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008044 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008045 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008046 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008047}
Mike Stump11289f42009-09-09 15:08:12 +00008048
Douglas Gregora16548e2009-08-11 05:31:07 +00008049template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008050ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008051TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008052 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008053 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008054 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008055
John McCalldadc5752010-08-24 06:29:42 +00008056 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008057 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008058 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008059
Douglas Gregora16548e2009-08-11 05:31:07 +00008060 if (!getDerived().AlwaysRebuild() &&
8061 LHS.get() == E->getLHS() &&
8062 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008063 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008064
Lang Hames5de91cc2012-10-02 04:45:10 +00008065 Sema::FPContractStateRAII FPContractState(getSema());
8066 getSema().FPFeatures.fp_contract = E->isFPContractable();
8067
Douglas Gregora16548e2009-08-11 05:31:07 +00008068 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008069 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008070}
8071
Mike Stump11289f42009-09-09 15:08:12 +00008072template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008073ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008074TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008075 CompoundAssignOperator *E) {
8076 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008077}
Mike Stump11289f42009-09-09 15:08:12 +00008078
Douglas Gregora16548e2009-08-11 05:31:07 +00008079template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008080ExprResult TreeTransform<Derived>::
8081TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8082 // Just rebuild the common and RHS expressions and see whether we
8083 // get any changes.
8084
8085 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8086 if (commonExpr.isInvalid())
8087 return ExprError();
8088
8089 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8090 if (rhs.isInvalid())
8091 return ExprError();
8092
8093 if (!getDerived().AlwaysRebuild() &&
8094 commonExpr.get() == e->getCommon() &&
8095 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008096 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008097
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008098 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008099 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008100 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008101 e->getColonLoc(),
8102 rhs.get());
8103}
8104
8105template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008106ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008107TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008108 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008109 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008110 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008111
John McCalldadc5752010-08-24 06:29:42 +00008112 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008113 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008114 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008115
John McCalldadc5752010-08-24 06:29:42 +00008116 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008117 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008118 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008119
Douglas Gregora16548e2009-08-11 05:31:07 +00008120 if (!getDerived().AlwaysRebuild() &&
8121 Cond.get() == E->getCond() &&
8122 LHS.get() == E->getLHS() &&
8123 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008124 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008125
John McCallb268a282010-08-23 23:25:46 +00008126 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008127 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008128 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008129 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008130 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008131}
Mike Stump11289f42009-09-09 15:08:12 +00008132
8133template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008134ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008135TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008136 // Implicit casts are eliminated during transformation, since they
8137 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008138 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008139}
Mike Stump11289f42009-09-09 15:08:12 +00008140
Douglas Gregora16548e2009-08-11 05:31:07 +00008141template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008142ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008143TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008144 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8145 if (!Type)
8146 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008147
John McCalldadc5752010-08-24 06:29:42 +00008148 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008149 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008150 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008151 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008152
Douglas Gregora16548e2009-08-11 05:31:07 +00008153 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008154 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008155 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008156 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008157
John McCall97513962010-01-15 18:39:57 +00008158 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008159 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008160 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008161 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008162}
Mike Stump11289f42009-09-09 15:08:12 +00008163
Douglas Gregora16548e2009-08-11 05:31:07 +00008164template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008165ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008166TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008167 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8168 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8169 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008170 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008171
John McCalldadc5752010-08-24 06:29:42 +00008172 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008173 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008174 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008175
Douglas Gregora16548e2009-08-11 05:31:07 +00008176 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008177 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008178 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008179 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008180
John McCall5d7aa7f2010-01-19 22:33:45 +00008181 // Note: the expression type doesn't necessarily match the
8182 // type-as-written, but that's okay, because it should always be
8183 // derivable from the initializer.
8184
John McCalle15bbff2010-01-18 19:35:47 +00008185 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008186 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008187 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008188}
Mike Stump11289f42009-09-09 15:08:12 +00008189
Douglas Gregora16548e2009-08-11 05:31:07 +00008190template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008191ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008192TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008193 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008194 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008195 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008196
Douglas Gregora16548e2009-08-11 05:31:07 +00008197 if (!getDerived().AlwaysRebuild() &&
8198 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008199 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008200
Douglas Gregora16548e2009-08-11 05:31:07 +00008201 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008202 SourceLocation FakeOperatorLoc =
8203 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008204 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008205 E->getAccessorLoc(),
8206 E->getAccessor());
8207}
Mike Stump11289f42009-09-09 15:08:12 +00008208
Douglas Gregora16548e2009-08-11 05:31:07 +00008209template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008210ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008211TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008212 if (InitListExpr *Syntactic = E->getSyntacticForm())
8213 E = Syntactic;
8214
Douglas Gregora16548e2009-08-11 05:31:07 +00008215 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008216
Benjamin Kramerf0623432012-08-23 22:51:59 +00008217 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008218 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008219 Inits, &InitChanged))
8220 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008221
Richard Smith520449d2015-02-05 06:15:50 +00008222 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8223 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8224 // in some cases. We can't reuse it in general, because the syntactic and
8225 // semantic forms are linked, and we can't know that semantic form will
8226 // match even if the syntactic form does.
8227 }
Mike Stump11289f42009-09-09 15:08:12 +00008228
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008229 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008230 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008231}
Mike Stump11289f42009-09-09 15:08:12 +00008232
Douglas Gregora16548e2009-08-11 05:31:07 +00008233template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008234ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008235TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008236 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008237
Douglas Gregorebe10102009-08-20 07:17:43 +00008238 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008239 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008240 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008241 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008242
Douglas Gregorebe10102009-08-20 07:17:43 +00008243 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008244 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008245 bool ExprChanged = false;
8246 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
8247 DEnd = E->designators_end();
8248 D != DEnd; ++D) {
8249 if (D->isFieldDesignator()) {
8250 Desig.AddDesignator(Designator::getField(D->getFieldName(),
8251 D->getDotLoc(),
8252 D->getFieldLoc()));
8253 continue;
8254 }
Mike Stump11289f42009-09-09 15:08:12 +00008255
Douglas Gregora16548e2009-08-11 05:31:07 +00008256 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00008257 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008258 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008259 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008260
8261 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008262 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008263
Douglas Gregora16548e2009-08-11 05:31:07 +00008264 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008265 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008266 continue;
8267 }
Mike Stump11289f42009-09-09 15:08:12 +00008268
Douglas Gregora16548e2009-08-11 05:31:07 +00008269 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008270 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00008271 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
8272 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008273 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008274
John McCalldadc5752010-08-24 06:29:42 +00008275 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008276 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008277 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008278
8279 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008280 End.get(),
8281 D->getLBracketLoc(),
8282 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008283
Douglas Gregora16548e2009-08-11 05:31:07 +00008284 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
8285 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00008286
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008287 ArrayExprs.push_back(Start.get());
8288 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008289 }
Mike Stump11289f42009-09-09 15:08:12 +00008290
Douglas Gregora16548e2009-08-11 05:31:07 +00008291 if (!getDerived().AlwaysRebuild() &&
8292 Init.get() == E->getInit() &&
8293 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008294 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008295
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008296 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008297 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008298 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008299}
Mike Stump11289f42009-09-09 15:08:12 +00008300
Yunzhong Gaocb779302015-06-10 00:27:52 +00008301// Seems that if TransformInitListExpr() only works on the syntactic form of an
8302// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8303template<typename Derived>
8304ExprResult
8305TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8306 DesignatedInitUpdateExpr *E) {
8307 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8308 "initializer");
8309 return ExprError();
8310}
8311
8312template<typename Derived>
8313ExprResult
8314TreeTransform<Derived>::TransformNoInitExpr(
8315 NoInitExpr *E) {
8316 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8317 return ExprError();
8318}
8319
Douglas Gregora16548e2009-08-11 05:31:07 +00008320template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008321ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008322TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008323 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008324 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008325
Douglas Gregor3da3c062009-10-28 00:29:27 +00008326 // FIXME: Will we ever have proper type location here? Will we actually
8327 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008328 QualType T = getDerived().TransformType(E->getType());
8329 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008330 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008331
Douglas Gregora16548e2009-08-11 05:31:07 +00008332 if (!getDerived().AlwaysRebuild() &&
8333 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008334 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008335
Douglas Gregora16548e2009-08-11 05:31:07 +00008336 return getDerived().RebuildImplicitValueInitExpr(T);
8337}
Mike Stump11289f42009-09-09 15:08:12 +00008338
Douglas Gregora16548e2009-08-11 05:31:07 +00008339template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008340ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008341TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008342 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8343 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008344 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008345
John McCalldadc5752010-08-24 06:29:42 +00008346 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008347 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008348 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008349
Douglas Gregora16548e2009-08-11 05:31:07 +00008350 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008351 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008352 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008353 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008354
John McCallb268a282010-08-23 23:25:46 +00008355 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008356 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008357}
8358
8359template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008360ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008361TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008362 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008363 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008364 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8365 &ArgumentChanged))
8366 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008367
Douglas Gregora16548e2009-08-11 05:31:07 +00008368 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008369 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008370 E->getRParenLoc());
8371}
Mike Stump11289f42009-09-09 15:08:12 +00008372
Douglas Gregora16548e2009-08-11 05:31:07 +00008373/// \brief Transform an address-of-label expression.
8374///
8375/// By default, the transformation of an address-of-label expression always
8376/// rebuilds the expression, so that the label identifier can be resolved to
8377/// the corresponding label statement by semantic analysis.
8378template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008379ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008380TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008381 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8382 E->getLabel());
8383 if (!LD)
8384 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008385
Douglas Gregora16548e2009-08-11 05:31:07 +00008386 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008387 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008388}
Mike Stump11289f42009-09-09 15:08:12 +00008389
8390template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008391ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008392TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008393 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008394 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008395 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008396 if (SubStmt.isInvalid()) {
8397 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008398 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008399 }
Mike Stump11289f42009-09-09 15:08:12 +00008400
Douglas Gregora16548e2009-08-11 05:31:07 +00008401 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008402 SubStmt.get() == E->getSubStmt()) {
8403 // Calling this an 'error' is unintuitive, but it does the right thing.
8404 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008405 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008406 }
Mike Stump11289f42009-09-09 15:08:12 +00008407
8408 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008409 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008410 E->getRParenLoc());
8411}
Mike Stump11289f42009-09-09 15:08:12 +00008412
Douglas Gregora16548e2009-08-11 05:31:07 +00008413template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008414ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008415TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008416 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008417 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008418 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008419
John McCalldadc5752010-08-24 06:29:42 +00008420 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008421 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008422 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008423
John McCalldadc5752010-08-24 06:29:42 +00008424 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008425 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008426 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008427
Douglas Gregora16548e2009-08-11 05:31:07 +00008428 if (!getDerived().AlwaysRebuild() &&
8429 Cond.get() == E->getCond() &&
8430 LHS.get() == E->getLHS() &&
8431 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008432 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008433
Douglas Gregora16548e2009-08-11 05:31:07 +00008434 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008435 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008436 E->getRParenLoc());
8437}
Mike Stump11289f42009-09-09 15:08:12 +00008438
Douglas Gregora16548e2009-08-11 05:31:07 +00008439template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008440ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008441TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008442 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008443}
8444
8445template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008446ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008447TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008448 switch (E->getOperator()) {
8449 case OO_New:
8450 case OO_Delete:
8451 case OO_Array_New:
8452 case OO_Array_Delete:
8453 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008454
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008455 case OO_Call: {
8456 // This is a call to an object's operator().
8457 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8458
8459 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008460 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008461 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008462 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008463
8464 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008465 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8466 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008467
8468 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008469 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008470 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008471 Args))
8472 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008473
John McCallb268a282010-08-23 23:25:46 +00008474 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008475 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008476 E->getLocEnd());
8477 }
8478
8479#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8480 case OO_##Name:
8481#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8482#include "clang/Basic/OperatorKinds.def"
8483 case OO_Subscript:
8484 // Handled below.
8485 break;
8486
8487 case OO_Conditional:
8488 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008489
8490 case OO_None:
8491 case NUM_OVERLOADED_OPERATORS:
8492 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008493 }
8494
John McCalldadc5752010-08-24 06:29:42 +00008495 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008496 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008497 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008498
Richard Smithdb2630f2012-10-21 03:28:35 +00008499 ExprResult First;
8500 if (E->getOperator() == OO_Amp)
8501 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8502 else
8503 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008504 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008505 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008506
John McCalldadc5752010-08-24 06:29:42 +00008507 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008508 if (E->getNumArgs() == 2) {
8509 Second = getDerived().TransformExpr(E->getArg(1));
8510 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008511 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008512 }
Mike Stump11289f42009-09-09 15:08:12 +00008513
Douglas Gregora16548e2009-08-11 05:31:07 +00008514 if (!getDerived().AlwaysRebuild() &&
8515 Callee.get() == E->getCallee() &&
8516 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008517 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008518 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008519
Lang Hames5de91cc2012-10-02 04:45:10 +00008520 Sema::FPContractStateRAII FPContractState(getSema());
8521 getSema().FPFeatures.fp_contract = E->isFPContractable();
8522
Douglas Gregora16548e2009-08-11 05:31:07 +00008523 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8524 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008525 Callee.get(),
8526 First.get(),
8527 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008528}
Mike Stump11289f42009-09-09 15:08:12 +00008529
Douglas Gregora16548e2009-08-11 05:31:07 +00008530template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008531ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008532TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8533 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008534}
Mike Stump11289f42009-09-09 15:08:12 +00008535
Douglas Gregora16548e2009-08-11 05:31:07 +00008536template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008537ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008538TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8539 // Transform the callee.
8540 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8541 if (Callee.isInvalid())
8542 return ExprError();
8543
8544 // Transform exec config.
8545 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8546 if (EC.isInvalid())
8547 return ExprError();
8548
8549 // Transform arguments.
8550 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008551 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008552 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008553 &ArgChanged))
8554 return ExprError();
8555
8556 if (!getDerived().AlwaysRebuild() &&
8557 Callee.get() == E->getCallee() &&
8558 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008559 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008560
8561 // FIXME: Wrong source location information for the '('.
8562 SourceLocation FakeLParenLoc
8563 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8564 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008565 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008566 E->getRParenLoc(), EC.get());
8567}
8568
8569template<typename Derived>
8570ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008571TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008572 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8573 if (!Type)
8574 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008575
John McCalldadc5752010-08-24 06:29:42 +00008576 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008577 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008578 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008579 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008580
Douglas Gregora16548e2009-08-11 05:31:07 +00008581 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008582 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008583 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008584 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008585 return getDerived().RebuildCXXNamedCastExpr(
8586 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8587 Type, E->getAngleBrackets().getEnd(),
8588 // FIXME. this should be '(' location
8589 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008590}
Mike Stump11289f42009-09-09 15:08:12 +00008591
Douglas Gregora16548e2009-08-11 05:31:07 +00008592template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008593ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008594TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8595 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008596}
Mike Stump11289f42009-09-09 15:08:12 +00008597
8598template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008599ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008600TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8601 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008602}
8603
Douglas Gregora16548e2009-08-11 05:31:07 +00008604template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008605ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008606TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008607 CXXReinterpretCastExpr *E) {
8608 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008609}
Mike Stump11289f42009-09-09 15:08:12 +00008610
Douglas Gregora16548e2009-08-11 05:31:07 +00008611template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008612ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008613TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8614 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008615}
Mike Stump11289f42009-09-09 15:08:12 +00008616
Douglas Gregora16548e2009-08-11 05:31:07 +00008617template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008618ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008619TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008620 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008621 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8622 if (!Type)
8623 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008624
John McCalldadc5752010-08-24 06:29:42 +00008625 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008626 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008627 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008628 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008629
Douglas Gregora16548e2009-08-11 05:31:07 +00008630 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008631 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008632 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008633 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008634
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008635 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008636 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008637 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008638 E->getRParenLoc());
8639}
Mike Stump11289f42009-09-09 15:08:12 +00008640
Douglas Gregora16548e2009-08-11 05:31:07 +00008641template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008642ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008643TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008644 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008645 TypeSourceInfo *TInfo
8646 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8647 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008648 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008649
Douglas Gregora16548e2009-08-11 05:31:07 +00008650 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008651 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008652 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008653
Douglas Gregor9da64192010-04-26 22:37:10 +00008654 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8655 E->getLocStart(),
8656 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008657 E->getLocEnd());
8658 }
Mike Stump11289f42009-09-09 15:08:12 +00008659
Eli Friedman456f0182012-01-20 01:26:23 +00008660 // We don't know whether the subexpression is potentially evaluated until
8661 // after we perform semantic analysis. We speculatively assume it is
8662 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008663 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008664 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8665 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008666
John McCalldadc5752010-08-24 06:29:42 +00008667 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008668 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008669 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008670
Douglas Gregora16548e2009-08-11 05:31:07 +00008671 if (!getDerived().AlwaysRebuild() &&
8672 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008673 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008674
Douglas Gregor9da64192010-04-26 22:37:10 +00008675 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8676 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008677 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008678 E->getLocEnd());
8679}
8680
8681template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008682ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008683TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8684 if (E->isTypeOperand()) {
8685 TypeSourceInfo *TInfo
8686 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8687 if (!TInfo)
8688 return ExprError();
8689
8690 if (!getDerived().AlwaysRebuild() &&
8691 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008692 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008693
Douglas Gregor69735112011-03-06 17:40:41 +00008694 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008695 E->getLocStart(),
8696 TInfo,
8697 E->getLocEnd());
8698 }
8699
Francois Pichet9f4f2072010-09-08 12:20:18 +00008700 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8701
8702 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8703 if (SubExpr.isInvalid())
8704 return ExprError();
8705
8706 if (!getDerived().AlwaysRebuild() &&
8707 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008708 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008709
8710 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8711 E->getLocStart(),
8712 SubExpr.get(),
8713 E->getLocEnd());
8714}
8715
8716template<typename Derived>
8717ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008718TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008719 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008720}
Mike Stump11289f42009-09-09 15:08:12 +00008721
Douglas Gregora16548e2009-08-11 05:31:07 +00008722template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008723ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008724TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008725 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008726 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008727}
Mike Stump11289f42009-09-09 15:08:12 +00008728
Douglas Gregora16548e2009-08-11 05:31:07 +00008729template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008730ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008731TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008732 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008733
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008734 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8735 // Make sure that we capture 'this'.
8736 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008737 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008738 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008739
Douglas Gregorb15af892010-01-07 23:12:05 +00008740 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008741}
Mike Stump11289f42009-09-09 15:08:12 +00008742
Douglas Gregora16548e2009-08-11 05:31:07 +00008743template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008744ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008745TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008746 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008747 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008748 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008749
Douglas Gregora16548e2009-08-11 05:31:07 +00008750 if (!getDerived().AlwaysRebuild() &&
8751 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008752 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008753
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008754 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8755 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008756}
Mike Stump11289f42009-09-09 15:08:12 +00008757
Douglas Gregora16548e2009-08-11 05:31:07 +00008758template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008759ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008760TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008761 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008762 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8763 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008764 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008765 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008766
Chandler Carruth794da4c2010-02-08 06:42:49 +00008767 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008768 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008769 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008770
Douglas Gregor033f6752009-12-23 23:03:06 +00008771 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008772}
Mike Stump11289f42009-09-09 15:08:12 +00008773
Douglas Gregora16548e2009-08-11 05:31:07 +00008774template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008775ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008776TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8777 FieldDecl *Field
8778 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8779 E->getField()));
8780 if (!Field)
8781 return ExprError();
8782
8783 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008784 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008785
8786 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8787}
8788
8789template<typename Derived>
8790ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008791TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8792 CXXScalarValueInitExpr *E) {
8793 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8794 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008795 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008796
Douglas Gregora16548e2009-08-11 05:31:07 +00008797 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008798 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008799 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008800
Chad Rosier1dcde962012-08-08 18:46:20 +00008801 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008802 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008803 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008804}
Mike Stump11289f42009-09-09 15:08:12 +00008805
Douglas Gregora16548e2009-08-11 05:31:07 +00008806template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008807ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008808TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008809 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008810 TypeSourceInfo *AllocTypeInfo
8811 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8812 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008813 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008814
Douglas Gregora16548e2009-08-11 05:31:07 +00008815 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008816 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008817 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008818 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008819
Douglas Gregora16548e2009-08-11 05:31:07 +00008820 // Transform the placement arguments (if any).
8821 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008822 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008823 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008824 E->getNumPlacementArgs(), true,
8825 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008826 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008827
Sebastian Redl6047f072012-02-16 12:22:20 +00008828 // Transform the initializer (if any).
8829 Expr *OldInit = E->getInitializer();
8830 ExprResult NewInit;
8831 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008832 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008833 if (NewInit.isInvalid())
8834 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008835
Sebastian Redl6047f072012-02-16 12:22:20 +00008836 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008837 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008838 if (E->getOperatorNew()) {
8839 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008840 getDerived().TransformDecl(E->getLocStart(),
8841 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008842 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008843 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008844 }
8845
Craig Topperc3ec1492014-05-26 06:22:03 +00008846 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008847 if (E->getOperatorDelete()) {
8848 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008849 getDerived().TransformDecl(E->getLocStart(),
8850 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008851 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008852 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008853 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008854
Douglas Gregora16548e2009-08-11 05:31:07 +00008855 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008856 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008857 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008858 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008859 OperatorNew == E->getOperatorNew() &&
8860 OperatorDelete == E->getOperatorDelete() &&
8861 !ArgumentChanged) {
8862 // Mark any declarations we need as referenced.
8863 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008864 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008865 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008866 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008867 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008868
Sebastian Redl6047f072012-02-16 12:22:20 +00008869 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008870 QualType ElementType
8871 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8872 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8873 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8874 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008875 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008876 }
8877 }
8878 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008879
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008880 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008881 }
Mike Stump11289f42009-09-09 15:08:12 +00008882
Douglas Gregor0744ef62010-09-07 21:49:58 +00008883 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008884 if (!ArraySize.get()) {
8885 // If no array size was specified, but the new expression was
8886 // instantiated with an array type (e.g., "new T" where T is
8887 // instantiated with "int[4]"), extract the outer bound from the
8888 // array type as our array size. We do this with constant and
8889 // dependently-sized array types.
8890 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8891 if (!ArrayT) {
8892 // Do nothing
8893 } else if (const ConstantArrayType *ConsArrayT
8894 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008895 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8896 SemaRef.Context.getSizeType(),
8897 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008898 AllocType = ConsArrayT->getElementType();
8899 } else if (const DependentSizedArrayType *DepArrayT
8900 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8901 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008902 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008903 AllocType = DepArrayT->getElementType();
8904 }
8905 }
8906 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008907
Douglas Gregora16548e2009-08-11 05:31:07 +00008908 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8909 E->isGlobalNew(),
8910 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008911 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008912 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008913 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008914 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008915 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008916 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008917 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008918 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008919}
Mike Stump11289f42009-09-09 15:08:12 +00008920
Douglas Gregora16548e2009-08-11 05:31:07 +00008921template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008922ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008923TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008924 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008925 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008926 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008927
Douglas Gregord2d9da02010-02-26 00:38:10 +00008928 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008929 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008930 if (E->getOperatorDelete()) {
8931 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008932 getDerived().TransformDecl(E->getLocStart(),
8933 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008934 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008935 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008936 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008937
Douglas Gregora16548e2009-08-11 05:31:07 +00008938 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008939 Operand.get() == E->getArgument() &&
8940 OperatorDelete == E->getOperatorDelete()) {
8941 // Mark any declarations we need as referenced.
8942 // FIXME: instantiation-specific.
8943 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008944 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008945
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008946 if (!E->getArgument()->isTypeDependent()) {
8947 QualType Destroyed = SemaRef.Context.getBaseElementType(
8948 E->getDestroyedType());
8949 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8950 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008951 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008952 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008953 }
8954 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008955
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008956 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008957 }
Mike Stump11289f42009-09-09 15:08:12 +00008958
Douglas Gregora16548e2009-08-11 05:31:07 +00008959 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8960 E->isGlobalDelete(),
8961 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008962 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008963}
Mike Stump11289f42009-09-09 15:08:12 +00008964
Douglas Gregora16548e2009-08-11 05:31:07 +00008965template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008966ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008967TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008968 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008969 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008970 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008971 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008972
John McCallba7bf592010-08-24 05:47:05 +00008973 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008974 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008975 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008976 E->getOperatorLoc(),
8977 E->isArrow()? tok::arrow : tok::period,
8978 ObjectTypePtr,
8979 MayBePseudoDestructor);
8980 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008981 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008982
John McCallba7bf592010-08-24 05:47:05 +00008983 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00008984 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
8985 if (QualifierLoc) {
8986 QualifierLoc
8987 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
8988 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00008989 return ExprError();
8990 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00008991 CXXScopeSpec SS;
8992 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00008993
Douglas Gregor678f90d2010-02-25 01:56:36 +00008994 PseudoDestructorTypeStorage Destroyed;
8995 if (E->getDestroyedTypeInfo()) {
8996 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00008997 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008998 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00008999 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009000 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009001 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009002 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009003 // We aren't likely to be able to resolve the identifier down to a type
9004 // now anyway, so just retain the identifier.
9005 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9006 E->getDestroyedTypeLoc());
9007 } else {
9008 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009009 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009010 *E->getDestroyedTypeIdentifier(),
9011 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009012 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009013 SS, ObjectTypePtr,
9014 false);
9015 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009016 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009017
Douglas Gregor678f90d2010-02-25 01:56:36 +00009018 Destroyed
9019 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9020 E->getDestroyedTypeLoc());
9021 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009022
Craig Topperc3ec1492014-05-26 06:22:03 +00009023 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009024 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009025 CXXScopeSpec EmptySS;
9026 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009027 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009028 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009029 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009030 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009031
John McCallb268a282010-08-23 23:25:46 +00009032 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009033 E->getOperatorLoc(),
9034 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009035 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009036 ScopeTypeInfo,
9037 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009038 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009039 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009040}
Mike Stump11289f42009-09-09 15:08:12 +00009041
Douglas Gregorad8a3362009-09-04 17:36:40 +00009042template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009043ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009044TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009045 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009046 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9047 Sema::LookupOrdinaryName);
9048
9049 // Transform all the decls.
9050 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9051 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009052 NamedDecl *InstD = static_cast<NamedDecl*>(
9053 getDerived().TransformDecl(Old->getNameLoc(),
9054 *I));
John McCall84d87672009-12-10 09:41:52 +00009055 if (!InstD) {
9056 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9057 // This can happen because of dependent hiding.
9058 if (isa<UsingShadowDecl>(*I))
9059 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009060 else {
9061 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009062 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009063 }
John McCall84d87672009-12-10 09:41:52 +00009064 }
John McCalle66edc12009-11-24 19:00:30 +00009065
9066 // Expand using declarations.
9067 if (isa<UsingDecl>(InstD)) {
9068 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009069 for (auto *I : UD->shadows())
9070 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009071 continue;
9072 }
9073
9074 R.addDecl(InstD);
9075 }
9076
9077 // Resolve a kind, but don't do any further analysis. If it's
9078 // ambiguous, the callee needs to deal with it.
9079 R.resolveKind();
9080
9081 // Rebuild the nested-name qualifier, if present.
9082 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009083 if (Old->getQualifierLoc()) {
9084 NestedNameSpecifierLoc QualifierLoc
9085 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9086 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009087 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009088
Douglas Gregor0da1d432011-02-28 20:01:57 +00009089 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009090 }
9091
Douglas Gregor9262f472010-04-27 18:19:34 +00009092 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009093 CXXRecordDecl *NamingClass
9094 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9095 Old->getNameLoc(),
9096 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009097 if (!NamingClass) {
9098 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009099 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009100 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009101
Douglas Gregorda7be082010-04-27 16:10:10 +00009102 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009103 }
9104
Abramo Bagnara7945c982012-01-27 09:46:47 +00009105 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9106
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009107 // If we have neither explicit template arguments, nor the template keyword,
9108 // it's a normal declaration name.
9109 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid())
John McCalle66edc12009-11-24 19:00:30 +00009110 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
9111
9112 // If we have template arguments, rebuild them, then rebuild the
9113 // templateid expression.
9114 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009115 if (Old->hasExplicitTemplateArgs() &&
9116 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009117 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009118 TransArgs)) {
9119 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009120 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009121 }
John McCalle66edc12009-11-24 19:00:30 +00009122
Abramo Bagnara7945c982012-01-27 09:46:47 +00009123 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009124 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009125}
Mike Stump11289f42009-09-09 15:08:12 +00009126
Douglas Gregora16548e2009-08-11 05:31:07 +00009127template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009128ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009129TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9130 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009131 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009132 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9133 TypeSourceInfo *From = E->getArg(I);
9134 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009135 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009136 TypeLocBuilder TLB;
9137 TLB.reserve(FromTL.getFullDataSize());
9138 QualType To = getDerived().TransformType(TLB, FromTL);
9139 if (To.isNull())
9140 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009141
Douglas Gregor29c42f22012-02-24 07:38:34 +00009142 if (To == From->getType())
9143 Args.push_back(From);
9144 else {
9145 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9146 ArgChanged = true;
9147 }
9148 continue;
9149 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009150
Douglas Gregor29c42f22012-02-24 07:38:34 +00009151 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009152
Douglas Gregor29c42f22012-02-24 07:38:34 +00009153 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009154 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009155 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9156 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9157 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009158
Douglas Gregor29c42f22012-02-24 07:38:34 +00009159 // Determine whether the set of unexpanded parameter packs can and should
9160 // be expanded.
9161 bool Expand = true;
9162 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009163 Optional<unsigned> OrigNumExpansions =
9164 ExpansionTL.getTypePtr()->getNumExpansions();
9165 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009166 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9167 PatternTL.getSourceRange(),
9168 Unexpanded,
9169 Expand, RetainExpansion,
9170 NumExpansions))
9171 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009172
Douglas Gregor29c42f22012-02-24 07:38:34 +00009173 if (!Expand) {
9174 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009175 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009176 // expansion.
9177 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009178
Douglas Gregor29c42f22012-02-24 07:38:34 +00009179 TypeLocBuilder TLB;
9180 TLB.reserve(From->getTypeLoc().getFullDataSize());
9181
9182 QualType To = getDerived().TransformType(TLB, PatternTL);
9183 if (To.isNull())
9184 return ExprError();
9185
Chad Rosier1dcde962012-08-08 18:46:20 +00009186 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009187 PatternTL.getSourceRange(),
9188 ExpansionTL.getEllipsisLoc(),
9189 NumExpansions);
9190 if (To.isNull())
9191 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009192
Douglas Gregor29c42f22012-02-24 07:38:34 +00009193 PackExpansionTypeLoc ToExpansionTL
9194 = TLB.push<PackExpansionTypeLoc>(To);
9195 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9196 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9197 continue;
9198 }
9199
9200 // Expand the pack expansion by substituting for each argument in the
9201 // pack(s).
9202 for (unsigned I = 0; I != *NumExpansions; ++I) {
9203 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9204 TypeLocBuilder TLB;
9205 TLB.reserve(PatternTL.getFullDataSize());
9206 QualType To = getDerived().TransformType(TLB, PatternTL);
9207 if (To.isNull())
9208 return ExprError();
9209
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009210 if (To->containsUnexpandedParameterPack()) {
9211 To = getDerived().RebuildPackExpansionType(To,
9212 PatternTL.getSourceRange(),
9213 ExpansionTL.getEllipsisLoc(),
9214 NumExpansions);
9215 if (To.isNull())
9216 return ExprError();
9217
9218 PackExpansionTypeLoc ToExpansionTL
9219 = TLB.push<PackExpansionTypeLoc>(To);
9220 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9221 }
9222
Douglas Gregor29c42f22012-02-24 07:38:34 +00009223 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9224 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009225
Douglas Gregor29c42f22012-02-24 07:38:34 +00009226 if (!RetainExpansion)
9227 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009228
Douglas Gregor29c42f22012-02-24 07:38:34 +00009229 // If we're supposed to retain a pack expansion, do so by temporarily
9230 // forgetting the partially-substituted parameter pack.
9231 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9232
9233 TypeLocBuilder TLB;
9234 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009235
Douglas Gregor29c42f22012-02-24 07:38:34 +00009236 QualType To = getDerived().TransformType(TLB, PatternTL);
9237 if (To.isNull())
9238 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009239
9240 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009241 PatternTL.getSourceRange(),
9242 ExpansionTL.getEllipsisLoc(),
9243 NumExpansions);
9244 if (To.isNull())
9245 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009246
Douglas Gregor29c42f22012-02-24 07:38:34 +00009247 PackExpansionTypeLoc ToExpansionTL
9248 = TLB.push<PackExpansionTypeLoc>(To);
9249 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9250 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9251 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009252
Douglas Gregor29c42f22012-02-24 07:38:34 +00009253 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009254 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009255
9256 return getDerived().RebuildTypeTrait(E->getTrait(),
9257 E->getLocStart(),
9258 Args,
9259 E->getLocEnd());
9260}
9261
9262template<typename Derived>
9263ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009264TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9265 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9266 if (!T)
9267 return ExprError();
9268
9269 if (!getDerived().AlwaysRebuild() &&
9270 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009271 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009272
9273 ExprResult SubExpr;
9274 {
9275 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9276 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9277 if (SubExpr.isInvalid())
9278 return ExprError();
9279
9280 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009281 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009282 }
9283
9284 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9285 E->getLocStart(),
9286 T,
9287 SubExpr.get(),
9288 E->getLocEnd());
9289}
9290
9291template<typename Derived>
9292ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009293TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9294 ExprResult SubExpr;
9295 {
9296 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9297 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9298 if (SubExpr.isInvalid())
9299 return ExprError();
9300
9301 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009302 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009303 }
9304
9305 return getDerived().RebuildExpressionTrait(
9306 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9307}
9308
Reid Kleckner32506ed2014-06-12 23:03:48 +00009309template <typename Derived>
9310ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9311 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9312 TypeSourceInfo **RecoveryTSI) {
9313 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9314 DRE, AddrTaken, RecoveryTSI);
9315
9316 // Propagate both errors and recovered types, which return ExprEmpty.
9317 if (!NewDRE.isUsable())
9318 return NewDRE;
9319
9320 // We got an expr, wrap it up in parens.
9321 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9322 return PE;
9323 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9324 PE->getRParen());
9325}
9326
9327template <typename Derived>
9328ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9329 DependentScopeDeclRefExpr *E) {
9330 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9331 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009332}
9333
9334template<typename Derived>
9335ExprResult
9336TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9337 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009338 bool IsAddressOfOperand,
9339 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009340 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009341 NestedNameSpecifierLoc QualifierLoc
9342 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9343 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009344 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009345 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009346
John McCall31f82722010-11-12 08:19:04 +00009347 // TODO: If this is a conversion-function-id, verify that the
9348 // destination type name (if present) resolves the same way after
9349 // instantiation as it did in the local scope.
9350
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009351 DeclarationNameInfo NameInfo
9352 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9353 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009354 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009355
John McCalle66edc12009-11-24 19:00:30 +00009356 if (!E->hasExplicitTemplateArgs()) {
9357 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009358 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009359 // Note: it is sufficient to compare the Name component of NameInfo:
9360 // if name has not changed, DNLoc has not changed either.
9361 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009362 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009363
Reid Kleckner32506ed2014-06-12 23:03:48 +00009364 return getDerived().RebuildDependentScopeDeclRefExpr(
9365 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9366 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009367 }
John McCall6b51f282009-11-23 01:53:49 +00009368
9369 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009370 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9371 E->getNumTemplateArgs(),
9372 TransArgs))
9373 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009374
Reid Kleckner32506ed2014-06-12 23:03:48 +00009375 return getDerived().RebuildDependentScopeDeclRefExpr(
9376 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9377 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009378}
9379
9380template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009381ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009382TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009383 // CXXConstructExprs other than for list-initialization and
9384 // CXXTemporaryObjectExpr are always implicit, so when we have
9385 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009386 if ((E->getNumArgs() == 1 ||
9387 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009388 (!getDerived().DropCallArgument(E->getArg(0))) &&
9389 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009390 return getDerived().TransformExpr(E->getArg(0));
9391
Douglas Gregora16548e2009-08-11 05:31:07 +00009392 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9393
9394 QualType T = getDerived().TransformType(E->getType());
9395 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009396 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009397
9398 CXXConstructorDecl *Constructor
9399 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009400 getDerived().TransformDecl(E->getLocStart(),
9401 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009402 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009403 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009404
Douglas Gregora16548e2009-08-11 05:31:07 +00009405 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009406 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009407 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009408 &ArgumentChanged))
9409 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009410
Douglas Gregora16548e2009-08-11 05:31:07 +00009411 if (!getDerived().AlwaysRebuild() &&
9412 T == E->getType() &&
9413 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009414 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009415 // Mark the constructor as referenced.
9416 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009417 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009418 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009419 }
Mike Stump11289f42009-09-09 15:08:12 +00009420
Douglas Gregordb121ba2009-12-14 16:27:04 +00009421 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9422 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009423 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009424 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009425 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009426 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009427 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009428 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009429 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009430}
Mike Stump11289f42009-09-09 15:08:12 +00009431
Douglas Gregora16548e2009-08-11 05:31:07 +00009432/// \brief Transform a C++ temporary-binding expression.
9433///
Douglas Gregor363b1512009-12-24 18:51:59 +00009434/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9435/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009436template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009437ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009438TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009439 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009440}
Mike Stump11289f42009-09-09 15:08:12 +00009441
John McCall5d413782010-12-06 08:20:24 +00009442/// \brief Transform a C++ expression that contains cleanups that should
9443/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009444///
John McCall5d413782010-12-06 08:20:24 +00009445/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009446/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009447template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009448ExprResult
John McCall5d413782010-12-06 08:20:24 +00009449TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009450 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009451}
Mike Stump11289f42009-09-09 15:08:12 +00009452
Douglas Gregora16548e2009-08-11 05:31:07 +00009453template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009454ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009455TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009456 CXXTemporaryObjectExpr *E) {
9457 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9458 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009459 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009460
Douglas Gregora16548e2009-08-11 05:31:07 +00009461 CXXConstructorDecl *Constructor
9462 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009463 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009464 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009465 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009466 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009467
Douglas Gregora16548e2009-08-11 05:31:07 +00009468 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009469 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009470 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009471 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009472 &ArgumentChanged))
9473 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009474
Douglas Gregora16548e2009-08-11 05:31:07 +00009475 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009476 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009477 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009478 !ArgumentChanged) {
9479 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009480 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009481 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009482 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009483
Richard Smithd59b8322012-12-19 01:39:02 +00009484 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009485 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9486 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009487 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009488 E->getLocEnd());
9489}
Mike Stump11289f42009-09-09 15:08:12 +00009490
Douglas Gregora16548e2009-08-11 05:31:07 +00009491template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009492ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009493TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009494 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009495 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009496 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009497 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9498 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009499 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009500 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009501 CEnd = E->capture_end();
9502 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009503 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009504 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009505 EnterExpressionEvaluationContext EEEC(getSema(),
9506 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009507 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9508 C->getCapturedVar()->getInit(),
9509 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009510
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009511 if (NewExprInitResult.isInvalid())
9512 return ExprError();
9513 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009514
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009515 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009516 QualType NewInitCaptureType =
9517 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
9518 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009519 NewExprInit);
9520 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009521 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9522 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009523 }
9524
Faisal Vali2cba1332013-10-23 06:44:28 +00009525 // Transform the template parameters, and add them to the current
9526 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +00009527 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +00009528 E->getTemplateParameterList());
9529
Richard Smith01014ce2014-11-20 23:53:14 +00009530 // Transform the type of the original lambda's call operator.
9531 // The transformation MUST be done in the CurrentInstantiationScope since
9532 // it introduces a mapping of the original to the newly created
9533 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009534 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009535 {
9536 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9537 FunctionProtoTypeLoc OldCallOpFPTL =
9538 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009539
9540 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009541 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009542 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009543 QualType NewCallOpType = TransformFunctionProtoType(
9544 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009545 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9546 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9547 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009548 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009549 if (NewCallOpType.isNull())
9550 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009551 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9552 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009553 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009554
Richard Smithc38498f2015-04-27 21:27:54 +00009555 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9556 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9557 LSI->GLTemplateParameterList = TPL;
9558
Eli Friedmand564afb2012-09-19 01:18:11 +00009559 // Create the local class that will describe the lambda.
9560 CXXRecordDecl *Class
9561 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009562 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009563 /*KnownDependent=*/false,
9564 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009565 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9566
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009567 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009568 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9569 Class, E->getIntroducerRange(), NewCallOpTSI,
9570 E->getCallOperator()->getLocEnd(),
9571 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009572 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009573
Faisal Vali2cba1332013-10-23 06:44:28 +00009574 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +00009575 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +00009576
Douglas Gregorb4328232012-02-14 00:00:48 +00009577 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +00009578 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009579 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009580
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009581 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +00009582 getSema().buildLambdaScope(LSI, NewCallOperator,
9583 E->getIntroducerRange(),
9584 E->getCaptureDefault(),
9585 E->getCaptureDefaultLoc(),
9586 E->hasExplicitParameters(),
9587 E->hasExplicitResultType(),
9588 E->isMutable());
9589
9590 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009591
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009592 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009593 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009594 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009595 CEnd = E->capture_end();
9596 C != CEnd; ++C) {
9597 // When we hit the first implicit capture, tell Sema that we've finished
9598 // the list of explicit captures.
9599 if (!FinishedExplicitCaptures && C->isImplicit()) {
9600 getSema().finishLambdaExplicitCaptures(LSI);
9601 FinishedExplicitCaptures = true;
9602 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009603
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009604 // Capturing 'this' is trivial.
9605 if (C->capturesThis()) {
9606 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9607 continue;
9608 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009609 // Captured expression will be recaptured during captured variables
9610 // rebuilding.
9611 if (C->capturesVLAType())
9612 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009613
Richard Smithba71c082013-05-16 06:20:58 +00009614 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +00009615 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009616 InitCaptureInfoTy InitExprTypePair =
9617 InitCaptureExprsAndTypes[C - E->capture_begin()];
9618 ExprResult Init = InitExprTypePair.first;
9619 QualType InitQualType = InitExprTypePair.second;
9620 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009621 Invalid = true;
9622 continue;
9623 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009624 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009625 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9626 OldVD->getLocation(), InitExprTypePair.second,
9627 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009628 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009629 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009630 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009631 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009632 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009633 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009634 continue;
9635 }
9636
9637 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9638
Douglas Gregor3e308b12012-02-14 19:27:52 +00009639 // Determine the capture kind for Sema.
9640 Sema::TryCaptureKind Kind
9641 = C->isImplicit()? Sema::TryCapture_Implicit
9642 : C->getCaptureKind() == LCK_ByCopy
9643 ? Sema::TryCapture_ExplicitByVal
9644 : Sema::TryCapture_ExplicitByRef;
9645 SourceLocation EllipsisLoc;
9646 if (C->isPackExpansion()) {
9647 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9648 bool ShouldExpand = false;
9649 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009650 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009651 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9652 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009653 Unexpanded,
9654 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009655 NumExpansions)) {
9656 Invalid = true;
9657 continue;
9658 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009659
Douglas Gregor3e308b12012-02-14 19:27:52 +00009660 if (ShouldExpand) {
9661 // The transform has determined that we should perform an expansion;
9662 // transform and capture each of the arguments.
9663 // expansion of the pattern. Do so.
9664 VarDecl *Pack = C->getCapturedVar();
9665 for (unsigned I = 0; I != *NumExpansions; ++I) {
9666 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9667 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009668 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009669 Pack));
9670 if (!CapturedVar) {
9671 Invalid = true;
9672 continue;
9673 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009674
Douglas Gregor3e308b12012-02-14 19:27:52 +00009675 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009676 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9677 }
Richard Smith9467be42014-06-06 17:33:35 +00009678
9679 // FIXME: Retain a pack expansion if RetainExpansion is true.
9680
Douglas Gregor3e308b12012-02-14 19:27:52 +00009681 continue;
9682 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009683
Douglas Gregor3e308b12012-02-14 19:27:52 +00009684 EllipsisLoc = C->getEllipsisLoc();
9685 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009686
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009687 // Transform the captured variable.
9688 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009689 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009690 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009691 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009692 Invalid = true;
9693 continue;
9694 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009695
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009696 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +00009697 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
9698 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009699 }
9700 if (!FinishedExplicitCaptures)
9701 getSema().finishLambdaExplicitCaptures(LSI);
9702
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009703 // Enter a new evaluation context to insulate the lambda from any
9704 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009705 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009706
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009707 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +00009708 StmtResult Body =
9709 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
9710
9711 // ActOnLambda* will pop the function scope for us.
9712 FuncScopeCleanup.disable();
9713
Douglas Gregorb4328232012-02-14 00:00:48 +00009714 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +00009715 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +00009716 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009717 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009718 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009719 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009720
Richard Smithc38498f2015-04-27 21:27:54 +00009721 // Copy the LSI before ActOnFinishFunctionBody removes it.
9722 // FIXME: This is dumb. Store the lambda information somewhere that outlives
9723 // the call operator.
9724 auto LSICopy = *LSI;
9725 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
9726 /*IsInstantiation*/ true);
9727 SavedContext.pop();
9728
9729 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
9730 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +00009731}
9732
9733template<typename Derived>
9734ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009735TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009736 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009737 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9738 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009739 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009740
Douglas Gregora16548e2009-08-11 05:31:07 +00009741 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009742 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009743 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009744 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009745 &ArgumentChanged))
9746 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009747
Douglas Gregora16548e2009-08-11 05:31:07 +00009748 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009749 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009750 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009751 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009752
Douglas Gregora16548e2009-08-11 05:31:07 +00009753 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009754 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009755 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009756 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009757 E->getRParenLoc());
9758}
Mike Stump11289f42009-09-09 15:08:12 +00009759
Douglas Gregora16548e2009-08-11 05:31:07 +00009760template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009761ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009762TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009763 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009764 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009765 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009766 Expr *OldBase;
9767 QualType BaseType;
9768 QualType ObjectType;
9769 if (!E->isImplicitAccess()) {
9770 OldBase = E->getBase();
9771 Base = getDerived().TransformExpr(OldBase);
9772 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009773 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009774
John McCall2d74de92009-12-01 22:10:20 +00009775 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009776 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009777 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009778 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009779 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009780 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009781 ObjectTy,
9782 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009783 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009784 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009785
John McCallba7bf592010-08-24 05:47:05 +00009786 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009787 BaseType = ((Expr*) Base.get())->getType();
9788 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009789 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009790 BaseType = getDerived().TransformType(E->getBaseType());
9791 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9792 }
Mike Stump11289f42009-09-09 15:08:12 +00009793
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009794 // Transform the first part of the nested-name-specifier that qualifies
9795 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009796 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009797 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009798 E->getFirstQualifierFoundInScope(),
9799 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009800
Douglas Gregore16af532011-02-28 18:50:33 +00009801 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009802 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009803 QualifierLoc
9804 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9805 ObjectType,
9806 FirstQualifierInScope);
9807 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009808 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009809 }
Mike Stump11289f42009-09-09 15:08:12 +00009810
Abramo Bagnara7945c982012-01-27 09:46:47 +00009811 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9812
John McCall31f82722010-11-12 08:19:04 +00009813 // TODO: If this is a conversion-function-id, verify that the
9814 // destination type name (if present) resolves the same way after
9815 // instantiation as it did in the local scope.
9816
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009817 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009818 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009819 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009820 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009821
John McCall2d74de92009-12-01 22:10:20 +00009822 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009823 // This is a reference to a member without an explicitly-specified
9824 // template argument list. Optimize for this common case.
9825 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009826 Base.get() == OldBase &&
9827 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009828 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009829 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009830 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009831 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009832
John McCallb268a282010-08-23 23:25:46 +00009833 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009834 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009835 E->isArrow(),
9836 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009837 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009838 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009839 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009840 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009841 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009842 }
9843
John McCall6b51f282009-11-23 01:53:49 +00009844 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009845 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9846 E->getNumTemplateArgs(),
9847 TransArgs))
9848 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009849
John McCallb268a282010-08-23 23:25:46 +00009850 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009851 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009852 E->isArrow(),
9853 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009854 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009855 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009856 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009857 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009858 &TransArgs);
9859}
9860
9861template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009862ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009863TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009864 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009865 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009866 QualType BaseType;
9867 if (!Old->isImplicitAccess()) {
9868 Base = getDerived().TransformExpr(Old->getBase());
9869 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009870 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009871 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009872 Old->isArrow());
9873 if (Base.isInvalid())
9874 return ExprError();
9875 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009876 } else {
9877 BaseType = getDerived().TransformType(Old->getBaseType());
9878 }
John McCall10eae182009-11-30 22:42:35 +00009879
Douglas Gregor0da1d432011-02-28 20:01:57 +00009880 NestedNameSpecifierLoc QualifierLoc;
9881 if (Old->getQualifierLoc()) {
9882 QualifierLoc
9883 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9884 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009885 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009886 }
9887
Abramo Bagnara7945c982012-01-27 09:46:47 +00009888 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9889
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009890 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009891 Sema::LookupOrdinaryName);
9892
9893 // Transform all the decls.
9894 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9895 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009896 NamedDecl *InstD = static_cast<NamedDecl*>(
9897 getDerived().TransformDecl(Old->getMemberLoc(),
9898 *I));
John McCall84d87672009-12-10 09:41:52 +00009899 if (!InstD) {
9900 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9901 // This can happen because of dependent hiding.
9902 if (isa<UsingShadowDecl>(*I))
9903 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009904 else {
9905 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009906 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009907 }
John McCall84d87672009-12-10 09:41:52 +00009908 }
John McCall10eae182009-11-30 22:42:35 +00009909
9910 // Expand using declarations.
9911 if (isa<UsingDecl>(InstD)) {
9912 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009913 for (auto *I : UD->shadows())
9914 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009915 continue;
9916 }
9917
9918 R.addDecl(InstD);
9919 }
9920
9921 R.resolveKind();
9922
Douglas Gregor9262f472010-04-27 18:19:34 +00009923 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009924 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009925 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009926 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009927 Old->getMemberLoc(),
9928 Old->getNamingClass()));
9929 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009930 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009931
Douglas Gregorda7be082010-04-27 16:10:10 +00009932 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009933 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009934
John McCall10eae182009-11-30 22:42:35 +00009935 TemplateArgumentListInfo TransArgs;
9936 if (Old->hasExplicitTemplateArgs()) {
9937 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9938 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009939 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9940 Old->getNumTemplateArgs(),
9941 TransArgs))
9942 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009943 }
John McCall38836f02010-01-15 08:34:02 +00009944
9945 // FIXME: to do this check properly, we will need to preserve the
9946 // first-qualifier-in-scope here, just in case we had a dependent
9947 // base (and therefore couldn't do the check) and a
9948 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009949 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009950
John McCallb268a282010-08-23 23:25:46 +00009951 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009952 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009953 Old->getOperatorLoc(),
9954 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009955 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009956 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009957 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009958 R,
9959 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009960 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009961}
9962
9963template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009964ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009965TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009966 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009967 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9968 if (SubExpr.isInvalid())
9969 return ExprError();
9970
9971 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009972 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009973
9974 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
9975}
9976
9977template<typename Derived>
9978ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009979TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009980 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
9981 if (Pattern.isInvalid())
9982 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009983
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009984 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009985 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +00009986
Douglas Gregorb8840002011-01-14 21:20:45 +00009987 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
9988 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +00009989}
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009990
9991template<typename Derived>
9992ExprResult
9993TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
9994 // If E is not value-dependent, then nothing will change when we transform it.
9995 // Note: This is an instantiation-centric view.
9996 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009997 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +00009998
9999 // Note: None of the implementations of TryExpandParameterPacks can ever
10000 // produce a diagnostic when given only a single unexpanded parameter pack,
Chad Rosier1dcde962012-08-08 18:46:20 +000010001 // so
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010002 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10003 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +000010004 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010005 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +000010006 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
David Blaikieb9c168a2011-09-22 02:34:54 +000010007 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +000010008 ShouldExpand, RetainExpansion,
10009 NumExpansions))
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010010 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010011
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010012 if (RetainExpansion)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010013 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010014
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010015 NamedDecl *Pack = E->getPack();
10016 if (!ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010017 Pack = cast_or_null<NamedDecl>(getDerived().TransformDecl(E->getPackLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010018 Pack));
10019 if (!Pack)
10020 return ExprError();
10021 }
10022
Chad Rosier1dcde962012-08-08 18:46:20 +000010023
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010024 // We now know the length of the parameter pack, so build a new expression
10025 // that stores that length.
Chad Rosier1dcde962012-08-08 18:46:20 +000010026 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10027 E->getPackLoc(), E->getRParenLoc(),
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010028 NumExpansions);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010029}
10030
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010031template<typename Derived>
10032ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010033TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10034 SubstNonTypeTemplateParmPackExpr *E) {
10035 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010036 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010037}
10038
10039template<typename Derived>
10040ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010041TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10042 SubstNonTypeTemplateParmExpr *E) {
10043 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010044 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010045}
10046
10047template<typename Derived>
10048ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010049TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10050 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010051 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010052}
10053
10054template<typename Derived>
10055ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010056TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10057 MaterializeTemporaryExpr *E) {
10058 return getDerived().TransformExpr(E->GetTemporaryExpr());
10059}
Chad Rosier1dcde962012-08-08 18:46:20 +000010060
Douglas Gregorfe314812011-06-21 17:03:29 +000010061template<typename Derived>
10062ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010063TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10064 Expr *Pattern = E->getPattern();
10065
10066 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10067 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10068 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10069
10070 // Determine whether the set of unexpanded parameter packs can and should
10071 // be expanded.
10072 bool Expand = true;
10073 bool RetainExpansion = false;
10074 Optional<unsigned> NumExpansions;
10075 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10076 Pattern->getSourceRange(),
10077 Unexpanded,
10078 Expand, RetainExpansion,
10079 NumExpansions))
10080 return true;
10081
10082 if (!Expand) {
10083 // Do not expand any packs here, just transform and rebuild a fold
10084 // expression.
10085 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10086
10087 ExprResult LHS =
10088 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10089 if (LHS.isInvalid())
10090 return true;
10091
10092 ExprResult RHS =
10093 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10094 if (RHS.isInvalid())
10095 return true;
10096
10097 if (!getDerived().AlwaysRebuild() &&
10098 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10099 return E;
10100
10101 return getDerived().RebuildCXXFoldExpr(
10102 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10103 RHS.get(), E->getLocEnd());
10104 }
10105
10106 // The transform has determined that we should perform an elementwise
10107 // expansion of the pattern. Do so.
10108 ExprResult Result = getDerived().TransformExpr(E->getInit());
10109 if (Result.isInvalid())
10110 return true;
10111 bool LeftFold = E->isLeftFold();
10112
10113 // If we're retaining an expansion for a right fold, it is the innermost
10114 // component and takes the init (if any).
10115 if (!LeftFold && RetainExpansion) {
10116 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10117
10118 ExprResult Out = getDerived().TransformExpr(Pattern);
10119 if (Out.isInvalid())
10120 return true;
10121
10122 Result = getDerived().RebuildCXXFoldExpr(
10123 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10124 Result.get(), E->getLocEnd());
10125 if (Result.isInvalid())
10126 return true;
10127 }
10128
10129 for (unsigned I = 0; I != *NumExpansions; ++I) {
10130 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10131 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10132 ExprResult Out = getDerived().TransformExpr(Pattern);
10133 if (Out.isInvalid())
10134 return true;
10135
10136 if (Out.get()->containsUnexpandedParameterPack()) {
10137 // We still have a pack; retain a pack expansion for this slice.
10138 Result = getDerived().RebuildCXXFoldExpr(
10139 E->getLocStart(),
10140 LeftFold ? Result.get() : Out.get(),
10141 E->getOperator(), E->getEllipsisLoc(),
10142 LeftFold ? Out.get() : Result.get(),
10143 E->getLocEnd());
10144 } else if (Result.isUsable()) {
10145 // We've got down to a single element; build a binary operator.
10146 Result = getDerived().RebuildBinaryOperator(
10147 E->getEllipsisLoc(), E->getOperator(),
10148 LeftFold ? Result.get() : Out.get(),
10149 LeftFold ? Out.get() : Result.get());
10150 } else
10151 Result = Out;
10152
10153 if (Result.isInvalid())
10154 return true;
10155 }
10156
10157 // If we're retaining an expansion for a left fold, it is the outermost
10158 // component and takes the complete expansion so far as its init (if any).
10159 if (LeftFold && RetainExpansion) {
10160 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10161
10162 ExprResult Out = getDerived().TransformExpr(Pattern);
10163 if (Out.isInvalid())
10164 return true;
10165
10166 Result = getDerived().RebuildCXXFoldExpr(
10167 E->getLocStart(), Result.get(),
10168 E->getOperator(), E->getEllipsisLoc(),
10169 Out.get(), E->getLocEnd());
10170 if (Result.isInvalid())
10171 return true;
10172 }
10173
10174 // If we had no init and an empty pack, and we're not retaining an expansion,
10175 // then produce a fallback value or error.
10176 if (Result.isUnset())
10177 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10178 E->getOperator());
10179
10180 return Result;
10181}
10182
10183template<typename Derived>
10184ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010185TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10186 CXXStdInitializerListExpr *E) {
10187 return getDerived().TransformExpr(E->getSubExpr());
10188}
10189
10190template<typename Derived>
10191ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010192TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010193 return SemaRef.MaybeBindToTemporary(E);
10194}
10195
10196template<typename Derived>
10197ExprResult
10198TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010199 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010200}
10201
10202template<typename Derived>
10203ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010204TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10205 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10206 if (SubExpr.isInvalid())
10207 return ExprError();
10208
10209 if (!getDerived().AlwaysRebuild() &&
10210 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010211 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010212
10213 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010214}
10215
10216template<typename Derived>
10217ExprResult
10218TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10219 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010220 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010221 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010222 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010223 /*IsCall=*/false, Elements, &ArgChanged))
10224 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010225
Ted Kremeneke65b0862012-03-06 20:05:56 +000010226 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10227 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010228
Ted Kremeneke65b0862012-03-06 20:05:56 +000010229 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10230 Elements.data(),
10231 Elements.size());
10232}
10233
10234template<typename Derived>
10235ExprResult
10236TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010237 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010238 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010239 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010240 bool ArgChanged = false;
10241 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10242 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010243
Ted Kremeneke65b0862012-03-06 20:05:56 +000010244 if (OrigElement.isPackExpansion()) {
10245 // This key/value element is a pack expansion.
10246 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10247 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10248 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10249 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10250
10251 // Determine whether the set of unexpanded parameter packs can
10252 // and should be expanded.
10253 bool Expand = true;
10254 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010255 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10256 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010257 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10258 OrigElement.Value->getLocEnd());
10259 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10260 PatternRange,
10261 Unexpanded,
10262 Expand, RetainExpansion,
10263 NumExpansions))
10264 return ExprError();
10265
10266 if (!Expand) {
10267 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010268 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010269 // expansion.
10270 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10271 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10272 if (Key.isInvalid())
10273 return ExprError();
10274
10275 if (Key.get() != OrigElement.Key)
10276 ArgChanged = true;
10277
10278 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10279 if (Value.isInvalid())
10280 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010281
Ted Kremeneke65b0862012-03-06 20:05:56 +000010282 if (Value.get() != OrigElement.Value)
10283 ArgChanged = true;
10284
Chad Rosier1dcde962012-08-08 18:46:20 +000010285 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010286 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10287 };
10288 Elements.push_back(Expansion);
10289 continue;
10290 }
10291
10292 // Record right away that the argument was changed. This needs
10293 // to happen even if the array expands to nothing.
10294 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010295
Ted Kremeneke65b0862012-03-06 20:05:56 +000010296 // The transform has determined that we should perform an elementwise
10297 // expansion of the pattern. Do so.
10298 for (unsigned I = 0; I != *NumExpansions; ++I) {
10299 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10300 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10301 if (Key.isInvalid())
10302 return ExprError();
10303
10304 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10305 if (Value.isInvalid())
10306 return ExprError();
10307
Chad Rosier1dcde962012-08-08 18:46:20 +000010308 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010309 Key.get(), Value.get(), SourceLocation(), NumExpansions
10310 };
10311
10312 // If any unexpanded parameter packs remain, we still have a
10313 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010314 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010315 if (Key.get()->containsUnexpandedParameterPack() ||
10316 Value.get()->containsUnexpandedParameterPack())
10317 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010318
Ted Kremeneke65b0862012-03-06 20:05:56 +000010319 Elements.push_back(Element);
10320 }
10321
Richard Smith9467be42014-06-06 17:33:35 +000010322 // FIXME: Retain a pack expansion if RetainExpansion is true.
10323
Ted Kremeneke65b0862012-03-06 20:05:56 +000010324 // We've finished with this pack expansion.
10325 continue;
10326 }
10327
10328 // Transform and check key.
10329 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10330 if (Key.isInvalid())
10331 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010332
Ted Kremeneke65b0862012-03-06 20:05:56 +000010333 if (Key.get() != OrigElement.Key)
10334 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010335
Ted Kremeneke65b0862012-03-06 20:05:56 +000010336 // Transform and check value.
10337 ExprResult Value
10338 = getDerived().TransformExpr(OrigElement.Value);
10339 if (Value.isInvalid())
10340 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010341
Ted Kremeneke65b0862012-03-06 20:05:56 +000010342 if (Value.get() != OrigElement.Value)
10343 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010344
10345 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010346 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010347 };
10348 Elements.push_back(Element);
10349 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010350
Ted Kremeneke65b0862012-03-06 20:05:56 +000010351 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10352 return SemaRef.MaybeBindToTemporary(E);
10353
10354 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
10355 Elements.data(),
10356 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +000010357}
10358
Mike Stump11289f42009-09-09 15:08:12 +000010359template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010360ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010361TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010362 TypeSourceInfo *EncodedTypeInfo
10363 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10364 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010365 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010366
Douglas Gregora16548e2009-08-11 05:31:07 +000010367 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010368 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010369 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010370
10371 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010372 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010373 E->getRParenLoc());
10374}
Mike Stump11289f42009-09-09 15:08:12 +000010375
Douglas Gregora16548e2009-08-11 05:31:07 +000010376template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010377ExprResult TreeTransform<Derived>::
10378TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010379 // This is a kind of implicit conversion, and it needs to get dropped
10380 // and recomputed for the same general reasons that ImplicitCastExprs
10381 // do, as well a more specific one: this expression is only valid when
10382 // it appears *immediately* as an argument expression.
10383 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010384}
10385
10386template<typename Derived>
10387ExprResult TreeTransform<Derived>::
10388TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010389 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010390 = getDerived().TransformType(E->getTypeInfoAsWritten());
10391 if (!TSInfo)
10392 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010393
John McCall31168b02011-06-15 23:02:42 +000010394 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010395 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010396 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010397
John McCall31168b02011-06-15 23:02:42 +000010398 if (!getDerived().AlwaysRebuild() &&
10399 TSInfo == E->getTypeInfoAsWritten() &&
10400 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010401 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010402
John McCall31168b02011-06-15 23:02:42 +000010403 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010404 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010405 Result.get());
10406}
10407
10408template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010409ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010410TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010411 // Transform arguments.
10412 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010413 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010414 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010415 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010416 &ArgChanged))
10417 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010418
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010419 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10420 // Class message: transform the receiver type.
10421 TypeSourceInfo *ReceiverTypeInfo
10422 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10423 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010424 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010425
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010426 // If nothing changed, just retain the existing message send.
10427 if (!getDerived().AlwaysRebuild() &&
10428 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010429 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010430
10431 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010432 SmallVector<SourceLocation, 16> SelLocs;
10433 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010434 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10435 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010436 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010437 E->getMethodDecl(),
10438 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010439 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010440 E->getRightLoc());
10441 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010442 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10443 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10444 // Build a new class message send to 'super'.
10445 SmallVector<SourceLocation, 16> SelLocs;
10446 E->getSelectorLocs(SelLocs);
10447 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10448 E->getSelector(),
10449 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000010450 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010451 E->getMethodDecl(),
10452 E->getLeftLoc(),
10453 Args,
10454 E->getRightLoc());
10455 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010456
10457 // Instance message: transform the receiver
10458 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10459 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010460 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010461 = getDerived().TransformExpr(E->getInstanceReceiver());
10462 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010463 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010464
10465 // If nothing changed, just retain the existing message send.
10466 if (!getDerived().AlwaysRebuild() &&
10467 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010468 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010469
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010470 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010471 SmallVector<SourceLocation, 16> SelLocs;
10472 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010473 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010474 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010475 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010476 E->getMethodDecl(),
10477 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010478 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010479 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010480}
10481
Mike Stump11289f42009-09-09 15:08:12 +000010482template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010483ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010484TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010485 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010486}
10487
Mike Stump11289f42009-09-09 15:08:12 +000010488template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010489ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010490TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010491 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010492}
10493
Mike Stump11289f42009-09-09 15:08:12 +000010494template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010495ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010496TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010497 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010498 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010499 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010500 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010501
10502 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010503
Douglas Gregord51d90d2010-04-26 20:11:03 +000010504 // If nothing changed, just retain the existing expression.
10505 if (!getDerived().AlwaysRebuild() &&
10506 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010507 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010508
John McCallb268a282010-08-23 23:25:46 +000010509 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010510 E->getLocation(),
10511 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010512}
10513
Mike Stump11289f42009-09-09 15:08:12 +000010514template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010515ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010516TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010517 // 'super' and types never change. Property never changes. Just
10518 // retain the existing expression.
10519 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010520 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010521
Douglas Gregor9faee212010-04-26 20:47:02 +000010522 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010523 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010524 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010525 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010526
Douglas Gregor9faee212010-04-26 20:47:02 +000010527 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010528
Douglas Gregor9faee212010-04-26 20:47:02 +000010529 // If nothing changed, just retain the existing expression.
10530 if (!getDerived().AlwaysRebuild() &&
10531 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010532 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010533
John McCallb7bd14f2010-12-02 01:19:52 +000010534 if (E->isExplicitProperty())
10535 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10536 E->getExplicitProperty(),
10537 E->getLocation());
10538
10539 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010540 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010541 E->getImplicitPropertyGetter(),
10542 E->getImplicitPropertySetter(),
10543 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010544}
10545
Mike Stump11289f42009-09-09 15:08:12 +000010546template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010547ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010548TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10549 // Transform the base expression.
10550 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10551 if (Base.isInvalid())
10552 return ExprError();
10553
10554 // Transform the key expression.
10555 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10556 if (Key.isInvalid())
10557 return ExprError();
10558
10559 // If nothing changed, just retain the existing expression.
10560 if (!getDerived().AlwaysRebuild() &&
10561 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010562 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010563
Chad Rosier1dcde962012-08-08 18:46:20 +000010564 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010565 Base.get(), Key.get(),
10566 E->getAtIndexMethodDecl(),
10567 E->setAtIndexMethodDecl());
10568}
10569
10570template<typename Derived>
10571ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010572TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010573 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010574 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010575 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010576 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010577
Douglas Gregord51d90d2010-04-26 20:11:03 +000010578 // If nothing changed, just retain the existing expression.
10579 if (!getDerived().AlwaysRebuild() &&
10580 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010581 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010582
John McCallb268a282010-08-23 23:25:46 +000010583 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010584 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010585 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010586}
10587
Mike Stump11289f42009-09-09 15:08:12 +000010588template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010589ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010590TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010591 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010592 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010593 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010594 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010595 SubExprs, &ArgumentChanged))
10596 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010597
Douglas Gregora16548e2009-08-11 05:31:07 +000010598 if (!getDerived().AlwaysRebuild() &&
10599 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010600 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010601
Douglas Gregora16548e2009-08-11 05:31:07 +000010602 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010603 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010604 E->getRParenLoc());
10605}
10606
Mike Stump11289f42009-09-09 15:08:12 +000010607template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010608ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010609TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10610 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10611 if (SrcExpr.isInvalid())
10612 return ExprError();
10613
10614 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10615 if (!Type)
10616 return ExprError();
10617
10618 if (!getDerived().AlwaysRebuild() &&
10619 Type == E->getTypeSourceInfo() &&
10620 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010621 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010622
10623 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10624 SrcExpr.get(), Type,
10625 E->getRParenLoc());
10626}
10627
10628template<typename Derived>
10629ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010630TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000010631 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000010632
Craig Topperc3ec1492014-05-26 06:22:03 +000010633 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000010634 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
10635
10636 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000010637 blockScope->TheDecl->setBlockMissingReturnType(
10638 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000010639
Chris Lattner01cf8db2011-07-20 06:58:45 +000010640 SmallVector<ParmVarDecl*, 4> params;
10641 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000010642
Fariborz Jahanian1babe772010-07-09 18:44:02 +000010643 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000010644 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
10645 oldBlock->param_begin(),
10646 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010647 nullptr, paramTypes, &params)) {
10648 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010649 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010650 }
John McCall490112f2011-02-04 18:33:18 +000010651
Jordan Rosea0a86be2013-03-08 22:25:36 +000010652 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000010653 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000010654 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000010655
Jordan Rose5c382722013-03-08 21:51:21 +000010656 QualType functionType =
10657 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010658 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000010659 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000010660
10661 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000010662 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000010663 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000010664
10665 if (!oldBlock->blockMissingReturnType()) {
10666 blockScope->HasImplicitReturnType = false;
10667 blockScope->ReturnType = exprResultType;
10668 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010669
John McCall3882ace2011-01-05 12:14:39 +000010670 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000010671 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010672 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010673 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000010674 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010675 }
John McCall3882ace2011-01-05 12:14:39 +000010676
John McCall490112f2011-02-04 18:33:18 +000010677#ifndef NDEBUG
10678 // In builds with assertions, make sure that we captured everything we
10679 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010680 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000010681 for (const auto &I : oldBlock->captures()) {
10682 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000010683
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010684 // Ignore parameter packs.
10685 if (isa<ParmVarDecl>(oldCapture) &&
10686 cast<ParmVarDecl>(oldCapture)->isParameterPack())
10687 continue;
John McCall490112f2011-02-04 18:33:18 +000010688
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010689 VarDecl *newCapture =
10690 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
10691 oldCapture));
10692 assert(blockScope->CaptureMap.count(newCapture));
10693 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010694 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000010695 }
10696#endif
10697
10698 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010699 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000010700}
10701
Mike Stump11289f42009-09-09 15:08:12 +000010702template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010703ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000010704TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010705 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010706}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010707
10708template<typename Derived>
10709ExprResult
10710TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010711 QualType RetTy = getDerived().TransformType(E->getType());
10712 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010713 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010714 SubExprs.reserve(E->getNumSubExprs());
10715 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10716 SubExprs, &ArgumentChanged))
10717 return ExprError();
10718
10719 if (!getDerived().AlwaysRebuild() &&
10720 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010721 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010722
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010723 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010724 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010725}
Chad Rosier1dcde962012-08-08 18:46:20 +000010726
Douglas Gregora16548e2009-08-11 05:31:07 +000010727//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010728// Type reconstruction
10729//===----------------------------------------------------------------------===//
10730
Mike Stump11289f42009-09-09 15:08:12 +000010731template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010732QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10733 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010734 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010735 getDerived().getBaseEntity());
10736}
10737
Mike Stump11289f42009-09-09 15:08:12 +000010738template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010739QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10740 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010741 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010742 getDerived().getBaseEntity());
10743}
10744
Mike Stump11289f42009-09-09 15:08:12 +000010745template<typename Derived>
10746QualType
John McCall70dd5f62009-10-30 00:06:24 +000010747TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10748 bool WrittenAsLValue,
10749 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010750 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010751 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010752}
10753
10754template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010755QualType
John McCall70dd5f62009-10-30 00:06:24 +000010756TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10757 QualType ClassType,
10758 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010759 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10760 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010761}
10762
10763template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000010764QualType TreeTransform<Derived>::RebuildObjCObjectType(
10765 QualType BaseType,
10766 SourceLocation Loc,
10767 SourceLocation TypeArgsLAngleLoc,
10768 ArrayRef<TypeSourceInfo *> TypeArgs,
10769 SourceLocation TypeArgsRAngleLoc,
10770 SourceLocation ProtocolLAngleLoc,
10771 ArrayRef<ObjCProtocolDecl *> Protocols,
10772 ArrayRef<SourceLocation> ProtocolLocs,
10773 SourceLocation ProtocolRAngleLoc) {
10774 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
10775 TypeArgs, TypeArgsRAngleLoc,
10776 ProtocolLAngleLoc, Protocols, ProtocolLocs,
10777 ProtocolRAngleLoc,
10778 /*FailOnError=*/true);
10779}
10780
10781template<typename Derived>
10782QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
10783 QualType PointeeType,
10784 SourceLocation Star) {
10785 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
10786}
10787
10788template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010789QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010790TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10791 ArrayType::ArraySizeModifier SizeMod,
10792 const llvm::APInt *Size,
10793 Expr *SizeExpr,
10794 unsigned IndexTypeQuals,
10795 SourceRange BracketsRange) {
10796 if (SizeExpr || !Size)
10797 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10798 IndexTypeQuals, BracketsRange,
10799 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010800
10801 QualType Types[] = {
10802 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10803 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10804 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010805 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010806 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010807 QualType SizeType;
10808 for (unsigned I = 0; I != NumTypes; ++I)
10809 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10810 SizeType = Types[I];
10811 break;
10812 }
Mike Stump11289f42009-09-09 15:08:12 +000010813
Eli Friedman9562f392012-01-25 23:20:27 +000010814 // Note that we can return a VariableArrayType here in the case where
10815 // the element type was a dependent VariableArrayType.
10816 IntegerLiteral *ArraySize
10817 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10818 /*FIXME*/BracketsRange.getBegin());
10819 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010820 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010821 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010822}
Mike Stump11289f42009-09-09 15:08:12 +000010823
Douglas Gregord6ff3322009-08-04 16:50:30 +000010824template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010825QualType
10826TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010827 ArrayType::ArraySizeModifier SizeMod,
10828 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010829 unsigned IndexTypeQuals,
10830 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010831 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010832 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010833}
10834
10835template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010836QualType
Mike Stump11289f42009-09-09 15:08:12 +000010837TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010838 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010839 unsigned IndexTypeQuals,
10840 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010841 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010842 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010843}
Mike Stump11289f42009-09-09 15:08:12 +000010844
Douglas Gregord6ff3322009-08-04 16:50:30 +000010845template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010846QualType
10847TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010848 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010849 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010850 unsigned IndexTypeQuals,
10851 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010852 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010853 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010854 IndexTypeQuals, BracketsRange);
10855}
10856
10857template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010858QualType
10859TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010860 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010861 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010862 unsigned IndexTypeQuals,
10863 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010864 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010865 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010866 IndexTypeQuals, BracketsRange);
10867}
10868
10869template<typename Derived>
10870QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010871 unsigned NumElements,
10872 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010873 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010874 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010875}
Mike Stump11289f42009-09-09 15:08:12 +000010876
Douglas Gregord6ff3322009-08-04 16:50:30 +000010877template<typename Derived>
10878QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10879 unsigned NumElements,
10880 SourceLocation AttributeLoc) {
10881 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10882 NumElements, true);
10883 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010884 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10885 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010886 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010887}
Mike Stump11289f42009-09-09 15:08:12 +000010888
Douglas Gregord6ff3322009-08-04 16:50:30 +000010889template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010890QualType
10891TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010892 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010893 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010894 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010895}
Mike Stump11289f42009-09-09 15:08:12 +000010896
Douglas Gregord6ff3322009-08-04 16:50:30 +000010897template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010898QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10899 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010900 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010901 const FunctionProtoType::ExtProtoInfo &EPI) {
10902 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010903 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010904 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010905 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010906}
Mike Stump11289f42009-09-09 15:08:12 +000010907
Douglas Gregord6ff3322009-08-04 16:50:30 +000010908template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010909QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10910 return SemaRef.Context.getFunctionNoProtoType(T);
10911}
10912
10913template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010914QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10915 assert(D && "no decl found");
10916 if (D->isInvalidDecl()) return QualType();
10917
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010918 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000010919 TypeDecl *Ty;
10920 if (isa<UsingDecl>(D)) {
10921 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000010922 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000010923 "UnresolvedUsingTypenameDecl transformed to non-typename using");
10924
10925 // A valid resolved using typename decl points to exactly one type decl.
10926 assert(++Using->shadow_begin() == Using->shadow_end());
10927 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000010928
John McCallb96ec562009-12-04 22:46:56 +000010929 } else {
10930 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
10931 "UnresolvedUsingTypenameDecl transformed to non-using decl");
10932 Ty = cast<UnresolvedUsingTypenameDecl>(D);
10933 }
10934
10935 return SemaRef.Context.getTypeDeclType(Ty);
10936}
10937
10938template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010939QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
10940 SourceLocation Loc) {
10941 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010942}
10943
10944template<typename Derived>
10945QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
10946 return SemaRef.Context.getTypeOfType(Underlying);
10947}
10948
10949template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000010950QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
10951 SourceLocation Loc) {
10952 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010953}
10954
10955template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000010956QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
10957 UnaryTransformType::UTTKind UKind,
10958 SourceLocation Loc) {
10959 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
10960}
10961
10962template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000010963QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000010964 TemplateName Template,
10965 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000010966 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000010967 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010968}
Mike Stump11289f42009-09-09 15:08:12 +000010969
Douglas Gregor1135c352009-08-06 05:28:30 +000010970template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000010971QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
10972 SourceLocation KWLoc) {
10973 return SemaRef.BuildAtomicType(ValueType, KWLoc);
10974}
10975
10976template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010977TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010978TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010979 bool TemplateKW,
10980 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010981 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000010982 Template);
10983}
10984
10985template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010986TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000010987TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
10988 const IdentifierInfo &Name,
10989 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000010990 QualType ObjectType,
10991 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000010992 UnqualifiedId TemplateName;
10993 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000010994 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000010995 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000010996 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000010997 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000010998 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000010999 /*EnteringContext=*/false,
11000 Template);
John McCall31f82722010-11-12 08:19:04 +000011001 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011002}
Mike Stump11289f42009-09-09 15:08:12 +000011003
Douglas Gregora16548e2009-08-11 05:31:07 +000011004template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011005TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011006TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011007 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011008 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011009 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011010 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011011 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011012 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011013 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011014 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011015 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011016 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011017 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011018 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011019 /*EnteringContext=*/false,
11020 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011021 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011022}
Chad Rosier1dcde962012-08-08 18:46:20 +000011023
Douglas Gregor71395fa2009-11-04 00:56:37 +000011024template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011025ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011026TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11027 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011028 Expr *OrigCallee,
11029 Expr *First,
11030 Expr *Second) {
11031 Expr *Callee = OrigCallee->IgnoreParenCasts();
11032 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011033
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011034 if (First->getObjectKind() == OK_ObjCProperty) {
11035 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11036 if (BinaryOperator::isAssignmentOp(Opc))
11037 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11038 First, Second);
11039 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11040 if (Result.isInvalid())
11041 return ExprError();
11042 First = Result.get();
11043 }
11044
11045 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11046 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11047 if (Result.isInvalid())
11048 return ExprError();
11049 Second = Result.get();
11050 }
11051
Douglas Gregora16548e2009-08-11 05:31:07 +000011052 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011053 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011054 if (!First->getType()->isOverloadableType() &&
11055 !Second->getType()->isOverloadableType())
11056 return getSema().CreateBuiltinArraySubscriptExpr(First,
11057 Callee->getLocStart(),
11058 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011059 } else if (Op == OO_Arrow) {
11060 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011061 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11062 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011063 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011064 // The argument is not of overloadable type, so try to create a
11065 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011066 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011067 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011068
John McCallb268a282010-08-23 23:25:46 +000011069 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011070 }
11071 } else {
John McCallb268a282010-08-23 23:25:46 +000011072 if (!First->getType()->isOverloadableType() &&
11073 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011074 // Neither of the arguments is an overloadable type, so try to
11075 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011076 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011077 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011078 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011079 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011080 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011081
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011082 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011083 }
11084 }
Mike Stump11289f42009-09-09 15:08:12 +000011085
11086 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011087 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011088 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011089
John McCallb268a282010-08-23 23:25:46 +000011090 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011091 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011092 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011093 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011094 // If we've resolved this to a particular non-member function, just call
11095 // that function. If we resolved it to a member function,
11096 // CreateOverloaded* will find that function for us.
11097 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11098 if (!isa<CXXMethodDecl>(ND))
11099 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011100 }
Mike Stump11289f42009-09-09 15:08:12 +000011101
Douglas Gregora16548e2009-08-11 05:31:07 +000011102 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011103 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011104 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011105
Douglas Gregora16548e2009-08-11 05:31:07 +000011106 // Create the overloaded operator invocation for unary operators.
11107 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011108 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011109 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011110 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011111 }
Mike Stump11289f42009-09-09 15:08:12 +000011112
Douglas Gregore9d62932011-07-15 16:25:15 +000011113 if (Op == OO_Subscript) {
11114 SourceLocation LBrace;
11115 SourceLocation RBrace;
11116
11117 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011118 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011119 LBrace = SourceLocation::getFromRawEncoding(
11120 NameLoc.CXXOperatorName.BeginOpNameLoc);
11121 RBrace = SourceLocation::getFromRawEncoding(
11122 NameLoc.CXXOperatorName.EndOpNameLoc);
11123 } else {
11124 LBrace = Callee->getLocStart();
11125 RBrace = OpLoc;
11126 }
11127
11128 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11129 First, Second);
11130 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011131
Douglas Gregora16548e2009-08-11 05:31:07 +000011132 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011133 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011134 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011135 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11136 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011137 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011138
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011139 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011140}
Mike Stump11289f42009-09-09 15:08:12 +000011141
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011142template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011143ExprResult
John McCallb268a282010-08-23 23:25:46 +000011144TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011145 SourceLocation OperatorLoc,
11146 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011147 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011148 TypeSourceInfo *ScopeType,
11149 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011150 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011151 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011152 QualType BaseType = Base->getType();
11153 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011154 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011155 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011156 !BaseType->getAs<PointerType>()->getPointeeType()
11157 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011158 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011159 return SemaRef.BuildPseudoDestructorExpr(
11160 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11161 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011162 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011163
Douglas Gregor678f90d2010-02-25 01:56:36 +000011164 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011165 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11166 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11167 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11168 NameInfo.setNamedTypeInfo(DestroyedType);
11169
Richard Smith8e4a3862012-05-15 06:15:11 +000011170 // The scope type is now known to be a valid nested name specifier
11171 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011172 if (ScopeType) {
11173 if (!ScopeType->getType()->getAs<TagType>()) {
11174 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11175 diag::err_expected_class_or_namespace)
11176 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11177 return ExprError();
11178 }
11179 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11180 CCLoc);
11181 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011182
Abramo Bagnara7945c982012-01-27 09:46:47 +000011183 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011184 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011185 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011186 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011187 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011188 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +000011189 /*TemplateArgs*/ nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011190}
11191
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011192template<typename Derived>
11193StmtResult
11194TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011195 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011196 CapturedDecl *CD = S->getCapturedDecl();
11197 unsigned NumParams = CD->getNumParams();
11198 unsigned ContextParamPos = CD->getContextParamPosition();
11199 SmallVector<Sema::CapturedParamNameType, 4> Params;
11200 for (unsigned I = 0; I < NumParams; ++I) {
11201 if (I != ContextParamPos) {
11202 Params.push_back(
11203 std::make_pair(
11204 CD->getParam(I)->getName(),
11205 getDerived().TransformType(CD->getParam(I)->getType())));
11206 } else {
11207 Params.push_back(std::make_pair(StringRef(), QualType()));
11208 }
11209 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011210 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011211 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011212 StmtResult Body;
11213 {
11214 Sema::CompoundScopeRAII CompoundScope(getSema());
11215 Body = getDerived().TransformStmt(S->getCapturedStmt());
11216 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011217
11218 if (Body.isInvalid()) {
11219 getSema().ActOnCapturedRegionError();
11220 return StmtError();
11221 }
11222
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011223 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011224}
11225
Douglas Gregord6ff3322009-08-04 16:50:30 +000011226} // end namespace clang
11227
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000011228#endif