blob: 29073debcd7338efe48347454b1dc82de3addee1 [file] [log] [blame]
Chris Lattnercab02a62011-02-17 20:34:02 +00001//===------- TreeTransform.h - Semantic Tree Transformation -----*- C++ -*-===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
Chris Lattnercab02a62011-02-17 20:34:02 +00007//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +00008//
9// This file implements a semantic tree transformation that takes a given
10// AST and rebuilds it, possibly transforming some nodes in the process.
11//
Chris Lattnercab02a62011-02-17 20:34:02 +000012//===----------------------------------------------------------------------===//
13
Benjamin Kramer2f5db8b2014-08-13 16:25:19 +000014#ifndef LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
15#define LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H
Douglas Gregord6ff3322009-08-04 16:50:30 +000016
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "TypeLocBuilder.h"
Douglas Gregor2b6ca462009-09-03 21:38:09 +000018#include "clang/AST/Decl.h"
John McCallde6836a2010-08-24 07:21:54 +000019#include "clang/AST/DeclObjC.h"
Richard Smith3f1b5d02011-05-05 21:57:07 +000020#include "clang/AST/DeclTemplate.h"
Douglas Gregor766b0bb2009-08-06 22:17:10 +000021#include "clang/AST/Expr.h"
Douglas Gregora16548e2009-08-11 05:31:07 +000022#include "clang/AST/ExprCXX.h"
23#include "clang/AST/ExprObjC.h"
Alexey Bataev1a3320e2015-08-25 14:24:04 +000024#include "clang/AST/ExprOpenMP.h"
Douglas Gregorebe10102009-08-20 07:17:43 +000025#include "clang/AST/Stmt.h"
26#include "clang/AST/StmtCXX.h"
27#include "clang/AST/StmtObjC.h"
Alexey Bataev5ec3eb12013-07-19 03:13:43 +000028#include "clang/AST/StmtOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000029#include "clang/Sema/Designator.h"
30#include "clang/Sema/Lookup.h"
31#include "clang/Sema/Ownership.h"
32#include "clang/Sema/ParsedTemplate.h"
33#include "clang/Sema/ScopeInfo.h"
34#include "clang/Sema/SemaDiagnostic.h"
35#include "clang/Sema/SemaInternal.h"
David Blaikieb9c168a2011-09-22 02:34:54 +000036#include "llvm/ADT/ArrayRef.h"
John McCall550e0c22009-10-21 00:40:46 +000037#include "llvm/Support/ErrorHandling.h"
Douglas Gregord6ff3322009-08-04 16:50:30 +000038#include <algorithm>
39
40namespace clang {
John McCallaab3e412010-08-25 08:40:02 +000041using namespace sema;
Mike Stump11289f42009-09-09 15:08:12 +000042
Douglas Gregord6ff3322009-08-04 16:50:30 +000043/// \brief A semantic tree transformation that allows one to transform one
44/// abstract syntax tree into another.
45///
Mike Stump11289f42009-09-09 15:08:12 +000046/// A new tree transformation is defined by creating a new subclass \c X of
47/// \c TreeTransform<X> and then overriding certain operations to provide
48/// behavior specific to that transformation. For example, template
Douglas Gregord6ff3322009-08-04 16:50:30 +000049/// instantiation is implemented as a tree transformation where the
50/// transformation of TemplateTypeParmType nodes involves substituting the
51/// template arguments for their corresponding template parameters; a similar
52/// transformation is performed for non-type template parameters and
53/// template template parameters.
54///
55/// This tree-transformation template uses static polymorphism to allow
Mike Stump11289f42009-09-09 15:08:12 +000056/// subclasses to customize any of its operations. Thus, a subclass can
Douglas Gregord6ff3322009-08-04 16:50:30 +000057/// override any of the transformation or rebuild operators by providing an
58/// operation with the same signature as the default implementation. The
59/// overridding function should not be virtual.
60///
61/// Semantic tree transformations are split into two stages, either of which
62/// can be replaced by a subclass. The "transform" step transforms an AST node
63/// or the parts of an AST node using the various transformation functions,
64/// then passes the pieces on to the "rebuild" step, which constructs a new AST
65/// node of the appropriate kind from the pieces. The default transformation
66/// routines recursively transform the operands to composite AST nodes (e.g.,
67/// the pointee type of a PointerType node) and, if any of those operand nodes
68/// were changed by the transformation, invokes the rebuild operation to create
69/// a new AST node.
70///
Mike Stump11289f42009-09-09 15:08:12 +000071/// Subclasses can customize the transformation at various levels. The
Douglas Gregore922c772009-08-04 22:27:00 +000072/// most coarse-grained transformations involve replacing TransformType(),
Douglas Gregorfd35cde2011-03-02 18:50:38 +000073/// TransformExpr(), TransformDecl(), TransformNestedNameSpecifierLoc(),
Douglas Gregord6ff3322009-08-04 16:50:30 +000074/// TransformTemplateName(), or TransformTemplateArgument() with entirely
75/// new implementations.
76///
77/// For more fine-grained transformations, subclasses can replace any of the
78/// \c TransformXXX functions (where XXX is the name of an AST node, e.g.,
Douglas Gregorebe10102009-08-20 07:17:43 +000079/// PointerType, StmtExpr) to alter the transformation. As mentioned previously,
Douglas Gregord6ff3322009-08-04 16:50:30 +000080/// replacing TransformTemplateTypeParmType() allows template instantiation
Mike Stump11289f42009-09-09 15:08:12 +000081/// to substitute template arguments for their corresponding template
Douglas Gregord6ff3322009-08-04 16:50:30 +000082/// parameters. Additionally, subclasses can override the \c RebuildXXX
83/// functions to control how AST nodes are rebuilt when their operands change.
84/// By default, \c TreeTransform will invoke semantic analysis to rebuild
85/// AST nodes. However, certain other tree transformations (e.g, cloning) may
86/// be able to use more efficient rebuild steps.
87///
88/// There are a handful of other functions that can be overridden, allowing one
Mike Stump11289f42009-09-09 15:08:12 +000089/// to avoid traversing nodes that don't need any transformation
Douglas Gregord6ff3322009-08-04 16:50:30 +000090/// (\c AlreadyTransformed()), force rebuilding AST nodes even when their
91/// operands have not changed (\c AlwaysRebuild()), and customize the
92/// default locations and entity names used for type-checking
93/// (\c getBaseLocation(), \c getBaseEntity()).
Douglas Gregord6ff3322009-08-04 16:50:30 +000094template<typename Derived>
95class TreeTransform {
Douglas Gregora8bac7f2011-01-10 07:32:04 +000096 /// \brief Private RAII object that helps us forget and then re-remember
97 /// the template argument corresponding to a partially-substituted parameter
98 /// pack.
99 class ForgetPartiallySubstitutedPackRAII {
100 Derived &Self;
101 TemplateArgument Old;
Chad Rosier1dcde962012-08-08 18:46:20 +0000102
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000103 public:
104 ForgetPartiallySubstitutedPackRAII(Derived &Self) : Self(Self) {
105 Old = Self.ForgetPartiallySubstitutedPack();
106 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000107
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000108 ~ForgetPartiallySubstitutedPackRAII() {
109 Self.RememberPartiallySubstitutedPack(Old);
110 }
111 };
Chad Rosier1dcde962012-08-08 18:46:20 +0000112
Douglas Gregord6ff3322009-08-04 16:50:30 +0000113protected:
114 Sema &SemaRef;
Chad Rosier1dcde962012-08-08 18:46:20 +0000115
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000116 /// \brief The set of local declarations that have been transformed, for
117 /// cases where we are forced to build new declarations within the transformer
118 /// rather than in the subclass (e.g., lambda closure types).
119 llvm::DenseMap<Decl *, Decl *> TransformedLocalDecls;
Chad Rosier1dcde962012-08-08 18:46:20 +0000120
Mike Stump11289f42009-09-09 15:08:12 +0000121public:
Douglas Gregord6ff3322009-08-04 16:50:30 +0000122 /// \brief Initializes a new tree transformer.
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000123 TreeTransform(Sema &SemaRef) : SemaRef(SemaRef) { }
Mike Stump11289f42009-09-09 15:08:12 +0000124
Douglas Gregord6ff3322009-08-04 16:50:30 +0000125 /// \brief Retrieves a reference to the derived class.
126 Derived &getDerived() { return static_cast<Derived&>(*this); }
127
128 /// \brief Retrieves a reference to the derived class.
Mike Stump11289f42009-09-09 15:08:12 +0000129 const Derived &getDerived() const {
130 return static_cast<const Derived&>(*this);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000131 }
132
John McCalldadc5752010-08-24 06:29:42 +0000133 static inline ExprResult Owned(Expr *E) { return E; }
134 static inline StmtResult Owned(Stmt *S) { return S; }
John McCallb268a282010-08-23 23:25:46 +0000135
Douglas Gregord6ff3322009-08-04 16:50:30 +0000136 /// \brief Retrieves a reference to the semantic analysis object used for
137 /// this tree transform.
138 Sema &getSema() const { return SemaRef; }
Mike Stump11289f42009-09-09 15:08:12 +0000139
Douglas Gregord6ff3322009-08-04 16:50:30 +0000140 /// \brief Whether the transformation should always rebuild AST nodes, even
141 /// if none of the children have changed.
142 ///
143 /// Subclasses may override this function to specify when the transformation
144 /// should rebuild all AST nodes.
Richard Smith2aa81a72013-11-07 20:07:17 +0000145 ///
146 /// We must always rebuild all AST nodes when performing variadic template
147 /// pack expansion, in order to avoid violating the AST invariant that each
148 /// statement node appears at most once in its containing declaration.
149 bool AlwaysRebuild() { return SemaRef.ArgumentPackSubstitutionIndex != -1; }
Mike Stump11289f42009-09-09 15:08:12 +0000150
Douglas Gregord6ff3322009-08-04 16:50:30 +0000151 /// \brief Returns the location of the entity being transformed, if that
152 /// information was not available elsewhere in the AST.
153 ///
Mike Stump11289f42009-09-09 15:08:12 +0000154 /// By default, returns no source-location information. Subclasses can
Douglas Gregord6ff3322009-08-04 16:50:30 +0000155 /// provide an alternative implementation that provides better location
156 /// information.
157 SourceLocation getBaseLocation() { return SourceLocation(); }
Mike Stump11289f42009-09-09 15:08:12 +0000158
Douglas Gregord6ff3322009-08-04 16:50:30 +0000159 /// \brief Returns the name of the entity being transformed, if that
160 /// information was not available elsewhere in the AST.
161 ///
162 /// By default, returns an empty name. Subclasses can provide an alternative
163 /// implementation with a more precise name.
164 DeclarationName getBaseEntity() { return DeclarationName(); }
165
Douglas Gregora16548e2009-08-11 05:31:07 +0000166 /// \brief Sets the "base" location and entity when that
167 /// information is known based on another transformation.
168 ///
169 /// By default, the source location and entity are ignored. Subclasses can
170 /// override this function to provide a customized implementation.
171 void setBase(SourceLocation Loc, DeclarationName Entity) { }
Mike Stump11289f42009-09-09 15:08:12 +0000172
Douglas Gregora16548e2009-08-11 05:31:07 +0000173 /// \brief RAII object that temporarily sets the base location and entity
174 /// used for reporting diagnostics in types.
175 class TemporaryBase {
176 TreeTransform &Self;
177 SourceLocation OldLocation;
178 DeclarationName OldEntity;
Mike Stump11289f42009-09-09 15:08:12 +0000179
Douglas Gregora16548e2009-08-11 05:31:07 +0000180 public:
181 TemporaryBase(TreeTransform &Self, SourceLocation Location,
Mike Stump11289f42009-09-09 15:08:12 +0000182 DeclarationName Entity) : Self(Self) {
Douglas Gregora16548e2009-08-11 05:31:07 +0000183 OldLocation = Self.getDerived().getBaseLocation();
184 OldEntity = Self.getDerived().getBaseEntity();
Chad Rosier1dcde962012-08-08 18:46:20 +0000185
Douglas Gregora518d5b2011-01-25 17:51:48 +0000186 if (Location.isValid())
187 Self.getDerived().setBase(Location, Entity);
Douglas Gregora16548e2009-08-11 05:31:07 +0000188 }
Mike Stump11289f42009-09-09 15:08:12 +0000189
Douglas Gregora16548e2009-08-11 05:31:07 +0000190 ~TemporaryBase() {
191 Self.getDerived().setBase(OldLocation, OldEntity);
192 }
193 };
Mike Stump11289f42009-09-09 15:08:12 +0000194
195 /// \brief Determine whether the given type \p T has already been
Douglas Gregord6ff3322009-08-04 16:50:30 +0000196 /// transformed.
197 ///
198 /// Subclasses can provide an alternative implementation of this routine
Mike Stump11289f42009-09-09 15:08:12 +0000199 /// to short-circuit evaluation when it is known that a given type will
Douglas Gregord6ff3322009-08-04 16:50:30 +0000200 /// not change. For example, template instantiation need not traverse
201 /// non-dependent types.
202 bool AlreadyTransformed(QualType T) {
203 return T.isNull();
204 }
205
Douglas Gregord196a582009-12-14 19:27:10 +0000206 /// \brief Determine whether the given call argument should be dropped, e.g.,
207 /// because it is a default argument.
208 ///
209 /// Subclasses can provide an alternative implementation of this routine to
210 /// determine which kinds of call arguments get dropped. By default,
211 /// CXXDefaultArgument nodes are dropped (prior to transformation).
212 bool DropCallArgument(Expr *E) {
213 return E->isDefaultArgument();
214 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000215
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000216 /// \brief Determine whether we should expand a pack expansion with the
217 /// given set of parameter packs into separate arguments by repeatedly
218 /// transforming the pattern.
219 ///
Douglas Gregor76aca7b2010-12-21 00:52:54 +0000220 /// By default, the transformer never tries to expand pack expansions.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000221 /// Subclasses can override this routine to provide different behavior.
222 ///
223 /// \param EllipsisLoc The location of the ellipsis that identifies the
224 /// pack expansion.
225 ///
226 /// \param PatternRange The source range that covers the entire pattern of
227 /// the pack expansion.
228 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000229 /// \param Unexpanded The set of unexpanded parameter packs within the
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000230 /// pattern.
231 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000232 /// \param ShouldExpand Will be set to \c true if the transformer should
233 /// expand the corresponding pack expansions into separate arguments. When
234 /// set, \c NumExpansions must also be set.
235 ///
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000236 /// \param RetainExpansion Whether the caller should add an unexpanded
237 /// pack expansion after all of the expanded arguments. This is used
238 /// when extending explicitly-specified template argument packs per
239 /// C++0x [temp.arg.explicit]p9.
240 ///
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000241 /// \param NumExpansions The number of separate arguments that will be in
Douglas Gregor0dca5fd2011-01-14 17:04:44 +0000242 /// the expanded form of the corresponding pack expansion. This is both an
243 /// input and an output parameter, which can be set by the caller if the
244 /// number of expansions is known a priori (e.g., due to a prior substitution)
245 /// and will be set by the callee when the number of expansions is known.
246 /// The callee must set this value when \c ShouldExpand is \c true; it may
247 /// set this value in other cases.
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000248 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000249 /// \returns true if an error occurred (e.g., because the parameter packs
250 /// are to be instantiated with arguments of different lengths), false
251 /// otherwise. If false, \c ShouldExpand (and possibly \c NumExpansions)
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000252 /// must be set.
253 bool TryExpandParameterPacks(SourceLocation EllipsisLoc,
254 SourceRange PatternRange,
Dmitri Gribenkof8579502013-01-12 19:30:44 +0000255 ArrayRef<UnexpandedParameterPack> Unexpanded,
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000256 bool &ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000257 bool &RetainExpansion,
David Blaikie05785d12013-02-20 22:23:23 +0000258 Optional<unsigned> &NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +0000259 ShouldExpand = false;
260 return false;
261 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000262
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000263 /// \brief "Forget" about the partially-substituted pack template argument,
264 /// when performing an instantiation that must preserve the parameter pack
265 /// use.
266 ///
267 /// This routine is meant to be overridden by the template instantiator.
268 TemplateArgument ForgetPartiallySubstitutedPack() {
269 return TemplateArgument();
270 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000271
Douglas Gregora8bac7f2011-01-10 07:32:04 +0000272 /// \brief "Remember" the partially-substituted pack template argument
273 /// after performing an instantiation that must preserve the parameter pack
274 /// use.
275 ///
276 /// This routine is meant to be overridden by the template instantiator.
277 void RememberPartiallySubstitutedPack(TemplateArgument Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000278
Douglas Gregorf3010112011-01-07 16:43:16 +0000279 /// \brief Note to the derived class when a function parameter pack is
280 /// being expanded.
281 void ExpandingFunctionParameterPack(ParmVarDecl *Pack) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000282
Douglas Gregord6ff3322009-08-04 16:50:30 +0000283 /// \brief Transforms the given type into another type.
284 ///
John McCall550e0c22009-10-21 00:40:46 +0000285 /// By default, this routine transforms a type by creating a
John McCallbcd03502009-12-07 02:54:59 +0000286 /// TypeSourceInfo for it and delegating to the appropriate
John McCall550e0c22009-10-21 00:40:46 +0000287 /// function. This is expensive, but we don't mind, because
288 /// this method is deprecated anyway; all users should be
John McCallbcd03502009-12-07 02:54:59 +0000289 /// switched to storing TypeSourceInfos.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000290 ///
291 /// \returns the transformed type.
John McCall31f82722010-11-12 08:19:04 +0000292 QualType TransformType(QualType T);
Mike Stump11289f42009-09-09 15:08:12 +0000293
John McCall550e0c22009-10-21 00:40:46 +0000294 /// \brief Transforms the given type-with-location into a new
295 /// type-with-location.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000296 ///
John McCall550e0c22009-10-21 00:40:46 +0000297 /// By default, this routine transforms a type by delegating to the
298 /// appropriate TransformXXXType to build a new type. Subclasses
299 /// may override this function (to take over all type
300 /// transformations) or some set of the TransformXXXType functions
301 /// to alter the transformation.
John McCall31f82722010-11-12 08:19:04 +0000302 TypeSourceInfo *TransformType(TypeSourceInfo *DI);
John McCall550e0c22009-10-21 00:40:46 +0000303
304 /// \brief Transform the given type-with-location into a new
305 /// type, collecting location information in the given builder
306 /// as necessary.
307 ///
John McCall31f82722010-11-12 08:19:04 +0000308 QualType TransformType(TypeLocBuilder &TLB, TypeLoc TL);
Mike Stump11289f42009-09-09 15:08:12 +0000309
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000310 /// \brief Transform the given statement.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000311 ///
Mike Stump11289f42009-09-09 15:08:12 +0000312 /// By default, this routine transforms a statement by delegating to the
Douglas Gregorebe10102009-08-20 07:17:43 +0000313 /// appropriate TransformXXXStmt function to transform a specific kind of
314 /// statement or the TransformExpr() function to transform an expression.
315 /// Subclasses may override this function to transform statements using some
316 /// other mechanism.
317 ///
318 /// \returns the transformed statement.
John McCalldadc5752010-08-24 06:29:42 +0000319 StmtResult TransformStmt(Stmt *S);
Mike Stump11289f42009-09-09 15:08:12 +0000320
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000321 /// \brief Transform the given statement.
322 ///
323 /// By default, this routine transforms a statement by delegating to the
324 /// appropriate TransformOMPXXXClause function to transform a specific kind
325 /// of clause. Subclasses may override this function to transform statements
326 /// using some other mechanism.
327 ///
328 /// \returns the transformed OpenMP clause.
329 OMPClause *TransformOMPClause(OMPClause *S);
330
Tyler Nowickic724a83e2014-10-12 20:46:07 +0000331 /// \brief Transform the given attribute.
332 ///
333 /// By default, this routine transforms a statement by delegating to the
334 /// appropriate TransformXXXAttr function to transform a specific kind
335 /// of attribute. Subclasses may override this function to transform
336 /// attributed statements using some other mechanism.
337 ///
338 /// \returns the transformed attribute
339 const Attr *TransformAttr(const Attr *S);
340
341/// \brief Transform the specified attribute.
342///
343/// Subclasses should override the transformation of attributes with a pragma
344/// spelling to transform expressions stored within the attribute.
345///
346/// \returns the transformed attribute.
347#define ATTR(X)
348#define PRAGMA_SPELLING_ATTR(X) \
349 const X##Attr *Transform##X##Attr(const X##Attr *R) { return R; }
350#include "clang/Basic/AttrList.inc"
351
Douglas Gregor766b0bb2009-08-06 22:17:10 +0000352 /// \brief Transform the given expression.
353 ///
Douglas Gregora16548e2009-08-11 05:31:07 +0000354 /// By default, this routine transforms an expression by delegating to the
355 /// appropriate TransformXXXExpr function to build a new expression.
356 /// Subclasses may override this function to transform expressions using some
357 /// other mechanism.
358 ///
359 /// \returns the transformed expression.
John McCalldadc5752010-08-24 06:29:42 +0000360 ExprResult TransformExpr(Expr *E);
Mike Stump11289f42009-09-09 15:08:12 +0000361
Richard Smithd59b8322012-12-19 01:39:02 +0000362 /// \brief Transform the given initializer.
363 ///
364 /// By default, this routine transforms an initializer by stripping off the
365 /// semantic nodes added by initialization, then passing the result to
366 /// TransformExpr or TransformExprs.
367 ///
368 /// \returns the transformed initializer.
Richard Smithc6abd962014-07-25 01:12:44 +0000369 ExprResult TransformInitializer(Expr *Init, bool NotCopyInit);
Richard Smithd59b8322012-12-19 01:39:02 +0000370
Douglas Gregora3efea12011-01-03 19:04:46 +0000371 /// \brief Transform the given list of expressions.
372 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000373 /// This routine transforms a list of expressions by invoking
374 /// \c TransformExpr() for each subexpression. However, it also provides
Douglas Gregora3efea12011-01-03 19:04:46 +0000375 /// support for variadic templates by expanding any pack expansions (if the
376 /// derived class permits such expansion) along the way. When pack expansions
377 /// are present, the number of outputs may not equal the number of inputs.
378 ///
379 /// \param Inputs The set of expressions to be transformed.
380 ///
381 /// \param NumInputs The number of expressions in \c Inputs.
382 ///
383 /// \param IsCall If \c true, then this transform is being performed on
Chad Rosier1dcde962012-08-08 18:46:20 +0000384 /// function-call arguments, and any arguments that should be dropped, will
Douglas Gregora3efea12011-01-03 19:04:46 +0000385 /// be.
386 ///
387 /// \param Outputs The transformed input expressions will be added to this
388 /// vector.
389 ///
390 /// \param ArgChanged If non-NULL, will be set \c true if any argument changed
391 /// due to transformation.
392 ///
393 /// \returns true if an error occurred, false otherwise.
394 bool TransformExprs(Expr **Inputs, unsigned NumInputs, bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000395 SmallVectorImpl<Expr *> &Outputs,
Craig Topperc3ec1492014-05-26 06:22:03 +0000396 bool *ArgChanged = nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000397
Douglas Gregord6ff3322009-08-04 16:50:30 +0000398 /// \brief Transform the given declaration, which is referenced from a type
399 /// or expression.
400 ///
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000401 /// By default, acts as the identity function on declarations, unless the
402 /// transformer has had to transform the declaration itself. Subclasses
Douglas Gregor1135c352009-08-06 05:28:30 +0000403 /// may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000404 Decl *TransformDecl(SourceLocation Loc, Decl *D) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000405 llvm::DenseMap<Decl *, Decl *>::iterator Known
406 = TransformedLocalDecls.find(D);
407 if (Known != TransformedLocalDecls.end())
408 return Known->second;
Chad Rosier1dcde962012-08-08 18:46:20 +0000409
410 return D;
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000411 }
Douglas Gregorebe10102009-08-20 07:17:43 +0000412
Chad Rosier1dcde962012-08-08 18:46:20 +0000413 /// \brief Transform the attributes associated with the given declaration and
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000414 /// place them on the new declaration.
415 ///
416 /// By default, this operation does nothing. Subclasses may override this
417 /// behavior to transform attributes.
418 void transformAttrs(Decl *Old, Decl *New) { }
Chad Rosier1dcde962012-08-08 18:46:20 +0000419
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000420 /// \brief Note that a local declaration has been transformed by this
421 /// transformer.
422 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000423 /// Local declarations are typically transformed via a call to
Douglas Gregor0c46b2b2012-02-13 22:00:16 +0000424 /// TransformDefinition. However, in some cases (e.g., lambda expressions),
425 /// the transformer itself has to transform the declarations. This routine
426 /// can be overridden by a subclass that keeps track of such mappings.
427 void transformedLocalDecl(Decl *Old, Decl *New) {
428 TransformedLocalDecls[Old] = New;
429 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000430
Douglas Gregorebe10102009-08-20 07:17:43 +0000431 /// \brief Transform the definition of the given declaration.
432 ///
Mike Stump11289f42009-09-09 15:08:12 +0000433 /// By default, invokes TransformDecl() to transform the declaration.
Douglas Gregorebe10102009-08-20 07:17:43 +0000434 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000435 Decl *TransformDefinition(SourceLocation Loc, Decl *D) {
436 return getDerived().TransformDecl(Loc, D);
Douglas Gregora04f2ca2010-03-01 15:56:25 +0000437 }
Mike Stump11289f42009-09-09 15:08:12 +0000438
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000439 /// \brief Transform the given declaration, which was the first part of a
440 /// nested-name-specifier in a member access expression.
441 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000442 /// This specific declaration transformation only applies to the first
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000443 /// identifier in a nested-name-specifier of a member access expression, e.g.,
444 /// the \c T in \c x->T::member
445 ///
446 /// By default, invokes TransformDecl() to transform the declaration.
447 /// Subclasses may override this function to provide alternate behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +0000448 NamedDecl *TransformFirstQualifierInScope(NamedDecl *D, SourceLocation Loc) {
449 return cast_or_null<NamedDecl>(getDerived().TransformDecl(Loc, D));
Douglas Gregora5cb6da2009-10-20 05:58:46 +0000450 }
Chad Rosier1dcde962012-08-08 18:46:20 +0000451
Douglas Gregor14454802011-02-25 02:25:35 +0000452 /// \brief Transform the given nested-name-specifier with source-location
453 /// information.
454 ///
455 /// By default, transforms all of the types and declarations within the
456 /// nested-name-specifier. Subclasses may override this function to provide
457 /// alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000458 NestedNameSpecifierLoc
459 TransformNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS,
460 QualType ObjectType = QualType(),
461 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor14454802011-02-25 02:25:35 +0000462
Douglas Gregorf816bd72009-09-03 22:13:48 +0000463 /// \brief Transform the given declaration name.
464 ///
465 /// By default, transforms the types of conversion function, constructor,
466 /// and destructor names and then (if needed) rebuilds the declaration name.
467 /// Identifiers and selectors are returned unmodified. Sublcasses may
468 /// override this function to provide alternate behavior.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +0000469 DeclarationNameInfo
John McCall31f82722010-11-12 08:19:04 +0000470 TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo);
Mike Stump11289f42009-09-09 15:08:12 +0000471
Douglas Gregord6ff3322009-08-04 16:50:30 +0000472 /// \brief Transform the given template name.
Mike Stump11289f42009-09-09 15:08:12 +0000473 ///
Douglas Gregor9db53502011-03-02 18:07:45 +0000474 /// \param SS The nested-name-specifier that qualifies the template
475 /// name. This nested-name-specifier must already have been transformed.
476 ///
477 /// \param Name The template name to transform.
478 ///
479 /// \param NameLoc The source location of the template name.
480 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000481 /// \param ObjectType If we're translating a template name within a member
Douglas Gregor9db53502011-03-02 18:07:45 +0000482 /// access expression, this is the type of the object whose member template
483 /// is being referenced.
484 ///
485 /// \param FirstQualifierInScope If the first part of a nested-name-specifier
486 /// also refers to a name within the current (lexical) scope, this is the
487 /// declaration it refers to.
488 ///
489 /// By default, transforms the template name by transforming the declarations
490 /// and nested-name-specifiers that occur within the template name.
491 /// Subclasses may override this function to provide alternate behavior.
Craig Topperc3ec1492014-05-26 06:22:03 +0000492 TemplateName
493 TransformTemplateName(CXXScopeSpec &SS, TemplateName Name,
494 SourceLocation NameLoc,
495 QualType ObjectType = QualType(),
496 NamedDecl *FirstQualifierInScope = nullptr);
Douglas Gregor9db53502011-03-02 18:07:45 +0000497
Douglas Gregord6ff3322009-08-04 16:50:30 +0000498 /// \brief Transform the given template argument.
499 ///
Mike Stump11289f42009-09-09 15:08:12 +0000500 /// By default, this operation transforms the type, expression, or
501 /// declaration stored within the template argument and constructs a
Douglas Gregore922c772009-08-04 22:27:00 +0000502 /// new template argument from the transformed result. Subclasses may
503 /// override this function to provide alternate behavior.
John McCall0ad16662009-10-29 08:12:44 +0000504 ///
505 /// Returns true if there was an error.
506 bool TransformTemplateArgument(const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +0000507 TemplateArgumentLoc &Output,
508 bool Uneval = false);
John McCall0ad16662009-10-29 08:12:44 +0000509
Douglas Gregor62e06f22010-12-20 17:31:10 +0000510 /// \brief Transform the given set of template arguments.
511 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000512 /// By default, this operation transforms all of the template arguments
Douglas Gregor62e06f22010-12-20 17:31:10 +0000513 /// in the input set using \c TransformTemplateArgument(), and appends
514 /// the transformed arguments to the output list.
515 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000516 /// Note that this overload of \c TransformTemplateArguments() is merely
517 /// a convenience function. Subclasses that wish to override this behavior
518 /// should override the iterator-based member template version.
519 ///
Douglas Gregor62e06f22010-12-20 17:31:10 +0000520 /// \param Inputs The set of template arguments to be transformed.
521 ///
522 /// \param NumInputs The number of template arguments in \p Inputs.
523 ///
524 /// \param Outputs The set of transformed template arguments output by this
525 /// routine.
526 ///
527 /// Returns true if an error occurred.
528 bool TransformTemplateArguments(const TemplateArgumentLoc *Inputs,
529 unsigned NumInputs,
Richard Smithd784e682015-09-23 21:41:42 +0000530 TemplateArgumentListInfo &Outputs,
531 bool Uneval = false) {
532 return TransformTemplateArguments(Inputs, Inputs + NumInputs, Outputs,
533 Uneval);
Douglas Gregorfe921a72010-12-20 23:36:19 +0000534 }
Douglas Gregor42cafa82010-12-20 17:42:22 +0000535
536 /// \brief Transform the given set of template arguments.
537 ///
Chad Rosier1dcde962012-08-08 18:46:20 +0000538 /// By default, this operation transforms all of the template arguments
Douglas Gregor42cafa82010-12-20 17:42:22 +0000539 /// in the input set using \c TransformTemplateArgument(), and appends
Chad Rosier1dcde962012-08-08 18:46:20 +0000540 /// the transformed arguments to the output list.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000541 ///
Douglas Gregorfe921a72010-12-20 23:36:19 +0000542 /// \param First An iterator to the first template argument.
543 ///
544 /// \param Last An iterator one step past the last template argument.
Douglas Gregor42cafa82010-12-20 17:42:22 +0000545 ///
546 /// \param Outputs The set of transformed template arguments output by this
547 /// routine.
548 ///
549 /// Returns true if an error occurred.
Douglas Gregorfe921a72010-12-20 23:36:19 +0000550 template<typename InputIterator>
551 bool TransformTemplateArguments(InputIterator First,
552 InputIterator Last,
Richard Smithd784e682015-09-23 21:41:42 +0000553 TemplateArgumentListInfo &Outputs,
554 bool Uneval = false);
Douglas Gregor42cafa82010-12-20 17:42:22 +0000555
John McCall0ad16662009-10-29 08:12:44 +0000556 /// \brief Fakes up a TemplateArgumentLoc for a given TemplateArgument.
557 void InventTemplateArgumentLoc(const TemplateArgument &Arg,
558 TemplateArgumentLoc &ArgLoc);
559
John McCallbcd03502009-12-07 02:54:59 +0000560 /// \brief Fakes up a TypeSourceInfo for a type.
561 TypeSourceInfo *InventTypeSourceInfo(QualType T) {
562 return SemaRef.Context.getTrivialTypeSourceInfo(T,
John McCall0ad16662009-10-29 08:12:44 +0000563 getDerived().getBaseLocation());
564 }
Mike Stump11289f42009-09-09 15:08:12 +0000565
John McCall550e0c22009-10-21 00:40:46 +0000566#define ABSTRACT_TYPELOC(CLASS, PARENT)
567#define TYPELOC(CLASS, PARENT) \
John McCall31f82722010-11-12 08:19:04 +0000568 QualType Transform##CLASS##Type(TypeLocBuilder &TLB, CLASS##TypeLoc T);
John McCall550e0c22009-10-21 00:40:46 +0000569#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +0000570
Richard Smith2e321552014-11-12 02:00:47 +0000571 template<typename Fn>
Douglas Gregor3024f072012-04-16 07:05:22 +0000572 QualType TransformFunctionProtoType(TypeLocBuilder &TLB,
573 FunctionProtoTypeLoc TL,
574 CXXRecordDecl *ThisContext,
Richard Smith2e321552014-11-12 02:00:47 +0000575 unsigned ThisTypeQuals,
576 Fn TransformExceptionSpec);
577
578 bool TransformExceptionSpec(SourceLocation Loc,
579 FunctionProtoType::ExceptionSpecInfo &ESI,
580 SmallVectorImpl<QualType> &Exceptions,
581 bool &Changed);
Douglas Gregor3024f072012-04-16 07:05:22 +0000582
David Majnemerfad8f482013-10-15 09:33:02 +0000583 StmtResult TransformSEHHandler(Stmt *Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +0000584
Chad Rosier1dcde962012-08-08 18:46:20 +0000585 QualType
John McCall31f82722010-11-12 08:19:04 +0000586 TransformTemplateSpecializationType(TypeLocBuilder &TLB,
587 TemplateSpecializationTypeLoc TL,
588 TemplateName Template);
589
Chad Rosier1dcde962012-08-08 18:46:20 +0000590 QualType
John McCall31f82722010-11-12 08:19:04 +0000591 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
592 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +0000593 TemplateName Template,
594 CXXScopeSpec &SS);
Douglas Gregor5a064722011-02-28 17:23:35 +0000595
Nico Weberc153d242014-07-28 00:02:09 +0000596 QualType TransformDependentTemplateSpecializationType(
597 TypeLocBuilder &TLB, DependentTemplateSpecializationTypeLoc TL,
598 NestedNameSpecifierLoc QualifierLoc);
Douglas Gregora7a795b2011-03-01 20:11:18 +0000599
John McCall58f10c32010-03-11 09:03:00 +0000600 /// \brief Transforms the parameters of a function type into the
601 /// given vectors.
602 ///
603 /// The result vectors should be kept in sync; null entries in the
604 /// variables vector are acceptable.
605 ///
606 /// Return true on error.
Douglas Gregordd472162011-01-07 00:20:55 +0000607 bool TransformFunctionTypeParams(SourceLocation Loc,
608 ParmVarDecl **Params, unsigned NumParams,
609 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +0000610 SmallVectorImpl<QualType> &PTypes,
611 SmallVectorImpl<ParmVarDecl*> *PVars);
John McCall58f10c32010-03-11 09:03:00 +0000612
613 /// \brief Transforms a single function-type parameter. Return null
614 /// on error.
John McCall8fb0d9d2011-05-01 22:35:37 +0000615 ///
616 /// \param indexAdjustment - A number to add to the parameter's
617 /// scope index; can be negative
Douglas Gregor715e4612011-01-14 22:40:04 +0000618 ParmVarDecl *TransformFunctionTypeParam(ParmVarDecl *OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +0000619 int indexAdjustment,
David Blaikie05785d12013-02-20 22:23:23 +0000620 Optional<unsigned> NumExpansions,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +0000621 bool ExpectParameterPack);
John McCall58f10c32010-03-11 09:03:00 +0000622
John McCall31f82722010-11-12 08:19:04 +0000623 QualType TransformReferenceType(TypeLocBuilder &TLB, ReferenceTypeLoc TL);
John McCall0ad16662009-10-29 08:12:44 +0000624
John McCalldadc5752010-08-24 06:29:42 +0000625 StmtResult TransformCompoundStmt(CompoundStmt *S, bool IsStmtExpr);
626 ExprResult TransformCXXNamedCastExpr(CXXNamedCastExpr *E);
Richard Smith2589b9802012-07-25 03:56:55 +0000627
Faisal Vali2cba1332013-10-23 06:44:28 +0000628 TemplateParameterList *TransformTemplateParameterList(
629 TemplateParameterList *TPL) {
630 return TPL;
631 }
632
Richard Smithdb2630f2012-10-21 03:28:35 +0000633 ExprResult TransformAddressOfOperand(Expr *E);
Reid Kleckner32506ed2014-06-12 23:03:48 +0000634
Richard Smithdb2630f2012-10-21 03:28:35 +0000635 ExprResult TransformDependentScopeDeclRefExpr(DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +0000636 bool IsAddressOfOperand,
637 TypeSourceInfo **RecoveryTSI);
638
639 ExprResult TransformParenDependentScopeDeclRefExpr(
640 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool IsAddressOfOperand,
641 TypeSourceInfo **RecoveryTSI);
642
Alexey Bataev1b59ab52014-02-27 08:29:12 +0000643 StmtResult TransformOMPExecutableDirective(OMPExecutableDirective *S);
Richard Smithdb2630f2012-10-21 03:28:35 +0000644
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000645// FIXME: We use LLVM_ATTRIBUTE_NOINLINE because inlining causes a ridiculous
646// amount of stack usage with clang.
Douglas Gregorebe10102009-08-20 07:17:43 +0000647#define STMT(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000648 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000649 StmtResult Transform##Node(Node *S);
Douglas Gregora16548e2009-08-11 05:31:07 +0000650#define EXPR(Node, Parent) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000651 LLVM_ATTRIBUTE_NOINLINE \
John McCalldadc5752010-08-24 06:29:42 +0000652 ExprResult Transform##Node(Node *E);
Alexis Huntabb2ac82010-05-18 06:22:21 +0000653#define ABSTRACT_STMT(Stmt)
Alexis Hunt656bb312010-05-05 15:24:00 +0000654#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +0000655
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000656#define OPENMP_CLAUSE(Name, Class) \
Eli Friedmanbc8c7342013-09-06 01:13:30 +0000657 LLVM_ATTRIBUTE_NOINLINE \
Alexey Bataev5ec3eb12013-07-19 03:13:43 +0000658 OMPClause *Transform ## Class(Class *S);
659#include "clang/Basic/OpenMPKinds.def"
660
Douglas Gregord6ff3322009-08-04 16:50:30 +0000661 /// \brief Build a new pointer type given its pointee type.
662 ///
663 /// By default, performs semantic analysis when building the pointer type.
664 /// Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000665 QualType RebuildPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000666
667 /// \brief Build a new block pointer type given its pointee type.
668 ///
Mike Stump11289f42009-09-09 15:08:12 +0000669 /// By default, performs semantic analysis when building the block pointer
Douglas Gregord6ff3322009-08-04 16:50:30 +0000670 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000671 QualType RebuildBlockPointerType(QualType PointeeType, SourceLocation Sigil);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000672
John McCall70dd5f62009-10-30 00:06:24 +0000673 /// \brief Build a new reference type given the type it references.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000674 ///
John McCall70dd5f62009-10-30 00:06:24 +0000675 /// By default, performs semantic analysis when building the
676 /// reference type. Subclasses may override this routine to provide
677 /// different behavior.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000678 ///
John McCall70dd5f62009-10-30 00:06:24 +0000679 /// \param LValue whether the type was written with an lvalue sigil
680 /// or an rvalue sigil.
681 QualType RebuildReferenceType(QualType ReferentType,
682 bool LValue,
683 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000684
Douglas Gregord6ff3322009-08-04 16:50:30 +0000685 /// \brief Build a new member pointer type given the pointee type and the
686 /// class type it refers into.
687 ///
688 /// By default, performs semantic analysis when building the member pointer
689 /// type. Subclasses may override this routine to provide different behavior.
John McCall70dd5f62009-10-30 00:06:24 +0000690 QualType RebuildMemberPointerType(QualType PointeeType, QualType ClassType,
691 SourceLocation Sigil);
Mike Stump11289f42009-09-09 15:08:12 +0000692
Douglas Gregor9bda6cf2015-07-07 03:58:14 +0000693 /// \brief Build an Objective-C object type.
694 ///
695 /// By default, performs semantic analysis when building the object type.
696 /// Subclasses may override this routine to provide different behavior.
697 QualType RebuildObjCObjectType(QualType BaseType,
698 SourceLocation Loc,
699 SourceLocation TypeArgsLAngleLoc,
700 ArrayRef<TypeSourceInfo *> TypeArgs,
701 SourceLocation TypeArgsRAngleLoc,
702 SourceLocation ProtocolLAngleLoc,
703 ArrayRef<ObjCProtocolDecl *> Protocols,
704 ArrayRef<SourceLocation> ProtocolLocs,
705 SourceLocation ProtocolRAngleLoc);
706
707 /// \brief Build a new Objective-C object pointer type given the pointee type.
708 ///
709 /// By default, directly builds the pointer type, with no additional semantic
710 /// analysis.
711 QualType RebuildObjCObjectPointerType(QualType PointeeType,
712 SourceLocation Star);
713
Douglas Gregord6ff3322009-08-04 16:50:30 +0000714 /// \brief Build a new array type given the element type, size
715 /// modifier, size of the array (if known), size expression, and index type
716 /// qualifiers.
717 ///
718 /// By default, performs semantic analysis when building the array type.
719 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000720 /// Also by default, all of the other Rebuild*Array
Douglas Gregord6ff3322009-08-04 16:50:30 +0000721 QualType RebuildArrayType(QualType ElementType,
722 ArrayType::ArraySizeModifier SizeMod,
723 const llvm::APInt *Size,
724 Expr *SizeExpr,
725 unsigned IndexTypeQuals,
726 SourceRange BracketsRange);
Mike Stump11289f42009-09-09 15:08:12 +0000727
Douglas Gregord6ff3322009-08-04 16:50:30 +0000728 /// \brief Build a new constant array type given the element type, size
729 /// modifier, (known) size of the array, and index type qualifiers.
730 ///
731 /// By default, performs semantic analysis when building the array type.
732 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000733 QualType RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000734 ArrayType::ArraySizeModifier SizeMod,
735 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +0000736 unsigned IndexTypeQuals,
737 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000738
Douglas Gregord6ff3322009-08-04 16:50:30 +0000739 /// \brief Build a new incomplete array type given the element type, size
740 /// modifier, and index type qualifiers.
741 ///
742 /// By default, performs semantic analysis when building the array type.
743 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000744 QualType RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000745 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +0000746 unsigned IndexTypeQuals,
747 SourceRange BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000748
Mike Stump11289f42009-09-09 15:08:12 +0000749 /// \brief Build a new variable-length array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000750 /// size modifier, size expression, and index type qualifiers.
751 ///
752 /// By default, performs semantic analysis when building the array type.
753 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000754 QualType RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000755 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000756 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000757 unsigned IndexTypeQuals,
758 SourceRange BracketsRange);
759
Mike Stump11289f42009-09-09 15:08:12 +0000760 /// \brief Build a new dependent-sized array type given the element type,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000761 /// size modifier, size expression, and index type qualifiers.
762 ///
763 /// By default, performs semantic analysis when building the array type.
764 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000765 QualType RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000766 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +0000767 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000768 unsigned IndexTypeQuals,
769 SourceRange BracketsRange);
770
771 /// \brief Build a new vector type given the element type and
772 /// number of elements.
773 ///
774 /// By default, performs semantic analysis when building the vector type.
775 /// Subclasses may override this routine to provide different behavior.
John Thompson22334602010-02-05 00:12:22 +0000776 QualType RebuildVectorType(QualType ElementType, unsigned NumElements,
Bob Wilsonaeb56442010-11-10 21:56:12 +0000777 VectorType::VectorKind VecKind);
Mike Stump11289f42009-09-09 15:08:12 +0000778
Douglas Gregord6ff3322009-08-04 16:50:30 +0000779 /// \brief Build a new extended vector type given the element type and
780 /// number of elements.
781 ///
782 /// By default, performs semantic analysis when building the vector type.
783 /// Subclasses may override this routine to provide different behavior.
784 QualType RebuildExtVectorType(QualType ElementType, unsigned NumElements,
785 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000786
787 /// \brief Build a new potentially dependently-sized extended vector type
Douglas Gregord6ff3322009-08-04 16:50:30 +0000788 /// given the element type and number of elements.
789 ///
790 /// By default, performs semantic analysis when building the vector type.
791 /// Subclasses may override this routine to provide different behavior.
Mike Stump11289f42009-09-09 15:08:12 +0000792 QualType RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +0000793 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +0000794 SourceLocation AttributeLoc);
Mike Stump11289f42009-09-09 15:08:12 +0000795
Douglas Gregord6ff3322009-08-04 16:50:30 +0000796 /// \brief Build a new function type.
797 ///
798 /// By default, performs semantic analysis when building the function type.
799 /// Subclasses may override this routine to provide different behavior.
800 QualType RebuildFunctionProtoType(QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +0000801 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +0000802 const FunctionProtoType::ExtProtoInfo &EPI);
Mike Stump11289f42009-09-09 15:08:12 +0000803
John McCall550e0c22009-10-21 00:40:46 +0000804 /// \brief Build a new unprototyped function type.
805 QualType RebuildFunctionNoProtoType(QualType ResultType);
806
John McCallb96ec562009-12-04 22:46:56 +0000807 /// \brief Rebuild an unresolved typename type, given the decl that
808 /// the UnresolvedUsingTypenameDecl was transformed to.
809 QualType RebuildUnresolvedUsingType(Decl *D);
810
Douglas Gregord6ff3322009-08-04 16:50:30 +0000811 /// \brief Build a new typedef type.
Richard Smithdda56e42011-04-15 14:24:37 +0000812 QualType RebuildTypedefType(TypedefNameDecl *Typedef) {
Douglas Gregord6ff3322009-08-04 16:50:30 +0000813 return SemaRef.Context.getTypeDeclType(Typedef);
814 }
815
816 /// \brief Build a new class/struct/union type.
817 QualType RebuildRecordType(RecordDecl *Record) {
818 return SemaRef.Context.getTypeDeclType(Record);
819 }
820
821 /// \brief Build a new Enum type.
822 QualType RebuildEnumType(EnumDecl *Enum) {
823 return SemaRef.Context.getTypeDeclType(Enum);
824 }
John McCallfcc33b02009-09-05 00:15:47 +0000825
Mike Stump11289f42009-09-09 15:08:12 +0000826 /// \brief Build a new typeof(expr) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000827 ///
828 /// By default, performs semantic analysis when building the typeof type.
829 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000830 QualType RebuildTypeOfExprType(Expr *Underlying, SourceLocation Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +0000831
Mike Stump11289f42009-09-09 15:08:12 +0000832 /// \brief Build a new typeof(type) type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000833 ///
834 /// By default, builds a new TypeOfType with the given underlying type.
835 QualType RebuildTypeOfType(QualType Underlying);
836
Alexis Hunte852b102011-05-24 22:41:36 +0000837 /// \brief Build a new unary transform type.
838 QualType RebuildUnaryTransformType(QualType BaseType,
839 UnaryTransformType::UTTKind UKind,
840 SourceLocation Loc);
841
Richard Smith74aeef52013-04-26 16:15:35 +0000842 /// \brief Build a new C++11 decltype type.
Douglas Gregord6ff3322009-08-04 16:50:30 +0000843 ///
844 /// By default, performs semantic analysis when building the decltype type.
845 /// Subclasses may override this routine to provide different behavior.
John McCall36e7fe32010-10-12 00:20:44 +0000846 QualType RebuildDecltypeType(Expr *Underlying, SourceLocation Loc);
Mike Stump11289f42009-09-09 15:08:12 +0000847
Richard Smith74aeef52013-04-26 16:15:35 +0000848 /// \brief Build a new C++11 auto type.
Richard Smith30482bc2011-02-20 03:19:35 +0000849 ///
850 /// By default, builds a new AutoType with the given deduced type.
Richard Smith74aeef52013-04-26 16:15:35 +0000851 QualType RebuildAutoType(QualType Deduced, bool IsDecltypeAuto) {
Richard Smith27d807c2013-04-30 13:56:41 +0000852 // Note, IsDependent is always false here: we implicitly convert an 'auto'
853 // which has been deduced to a dependent type into an undeduced 'auto', so
854 // that we'll retry deduction after the transformation.
Faisal Vali2b391ab2013-09-26 19:54:12 +0000855 return SemaRef.Context.getAutoType(Deduced, IsDecltypeAuto,
856 /*IsDependent*/ false);
Richard Smith30482bc2011-02-20 03:19:35 +0000857 }
858
Douglas Gregord6ff3322009-08-04 16:50:30 +0000859 /// \brief Build a new template specialization type.
860 ///
861 /// By default, performs semantic analysis when building the template
862 /// specialization type. Subclasses may override this routine to provide
863 /// different behavior.
864 QualType RebuildTemplateSpecializationType(TemplateName Template,
John McCall0ad16662009-10-29 08:12:44 +0000865 SourceLocation TemplateLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000866 TemplateArgumentListInfo &Args);
Mike Stump11289f42009-09-09 15:08:12 +0000867
Abramo Bagnara924a8f32010-12-10 16:29:40 +0000868 /// \brief Build a new parenthesized type.
869 ///
870 /// By default, builds a new ParenType type from the inner type.
871 /// Subclasses may override this routine to provide different behavior.
872 QualType RebuildParenType(QualType InnerType) {
873 return SemaRef.Context.getParenType(InnerType);
874 }
875
Douglas Gregord6ff3322009-08-04 16:50:30 +0000876 /// \brief Build a new qualified name type.
877 ///
Abramo Bagnara6150c882010-05-11 21:36:43 +0000878 /// By default, builds a new ElaboratedType type from the keyword,
879 /// the nested-name-specifier and the named type.
880 /// Subclasses may override this routine to provide different behavior.
John McCall954b5de2010-11-04 19:04:38 +0000881 QualType RebuildElaboratedType(SourceLocation KeywordLoc,
882 ElaboratedTypeKeyword Keyword,
Douglas Gregor844cb502011-03-01 18:12:44 +0000883 NestedNameSpecifierLoc QualifierLoc,
884 QualType Named) {
Chad Rosier1dcde962012-08-08 18:46:20 +0000885 return SemaRef.Context.getElaboratedType(Keyword,
886 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor844cb502011-03-01 18:12:44 +0000887 Named);
Mike Stump11289f42009-09-09 15:08:12 +0000888 }
Douglas Gregord6ff3322009-08-04 16:50:30 +0000889
890 /// \brief Build a new typename type that refers to a template-id.
891 ///
Abramo Bagnarad7548482010-05-19 21:37:53 +0000892 /// By default, builds a new DependentNameType type from the
893 /// nested-name-specifier and the given type. Subclasses may override
894 /// this routine to provide different behavior.
John McCallc392f372010-06-11 00:33:02 +0000895 QualType RebuildDependentTemplateSpecializationType(
Douglas Gregora7a795b2011-03-01 20:11:18 +0000896 ElaboratedTypeKeyword Keyword,
897 NestedNameSpecifierLoc QualifierLoc,
898 const IdentifierInfo *Name,
899 SourceLocation NameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +0000900 TemplateArgumentListInfo &Args) {
Douglas Gregora7a795b2011-03-01 20:11:18 +0000901 // Rebuild the template name.
902 // TODO: avoid TemplateName abstraction
Douglas Gregor9db53502011-03-02 18:07:45 +0000903 CXXScopeSpec SS;
904 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +0000905 TemplateName InstName
Craig Topperc3ec1492014-05-26 06:22:03 +0000906 = getDerived().RebuildTemplateName(SS, *Name, NameLoc, QualType(),
907 nullptr);
Chad Rosier1dcde962012-08-08 18:46:20 +0000908
Douglas Gregora7a795b2011-03-01 20:11:18 +0000909 if (InstName.isNull())
910 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000911
Douglas Gregora7a795b2011-03-01 20:11:18 +0000912 // If it's still dependent, make a dependent specialization.
913 if (InstName.getAsDependentTemplateName())
Chad Rosier1dcde962012-08-08 18:46:20 +0000914 return SemaRef.Context.getDependentTemplateSpecializationType(Keyword,
915 QualifierLoc.getNestedNameSpecifier(),
916 Name,
Douglas Gregora7a795b2011-03-01 20:11:18 +0000917 Args);
Chad Rosier1dcde962012-08-08 18:46:20 +0000918
Douglas Gregora7a795b2011-03-01 20:11:18 +0000919 // Otherwise, make an elaborated type wrapping a non-dependent
920 // specialization.
921 QualType T =
922 getDerived().RebuildTemplateSpecializationType(InstName, NameLoc, Args);
923 if (T.isNull()) return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +0000924
Craig Topperc3ec1492014-05-26 06:22:03 +0000925 if (Keyword == ETK_None && QualifierLoc.getNestedNameSpecifier() == nullptr)
Douglas Gregora7a795b2011-03-01 20:11:18 +0000926 return T;
Chad Rosier1dcde962012-08-08 18:46:20 +0000927
928 return SemaRef.Context.getElaboratedType(Keyword,
929 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregora7a795b2011-03-01 20:11:18 +0000930 T);
931 }
932
Douglas Gregord6ff3322009-08-04 16:50:30 +0000933 /// \brief Build a new typename type that refers to an identifier.
934 ///
935 /// By default, performs semantic analysis when building the typename type
Abramo Bagnarad7548482010-05-19 21:37:53 +0000936 /// (or elaborated type). Subclasses may override this routine to provide
Douglas Gregord6ff3322009-08-04 16:50:30 +0000937 /// different behavior.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000938 QualType RebuildDependentNameType(ElaboratedTypeKeyword Keyword,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000939 SourceLocation KeywordLoc,
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000940 NestedNameSpecifierLoc QualifierLoc,
941 const IdentifierInfo *Id,
Abramo Bagnarad7548482010-05-19 21:37:53 +0000942 SourceLocation IdLoc) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000943 CXXScopeSpec SS;
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000944 SS.Adopt(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +0000945
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000946 if (QualifierLoc.getNestedNameSpecifier()->isDependent()) {
Douglas Gregore677daf2010-03-31 22:19:08 +0000947 // If the name is still dependent, just build a new dependent name type.
948 if (!SemaRef.computeDeclContext(SS))
Chad Rosier1dcde962012-08-08 18:46:20 +0000949 return SemaRef.Context.getDependentNameType(Keyword,
950 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000951 Id);
Douglas Gregore677daf2010-03-31 22:19:08 +0000952 }
953
Abramo Bagnara6150c882010-05-11 21:36:43 +0000954 if (Keyword == ETK_None || Keyword == ETK_Typename)
Douglas Gregor3d0da5f2011-03-01 01:34:45 +0000955 return SemaRef.CheckTypenameType(Keyword, KeywordLoc, QualifierLoc,
Douglas Gregor9cbc22b2011-02-28 22:42:13 +0000956 *Id, IdLoc);
Abramo Bagnara6150c882010-05-11 21:36:43 +0000957
958 TagTypeKind Kind = TypeWithKeyword::getTagTypeKindForKeyword(Keyword);
959
Abramo Bagnarad7548482010-05-19 21:37:53 +0000960 // We had a dependent elaborated-type-specifier that has been transformed
Douglas Gregore677daf2010-03-31 22:19:08 +0000961 // into a non-dependent elaborated-type-specifier. Find the tag we're
962 // referring to.
Abramo Bagnarad7548482010-05-19 21:37:53 +0000963 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
Douglas Gregore677daf2010-03-31 22:19:08 +0000964 DeclContext *DC = SemaRef.computeDeclContext(SS, false);
965 if (!DC)
966 return QualType();
967
John McCallbf8c5192010-05-27 06:40:31 +0000968 if (SemaRef.RequireCompleteDeclContext(SS, DC))
969 return QualType();
970
Craig Topperc3ec1492014-05-26 06:22:03 +0000971 TagDecl *Tag = nullptr;
Douglas Gregore677daf2010-03-31 22:19:08 +0000972 SemaRef.LookupQualifiedName(Result, DC);
973 switch (Result.getResultKind()) {
974 case LookupResult::NotFound:
975 case LookupResult::NotFoundInCurrentInstantiation:
976 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000977
Douglas Gregore677daf2010-03-31 22:19:08 +0000978 case LookupResult::Found:
979 Tag = Result.getAsSingle<TagDecl>();
980 break;
Chad Rosier1dcde962012-08-08 18:46:20 +0000981
Douglas Gregore677daf2010-03-31 22:19:08 +0000982 case LookupResult::FoundOverloaded:
983 case LookupResult::FoundUnresolvedValue:
984 llvm_unreachable("Tag lookup cannot find non-tags");
Chad Rosier1dcde962012-08-08 18:46:20 +0000985
Douglas Gregore677daf2010-03-31 22:19:08 +0000986 case LookupResult::Ambiguous:
987 // Let the LookupResult structure handle ambiguities.
988 return QualType();
989 }
990
991 if (!Tag) {
Nick Lewycky0c438082011-01-24 19:01:04 +0000992 // Check where the name exists but isn't a tag type and use that to emit
993 // better diagnostics.
994 LookupResult Result(SemaRef, Id, IdLoc, Sema::LookupTagName);
995 SemaRef.LookupQualifiedName(Result, DC);
996 switch (Result.getResultKind()) {
997 case LookupResult::Found:
998 case LookupResult::FoundOverloaded:
999 case LookupResult::FoundUnresolvedValue: {
Richard Smith3f1b5d02011-05-05 21:57:07 +00001000 NamedDecl *SomeDecl = Result.getRepresentativeDecl();
Nick Lewycky0c438082011-01-24 19:01:04 +00001001 unsigned Kind = 0;
1002 if (isa<TypedefDecl>(SomeDecl)) Kind = 1;
Richard Smithdda56e42011-04-15 14:24:37 +00001003 else if (isa<TypeAliasDecl>(SomeDecl)) Kind = 2;
1004 else if (isa<ClassTemplateDecl>(SomeDecl)) Kind = 3;
Nick Lewycky0c438082011-01-24 19:01:04 +00001005 SemaRef.Diag(IdLoc, diag::err_tag_reference_non_tag) << Kind;
1006 SemaRef.Diag(SomeDecl->getLocation(), diag::note_declared_at);
1007 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00001008 }
Nick Lewycky0c438082011-01-24 19:01:04 +00001009 default:
Nick Lewycky0c438082011-01-24 19:01:04 +00001010 SemaRef.Diag(IdLoc, diag::err_not_tag_in_scope)
Stephan Tolksdorfeb7708d2014-03-13 20:34:03 +00001011 << Kind << Id << DC << QualifierLoc.getSourceRange();
Nick Lewycky0c438082011-01-24 19:01:04 +00001012 break;
1013 }
Douglas Gregore677daf2010-03-31 22:19:08 +00001014 return QualType();
1015 }
Abramo Bagnara6150c882010-05-11 21:36:43 +00001016
Richard Trieucaa33d32011-06-10 03:11:26 +00001017 if (!SemaRef.isAcceptableTagRedeclaration(Tag, Kind, /*isDefinition*/false,
Justin Bognerc6ecb7c2015-07-10 23:05:47 +00001018 IdLoc, Id)) {
Abramo Bagnarad7548482010-05-19 21:37:53 +00001019 SemaRef.Diag(KeywordLoc, diag::err_use_with_wrong_tag) << Id;
Douglas Gregore677daf2010-03-31 22:19:08 +00001020 SemaRef.Diag(Tag->getLocation(), diag::note_previous_use);
1021 return QualType();
1022 }
1023
1024 // Build the elaborated-type-specifier type.
1025 QualType T = SemaRef.Context.getTypeDeclType(Tag);
Chad Rosier1dcde962012-08-08 18:46:20 +00001026 return SemaRef.Context.getElaboratedType(Keyword,
1027 QualifierLoc.getNestedNameSpecifier(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00001028 T);
Douglas Gregor1135c352009-08-06 05:28:30 +00001029 }
Mike Stump11289f42009-09-09 15:08:12 +00001030
Douglas Gregor822d0302011-01-12 17:07:58 +00001031 /// \brief Build a new pack expansion type.
1032 ///
1033 /// By default, builds a new PackExpansionType type from the given pattern.
1034 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001035 QualType RebuildPackExpansionType(QualType Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00001036 SourceRange PatternRange,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001037 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00001038 Optional<unsigned> NumExpansions) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00001039 return getSema().CheckPackExpansion(Pattern, PatternRange, EllipsisLoc,
1040 NumExpansions);
Douglas Gregor822d0302011-01-12 17:07:58 +00001041 }
1042
Eli Friedman0dfb8892011-10-06 23:00:33 +00001043 /// \brief Build a new atomic type given its value type.
1044 ///
1045 /// By default, performs semantic analysis when building the atomic type.
1046 /// Subclasses may override this routine to provide different behavior.
1047 QualType RebuildAtomicType(QualType ValueType, SourceLocation KWLoc);
1048
Douglas Gregor71dc5092009-08-06 06:41:21 +00001049 /// \brief Build a new template name given a nested name specifier, a flag
1050 /// indicating whether the "template" keyword was provided, and the template
1051 /// that the template name refers to.
1052 ///
1053 /// By default, builds the new template name directly. Subclasses may override
1054 /// this routine to provide different behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001055 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +00001056 bool TemplateKW,
1057 TemplateDecl *Template);
1058
Douglas Gregor71dc5092009-08-06 06:41:21 +00001059 /// \brief Build a new template name given a nested name specifier and the
1060 /// name that is referred to as a template.
1061 ///
1062 /// By default, performs semantic analysis to determine whether the name can
1063 /// be resolved to a specific template, then builds the appropriate kind of
1064 /// template name. Subclasses may override this routine to provide different
1065 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001066 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
1067 const IdentifierInfo &Name,
1068 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +00001069 QualType ObjectType,
1070 NamedDecl *FirstQualifierInScope);
Mike Stump11289f42009-09-09 15:08:12 +00001071
Douglas Gregor71395fa2009-11-04 00:56:37 +00001072 /// \brief Build a new template name given a nested name specifier and the
1073 /// overloaded operator name that is referred to as a template.
1074 ///
1075 /// By default, performs semantic analysis to determine whether the name can
1076 /// be resolved to a specific template, then builds the appropriate kind of
1077 /// template name. Subclasses may override this routine to provide different
1078 /// behavior.
Douglas Gregor9db53502011-03-02 18:07:45 +00001079 TemplateName RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001080 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +00001081 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +00001082 QualType ObjectType);
Douglas Gregor5590be02011-01-15 06:45:20 +00001083
1084 /// \brief Build a new template name given a template template parameter pack
Chad Rosier1dcde962012-08-08 18:46:20 +00001085 /// and the
Douglas Gregor5590be02011-01-15 06:45:20 +00001086 ///
1087 /// By default, performs semantic analysis to determine whether the name can
1088 /// be resolved to a specific template, then builds the appropriate kind of
1089 /// template name. Subclasses may override this routine to provide different
1090 /// behavior.
1091 TemplateName RebuildTemplateName(TemplateTemplateParmDecl *Param,
1092 const TemplateArgument &ArgPack) {
1093 return getSema().Context.getSubstTemplateTemplateParmPack(Param, ArgPack);
1094 }
1095
Douglas Gregorebe10102009-08-20 07:17:43 +00001096 /// \brief Build a new compound statement.
1097 ///
1098 /// By default, performs semantic analysis to build the new statement.
1099 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001100 StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001101 MultiStmtArg Statements,
1102 SourceLocation RBraceLoc,
1103 bool IsStmtExpr) {
John McCallb268a282010-08-23 23:25:46 +00001104 return getSema().ActOnCompoundStmt(LBraceLoc, RBraceLoc, Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00001105 IsStmtExpr);
1106 }
1107
1108 /// \brief Build a new case statement.
1109 ///
1110 /// By default, performs semantic analysis to build the new statement.
1111 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001112 StmtResult RebuildCaseStmt(SourceLocation CaseLoc,
John McCallb268a282010-08-23 23:25:46 +00001113 Expr *LHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001114 SourceLocation EllipsisLoc,
John McCallb268a282010-08-23 23:25:46 +00001115 Expr *RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001116 SourceLocation ColonLoc) {
John McCallb268a282010-08-23 23:25:46 +00001117 return getSema().ActOnCaseStmt(CaseLoc, LHS, EllipsisLoc, RHS,
Douglas Gregorebe10102009-08-20 07:17:43 +00001118 ColonLoc);
1119 }
Mike Stump11289f42009-09-09 15:08:12 +00001120
Douglas Gregorebe10102009-08-20 07:17:43 +00001121 /// \brief Attach the body to a new case statement.
1122 ///
1123 /// By default, performs semantic analysis to build the new statement.
1124 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001125 StmtResult RebuildCaseStmtBody(Stmt *S, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001126 getSema().ActOnCaseStmtBody(S, Body);
1127 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00001128 }
Mike Stump11289f42009-09-09 15:08:12 +00001129
Douglas Gregorebe10102009-08-20 07:17:43 +00001130 /// \brief Build a new default statement.
1131 ///
1132 /// By default, performs semantic analysis to build the new statement.
1133 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001134 StmtResult RebuildDefaultStmt(SourceLocation DefaultLoc,
Douglas Gregorebe10102009-08-20 07:17:43 +00001135 SourceLocation ColonLoc,
John McCallb268a282010-08-23 23:25:46 +00001136 Stmt *SubStmt) {
1137 return getSema().ActOnDefaultStmt(DefaultLoc, ColonLoc, SubStmt,
Craig Topperc3ec1492014-05-26 06:22:03 +00001138 /*CurScope=*/nullptr);
Douglas Gregorebe10102009-08-20 07:17:43 +00001139 }
Mike Stump11289f42009-09-09 15:08:12 +00001140
Douglas Gregorebe10102009-08-20 07:17:43 +00001141 /// \brief Build a new label statement.
1142 ///
1143 /// By default, performs semantic analysis to build the new statement.
1144 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001145 StmtResult RebuildLabelStmt(SourceLocation IdentLoc, LabelDecl *L,
1146 SourceLocation ColonLoc, Stmt *SubStmt) {
1147 return SemaRef.ActOnLabelStmt(IdentLoc, L, ColonLoc, SubStmt);
Douglas Gregorebe10102009-08-20 07:17:43 +00001148 }
Mike Stump11289f42009-09-09 15:08:12 +00001149
Richard Smithc202b282012-04-14 00:33:13 +00001150 /// \brief Build a new label statement.
1151 ///
1152 /// By default, performs semantic analysis to build the new statement.
1153 /// Subclasses may override this routine to provide different behavior.
Alexander Kornienko20f6fc62012-07-09 10:04:07 +00001154 StmtResult RebuildAttributedStmt(SourceLocation AttrLoc,
1155 ArrayRef<const Attr*> Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00001156 Stmt *SubStmt) {
1157 return SemaRef.ActOnAttributedStmt(AttrLoc, Attrs, SubStmt);
1158 }
1159
Douglas Gregorebe10102009-08-20 07:17:43 +00001160 /// \brief Build a new "if" statement.
1161 ///
1162 /// By default, performs semantic analysis to build the new statement.
1163 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001164 StmtResult RebuildIfStmt(SourceLocation IfLoc, Sema::FullExprArg Cond,
Chad Rosier1dcde962012-08-08 18:46:20 +00001165 VarDecl *CondVar, Stmt *Then,
Chris Lattnercab02a62011-02-17 20:34:02 +00001166 SourceLocation ElseLoc, Stmt *Else) {
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00001167 return getSema().ActOnIfStmt(IfLoc, Cond, CondVar, Then, ElseLoc, Else);
Douglas Gregorebe10102009-08-20 07:17:43 +00001168 }
Mike Stump11289f42009-09-09 15:08:12 +00001169
Douglas Gregorebe10102009-08-20 07:17:43 +00001170 /// \brief Start building a new switch statement.
1171 ///
1172 /// By default, performs semantic analysis to build the new statement.
1173 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001174 StmtResult RebuildSwitchStmtStart(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001175 Expr *Cond, VarDecl *CondVar) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001176 return getSema().ActOnStartOfSwitchStmt(SwitchLoc, Cond,
John McCall48871652010-08-21 09:40:31 +00001177 CondVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00001178 }
Mike Stump11289f42009-09-09 15:08:12 +00001179
Douglas Gregorebe10102009-08-20 07:17:43 +00001180 /// \brief Attach the body to the switch statement.
1181 ///
1182 /// By default, performs semantic analysis to build the new statement.
1183 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001184 StmtResult RebuildSwitchStmtBody(SourceLocation SwitchLoc,
Chris Lattnercab02a62011-02-17 20:34:02 +00001185 Stmt *Switch, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001186 return getSema().ActOnFinishSwitchStmt(SwitchLoc, Switch, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001187 }
1188
1189 /// \brief Build a new while statement.
1190 ///
1191 /// By default, performs semantic analysis to build the new statement.
1192 /// Subclasses may override this routine to provide different behavior.
Chris Lattnercab02a62011-02-17 20:34:02 +00001193 StmtResult RebuildWhileStmt(SourceLocation WhileLoc, Sema::FullExprArg Cond,
1194 VarDecl *CondVar, Stmt *Body) {
John McCallb268a282010-08-23 23:25:46 +00001195 return getSema().ActOnWhileStmt(WhileLoc, Cond, CondVar, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001196 }
Mike Stump11289f42009-09-09 15:08:12 +00001197
Douglas Gregorebe10102009-08-20 07:17:43 +00001198 /// \brief Build a new do-while statement.
1199 ///
1200 /// By default, performs semantic analysis to build the new statement.
1201 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001202 StmtResult RebuildDoStmt(SourceLocation DoLoc, Stmt *Body,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001203 SourceLocation WhileLoc, SourceLocation LParenLoc,
1204 Expr *Cond, SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00001205 return getSema().ActOnDoStmt(DoLoc, Body, WhileLoc, LParenLoc,
1206 Cond, RParenLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001207 }
1208
1209 /// \brief Build a new for statement.
1210 ///
1211 /// By default, performs semantic analysis to build the new statement.
1212 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001213 StmtResult RebuildForStmt(SourceLocation ForLoc, SourceLocation LParenLoc,
Chad Rosier1dcde962012-08-08 18:46:20 +00001214 Stmt *Init, Sema::FullExprArg Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001215 VarDecl *CondVar, Sema::FullExprArg Inc,
1216 SourceLocation RParenLoc, Stmt *Body) {
Chad Rosier1dcde962012-08-08 18:46:20 +00001217 return getSema().ActOnForStmt(ForLoc, LParenLoc, Init, Cond,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001218 CondVar, Inc, RParenLoc, Body);
Douglas Gregorebe10102009-08-20 07:17:43 +00001219 }
Mike Stump11289f42009-09-09 15:08:12 +00001220
Douglas Gregorebe10102009-08-20 07:17:43 +00001221 /// \brief Build a new goto statement.
1222 ///
1223 /// By default, performs semantic analysis to build the new statement.
1224 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001225 StmtResult RebuildGotoStmt(SourceLocation GotoLoc, SourceLocation LabelLoc,
1226 LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00001227 return getSema().ActOnGotoStmt(GotoLoc, LabelLoc, Label);
Douglas Gregorebe10102009-08-20 07:17:43 +00001228 }
1229
1230 /// \brief Build a new indirect goto statement.
1231 ///
1232 /// By default, performs semantic analysis to build the new statement.
1233 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001234 StmtResult RebuildIndirectGotoStmt(SourceLocation GotoLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001235 SourceLocation StarLoc,
1236 Expr *Target) {
John McCallb268a282010-08-23 23:25:46 +00001237 return getSema().ActOnIndirectGotoStmt(GotoLoc, StarLoc, Target);
Douglas Gregorebe10102009-08-20 07:17:43 +00001238 }
Mike Stump11289f42009-09-09 15:08:12 +00001239
Douglas Gregorebe10102009-08-20 07:17:43 +00001240 /// \brief Build a new return statement.
1241 ///
1242 /// By default, performs semantic analysis to build the new statement.
1243 /// Subclasses may override this routine to provide different behavior.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001244 StmtResult RebuildReturnStmt(SourceLocation ReturnLoc, Expr *Result) {
Nick Lewyckyd78f92f2014-05-03 00:41:18 +00001245 return getSema().BuildReturnStmt(ReturnLoc, Result);
Douglas Gregorebe10102009-08-20 07:17:43 +00001246 }
Mike Stump11289f42009-09-09 15:08:12 +00001247
Douglas Gregorebe10102009-08-20 07:17:43 +00001248 /// \brief Build a new declaration statement.
1249 ///
1250 /// By default, performs semantic analysis to build the new statement.
1251 /// Subclasses may override this routine to provide different behavior.
Craig Toppere3d2ecbe2014-06-28 23:22:33 +00001252 StmtResult RebuildDeclStmt(MutableArrayRef<Decl *> Decls,
Rafael Espindolaab417692013-07-09 12:05:01 +00001253 SourceLocation StartLoc, SourceLocation EndLoc) {
1254 Sema::DeclGroupPtrTy DG = getSema().BuildDeclaratorGroup(Decls);
Richard Smith2abf6762011-02-23 00:37:57 +00001255 return getSema().ActOnDeclStmt(DG, StartLoc, EndLoc);
Douglas Gregorebe10102009-08-20 07:17:43 +00001256 }
Mike Stump11289f42009-09-09 15:08:12 +00001257
Anders Carlssonaaeef072010-01-24 05:50:09 +00001258 /// \brief Build a new inline asm statement.
1259 ///
1260 /// By default, performs semantic analysis to build the new statement.
1261 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001262 StmtResult RebuildGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
1263 bool IsVolatile, unsigned NumOutputs,
1264 unsigned NumInputs, IdentifierInfo **Names,
1265 MultiExprArg Constraints, MultiExprArg Exprs,
1266 Expr *AsmString, MultiExprArg Clobbers,
1267 SourceLocation RParenLoc) {
1268 return getSema().ActOnGCCAsmStmt(AsmLoc, IsSimple, IsVolatile, NumOutputs,
1269 NumInputs, Names, Constraints, Exprs,
1270 AsmString, Clobbers, RParenLoc);
Anders Carlssonaaeef072010-01-24 05:50:09 +00001271 }
Douglas Gregor306de2f2010-04-22 23:59:56 +00001272
Chad Rosier32503022012-06-11 20:47:18 +00001273 /// \brief Build a new MS style inline asm statement.
1274 ///
1275 /// By default, performs semantic analysis to build the new statement.
1276 /// Subclasses may override this routine to provide different behavior.
Chad Rosierde70e0e2012-08-25 00:11:56 +00001277 StmtResult RebuildMSAsmStmt(SourceLocation AsmLoc, SourceLocation LBraceLoc,
John McCallf413f5e2013-05-03 00:10:13 +00001278 ArrayRef<Token> AsmToks,
1279 StringRef AsmString,
1280 unsigned NumOutputs, unsigned NumInputs,
1281 ArrayRef<StringRef> Constraints,
1282 ArrayRef<StringRef> Clobbers,
1283 ArrayRef<Expr*> Exprs,
1284 SourceLocation EndLoc) {
1285 return getSema().ActOnMSAsmStmt(AsmLoc, LBraceLoc, AsmToks, AsmString,
1286 NumOutputs, NumInputs,
1287 Constraints, Clobbers, Exprs, EndLoc);
Chad Rosier32503022012-06-11 20:47:18 +00001288 }
1289
James Dennett2a4d13c2012-06-15 07:13:21 +00001290 /// \brief Build a new Objective-C \@try statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001291 ///
1292 /// By default, performs semantic analysis to build the new statement.
1293 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001294 StmtResult RebuildObjCAtTryStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001295 Stmt *TryBody,
Douglas Gregor96c79492010-04-23 22:50:49 +00001296 MultiStmtArg CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001297 Stmt *Finally) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001298 return getSema().ActOnObjCAtTryStmt(AtLoc, TryBody, CatchStmts,
John McCallb268a282010-08-23 23:25:46 +00001299 Finally);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001300 }
1301
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001302 /// \brief Rebuild an Objective-C exception declaration.
1303 ///
1304 /// By default, performs semantic analysis to build the new declaration.
1305 /// Subclasses may override this routine to provide different behavior.
1306 VarDecl *RebuildObjCExceptionDecl(VarDecl *ExceptionDecl,
1307 TypeSourceInfo *TInfo, QualType T) {
Abramo Bagnaradff19302011-03-08 08:55:46 +00001308 return getSema().BuildObjCExceptionDecl(TInfo, T,
1309 ExceptionDecl->getInnerLocStart(),
1310 ExceptionDecl->getLocation(),
1311 ExceptionDecl->getIdentifier());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001312 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001313
James Dennett2a4d13c2012-06-15 07:13:21 +00001314 /// \brief Build a new Objective-C \@catch statement.
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001315 ///
1316 /// By default, performs semantic analysis to build the new statement.
1317 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001318 StmtResult RebuildObjCAtCatchStmt(SourceLocation AtLoc,
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001319 SourceLocation RParenLoc,
1320 VarDecl *Var,
John McCallb268a282010-08-23 23:25:46 +00001321 Stmt *Body) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001322 return getSema().ActOnObjCAtCatchStmt(AtLoc, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00001323 Var, Body);
Douglas Gregorf4e837f2010-04-26 17:57:08 +00001324 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001325
James Dennett2a4d13c2012-06-15 07:13:21 +00001326 /// \brief Build a new Objective-C \@finally statement.
Douglas Gregor306de2f2010-04-22 23:59:56 +00001327 ///
1328 /// By default, performs semantic analysis to build the new statement.
1329 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001330 StmtResult RebuildObjCAtFinallyStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001331 Stmt *Body) {
1332 return getSema().ActOnObjCAtFinallyStmt(AtLoc, Body);
Douglas Gregor306de2f2010-04-22 23:59:56 +00001333 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001334
James Dennett2a4d13c2012-06-15 07:13:21 +00001335 /// \brief Build a new Objective-C \@throw statement.
Douglas Gregor2900c162010-04-22 21:44:01 +00001336 ///
1337 /// By default, performs semantic analysis to build the new statement.
1338 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001339 StmtResult RebuildObjCAtThrowStmt(SourceLocation AtLoc,
John McCallb268a282010-08-23 23:25:46 +00001340 Expr *Operand) {
1341 return getSema().BuildObjCAtThrowStmt(AtLoc, Operand);
Douglas Gregor2900c162010-04-22 21:44:01 +00001342 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001343
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001344 /// \brief Build a new OpenMP executable directive.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001345 ///
1346 /// By default, performs semantic analysis to build the new statement.
1347 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001348 StmtResult RebuildOMPExecutableDirective(OpenMPDirectiveKind Kind,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001349 DeclarationNameInfo DirName,
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001350 OpenMPDirectiveKind CancelRegion,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001351 ArrayRef<OMPClause *> Clauses,
Alexander Musmand9ed09f2014-07-21 09:42:05 +00001352 Stmt *AStmt, SourceLocation StartLoc,
Alexey Bataev1b59ab52014-02-27 08:29:12 +00001353 SourceLocation EndLoc) {
Alexey Bataev6d4ed052015-07-01 06:57:41 +00001354 return getSema().ActOnOpenMPExecutableDirective(
1355 Kind, DirName, CancelRegion, Clauses, AStmt, StartLoc, EndLoc);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001356 }
1357
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001358 /// \brief Build a new OpenMP 'if' clause.
1359 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001360 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001361 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001362 OMPClause *RebuildOMPIfClause(OpenMPDirectiveKind NameModifier,
1363 Expr *Condition, SourceLocation StartLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001364 SourceLocation LParenLoc,
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001365 SourceLocation NameModifierLoc,
1366 SourceLocation ColonLoc,
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001367 SourceLocation EndLoc) {
Alexey Bataev6b8046a2015-09-03 07:23:48 +00001368 return getSema().ActOnOpenMPIfClause(NameModifier, Condition, StartLoc,
1369 LParenLoc, NameModifierLoc, ColonLoc,
1370 EndLoc);
Alexey Bataevaadd52e2014-02-13 05:29:23 +00001371 }
1372
Alexey Bataev3778b602014-07-17 07:32:53 +00001373 /// \brief Build a new OpenMP 'final' clause.
1374 ///
1375 /// By default, performs semantic analysis to build the new OpenMP clause.
1376 /// Subclasses may override this routine to provide different behavior.
1377 OMPClause *RebuildOMPFinalClause(Expr *Condition, SourceLocation StartLoc,
1378 SourceLocation LParenLoc,
1379 SourceLocation EndLoc) {
1380 return getSema().ActOnOpenMPFinalClause(Condition, StartLoc, LParenLoc,
1381 EndLoc);
1382 }
1383
Alexey Bataev568a8332014-03-06 06:15:19 +00001384 /// \brief Build a new OpenMP 'num_threads' clause.
1385 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001386 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev568a8332014-03-06 06:15:19 +00001387 /// Subclasses may override this routine to provide different behavior.
1388 OMPClause *RebuildOMPNumThreadsClause(Expr *NumThreads,
1389 SourceLocation StartLoc,
1390 SourceLocation LParenLoc,
1391 SourceLocation EndLoc) {
1392 return getSema().ActOnOpenMPNumThreadsClause(NumThreads, StartLoc,
1393 LParenLoc, EndLoc);
1394 }
1395
Alexey Bataev62c87d22014-03-21 04:51:18 +00001396 /// \brief Build a new OpenMP 'safelen' clause.
1397 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001398 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev62c87d22014-03-21 04:51:18 +00001399 /// Subclasses may override this routine to provide different behavior.
1400 OMPClause *RebuildOMPSafelenClause(Expr *Len, SourceLocation StartLoc,
1401 SourceLocation LParenLoc,
1402 SourceLocation EndLoc) {
1403 return getSema().ActOnOpenMPSafelenClause(Len, StartLoc, LParenLoc, EndLoc);
1404 }
1405
Alexey Bataev66b15b52015-08-21 11:14:16 +00001406 /// \brief Build a new OpenMP 'simdlen' clause.
1407 ///
1408 /// By default, performs semantic analysis to build the new OpenMP clause.
1409 /// Subclasses may override this routine to provide different behavior.
1410 OMPClause *RebuildOMPSimdlenClause(Expr *Len, SourceLocation StartLoc,
1411 SourceLocation LParenLoc,
1412 SourceLocation EndLoc) {
1413 return getSema().ActOnOpenMPSimdlenClause(Len, StartLoc, LParenLoc, EndLoc);
1414 }
1415
Alexander Musman8bd31e62014-05-27 15:12:19 +00001416 /// \brief Build a new OpenMP 'collapse' clause.
1417 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001418 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8bd31e62014-05-27 15:12:19 +00001419 /// Subclasses may override this routine to provide different behavior.
1420 OMPClause *RebuildOMPCollapseClause(Expr *Num, SourceLocation StartLoc,
1421 SourceLocation LParenLoc,
1422 SourceLocation EndLoc) {
1423 return getSema().ActOnOpenMPCollapseClause(Num, StartLoc, LParenLoc,
1424 EndLoc);
1425 }
1426
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001427 /// \brief Build a new OpenMP 'default' clause.
1428 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001429 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001430 /// Subclasses may override this routine to provide different behavior.
1431 OMPClause *RebuildOMPDefaultClause(OpenMPDefaultClauseKind Kind,
1432 SourceLocation KindKwLoc,
1433 SourceLocation StartLoc,
1434 SourceLocation LParenLoc,
1435 SourceLocation EndLoc) {
1436 return getSema().ActOnOpenMPDefaultClause(Kind, KindKwLoc,
1437 StartLoc, LParenLoc, EndLoc);
1438 }
1439
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001440 /// \brief Build a new OpenMP 'proc_bind' clause.
1441 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001442 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevbcbadb62014-05-06 06:04:14 +00001443 /// Subclasses may override this routine to provide different behavior.
1444 OMPClause *RebuildOMPProcBindClause(OpenMPProcBindClauseKind Kind,
1445 SourceLocation KindKwLoc,
1446 SourceLocation StartLoc,
1447 SourceLocation LParenLoc,
1448 SourceLocation EndLoc) {
1449 return getSema().ActOnOpenMPProcBindClause(Kind, KindKwLoc,
1450 StartLoc, LParenLoc, EndLoc);
1451 }
1452
Alexey Bataev56dafe82014-06-20 07:16:17 +00001453 /// \brief Build a new OpenMP 'schedule' clause.
1454 ///
1455 /// By default, performs semantic analysis to build the new OpenMP clause.
1456 /// Subclasses may override this routine to provide different behavior.
1457 OMPClause *RebuildOMPScheduleClause(OpenMPScheduleClauseKind Kind,
1458 Expr *ChunkSize,
1459 SourceLocation StartLoc,
1460 SourceLocation LParenLoc,
1461 SourceLocation KindLoc,
1462 SourceLocation CommaLoc,
1463 SourceLocation EndLoc) {
1464 return getSema().ActOnOpenMPScheduleClause(
1465 Kind, ChunkSize, StartLoc, LParenLoc, KindLoc, CommaLoc, EndLoc);
1466 }
1467
Alexey Bataev10e775f2015-07-30 11:36:16 +00001468 /// \brief Build a new OpenMP 'ordered' clause.
1469 ///
1470 /// By default, performs semantic analysis to build the new OpenMP clause.
1471 /// Subclasses may override this routine to provide different behavior.
1472 OMPClause *RebuildOMPOrderedClause(SourceLocation StartLoc,
1473 SourceLocation EndLoc,
1474 SourceLocation LParenLoc, Expr *Num) {
1475 return getSema().ActOnOpenMPOrderedClause(StartLoc, EndLoc, LParenLoc, Num);
1476 }
1477
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001478 /// \brief Build a new OpenMP 'private' clause.
1479 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001480 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00001481 /// Subclasses may override this routine to provide different behavior.
1482 OMPClause *RebuildOMPPrivateClause(ArrayRef<Expr *> VarList,
1483 SourceLocation StartLoc,
1484 SourceLocation LParenLoc,
1485 SourceLocation EndLoc) {
1486 return getSema().ActOnOpenMPPrivateClause(VarList, StartLoc, LParenLoc,
1487 EndLoc);
1488 }
1489
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001490 /// \brief Build a new OpenMP 'firstprivate' clause.
1491 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001492 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd5af8e42013-10-01 05:32:34 +00001493 /// Subclasses may override this routine to provide different behavior.
1494 OMPClause *RebuildOMPFirstprivateClause(ArrayRef<Expr *> VarList,
1495 SourceLocation StartLoc,
1496 SourceLocation LParenLoc,
1497 SourceLocation EndLoc) {
1498 return getSema().ActOnOpenMPFirstprivateClause(VarList, StartLoc, LParenLoc,
1499 EndLoc);
1500 }
1501
Alexander Musman1bb328c2014-06-04 13:06:39 +00001502 /// \brief Build a new OpenMP 'lastprivate' clause.
1503 ///
1504 /// By default, performs semantic analysis to build the new OpenMP clause.
1505 /// Subclasses may override this routine to provide different behavior.
1506 OMPClause *RebuildOMPLastprivateClause(ArrayRef<Expr *> VarList,
1507 SourceLocation StartLoc,
1508 SourceLocation LParenLoc,
1509 SourceLocation EndLoc) {
1510 return getSema().ActOnOpenMPLastprivateClause(VarList, StartLoc, LParenLoc,
1511 EndLoc);
1512 }
1513
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001514 /// \brief Build a new OpenMP 'shared' clause.
1515 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001516 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd4dbdf52014-03-06 12:27:56 +00001517 /// Subclasses may override this routine to provide different behavior.
Alexey Bataev758e55e2013-09-06 18:03:48 +00001518 OMPClause *RebuildOMPSharedClause(ArrayRef<Expr *> VarList,
1519 SourceLocation StartLoc,
1520 SourceLocation LParenLoc,
1521 SourceLocation EndLoc) {
1522 return getSema().ActOnOpenMPSharedClause(VarList, StartLoc, LParenLoc,
1523 EndLoc);
1524 }
1525
Alexey Bataevc5e02582014-06-16 07:08:35 +00001526 /// \brief Build a new OpenMP 'reduction' clause.
1527 ///
1528 /// By default, performs semantic analysis to build the new statement.
1529 /// Subclasses may override this routine to provide different behavior.
1530 OMPClause *RebuildOMPReductionClause(ArrayRef<Expr *> VarList,
1531 SourceLocation StartLoc,
1532 SourceLocation LParenLoc,
1533 SourceLocation ColonLoc,
1534 SourceLocation EndLoc,
1535 CXXScopeSpec &ReductionIdScopeSpec,
1536 const DeclarationNameInfo &ReductionId) {
1537 return getSema().ActOnOpenMPReductionClause(
1538 VarList, StartLoc, LParenLoc, ColonLoc, EndLoc, ReductionIdScopeSpec,
1539 ReductionId);
1540 }
1541
Alexander Musman8dba6642014-04-22 13:09:42 +00001542 /// \brief Build a new OpenMP 'linear' clause.
1543 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001544 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musman8dba6642014-04-22 13:09:42 +00001545 /// Subclasses may override this routine to provide different behavior.
1546 OMPClause *RebuildOMPLinearClause(ArrayRef<Expr *> VarList, Expr *Step,
1547 SourceLocation StartLoc,
1548 SourceLocation LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001549 OpenMPLinearClauseKind Modifier,
1550 SourceLocation ModifierLoc,
Alexander Musman8dba6642014-04-22 13:09:42 +00001551 SourceLocation ColonLoc,
1552 SourceLocation EndLoc) {
1553 return getSema().ActOnOpenMPLinearClause(VarList, Step, StartLoc, LParenLoc,
Alexey Bataev182227b2015-08-20 10:54:39 +00001554 Modifier, ModifierLoc, ColonLoc,
1555 EndLoc);
Alexander Musman8dba6642014-04-22 13:09:42 +00001556 }
1557
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001558 /// \brief Build a new OpenMP 'aligned' clause.
1559 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001560 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexander Musmanf0d76e72014-05-29 14:36:25 +00001561 /// Subclasses may override this routine to provide different behavior.
1562 OMPClause *RebuildOMPAlignedClause(ArrayRef<Expr *> VarList, Expr *Alignment,
1563 SourceLocation StartLoc,
1564 SourceLocation LParenLoc,
1565 SourceLocation ColonLoc,
1566 SourceLocation EndLoc) {
1567 return getSema().ActOnOpenMPAlignedClause(VarList, Alignment, StartLoc,
1568 LParenLoc, ColonLoc, EndLoc);
1569 }
1570
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001571 /// \brief Build a new OpenMP 'copyin' clause.
1572 ///
Alexander Musman64d33f12014-06-04 07:53:32 +00001573 /// By default, performs semantic analysis to build the new OpenMP clause.
Alexey Bataevd48bcd82014-03-31 03:36:38 +00001574 /// Subclasses may override this routine to provide different behavior.
1575 OMPClause *RebuildOMPCopyinClause(ArrayRef<Expr *> VarList,
1576 SourceLocation StartLoc,
1577 SourceLocation LParenLoc,
1578 SourceLocation EndLoc) {
1579 return getSema().ActOnOpenMPCopyinClause(VarList, StartLoc, LParenLoc,
1580 EndLoc);
1581 }
1582
Alexey Bataevbae9a792014-06-27 10:37:06 +00001583 /// \brief Build a new OpenMP 'copyprivate' clause.
1584 ///
1585 /// By default, performs semantic analysis to build the new OpenMP clause.
1586 /// Subclasses may override this routine to provide different behavior.
1587 OMPClause *RebuildOMPCopyprivateClause(ArrayRef<Expr *> VarList,
1588 SourceLocation StartLoc,
1589 SourceLocation LParenLoc,
1590 SourceLocation EndLoc) {
1591 return getSema().ActOnOpenMPCopyprivateClause(VarList, StartLoc, LParenLoc,
1592 EndLoc);
1593 }
1594
Alexey Bataev6125da92014-07-21 11:26:11 +00001595 /// \brief Build a new OpenMP 'flush' pseudo clause.
1596 ///
1597 /// By default, performs semantic analysis to build the new OpenMP clause.
1598 /// Subclasses may override this routine to provide different behavior.
1599 OMPClause *RebuildOMPFlushClause(ArrayRef<Expr *> VarList,
1600 SourceLocation StartLoc,
1601 SourceLocation LParenLoc,
1602 SourceLocation EndLoc) {
1603 return getSema().ActOnOpenMPFlushClause(VarList, StartLoc, LParenLoc,
1604 EndLoc);
1605 }
1606
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00001607 /// \brief Build a new OpenMP 'depend' pseudo clause.
1608 ///
1609 /// By default, performs semantic analysis to build the new OpenMP clause.
1610 /// Subclasses may override this routine to provide different behavior.
1611 OMPClause *
1612 RebuildOMPDependClause(OpenMPDependClauseKind DepKind, SourceLocation DepLoc,
1613 SourceLocation ColonLoc, ArrayRef<Expr *> VarList,
1614 SourceLocation StartLoc, SourceLocation LParenLoc,
1615 SourceLocation EndLoc) {
1616 return getSema().ActOnOpenMPDependClause(DepKind, DepLoc, ColonLoc, VarList,
1617 StartLoc, LParenLoc, EndLoc);
1618 }
1619
Michael Wonge710d542015-08-07 16:16:36 +00001620 /// \brief Build a new OpenMP 'device' clause.
1621 ///
1622 /// By default, performs semantic analysis to build the new statement.
1623 /// Subclasses may override this routine to provide different behavior.
1624 OMPClause *RebuildOMPDeviceClause(Expr *Device, SourceLocation StartLoc,
1625 SourceLocation LParenLoc,
1626 SourceLocation EndLoc) {
1627 return getSema().ActOnOpenMPDeviceClause(Device, StartLoc, LParenLoc,
1628 EndLoc);
1629 }
1630
James Dennett2a4d13c2012-06-15 07:13:21 +00001631 /// \brief Rebuild the operand to an Objective-C \@synchronized statement.
John McCalld9bb7432011-07-27 21:50:02 +00001632 ///
1633 /// By default, performs semantic analysis to build the new statement.
1634 /// Subclasses may override this routine to provide different behavior.
1635 ExprResult RebuildObjCAtSynchronizedOperand(SourceLocation atLoc,
1636 Expr *object) {
1637 return getSema().ActOnObjCAtSynchronizedOperand(atLoc, object);
1638 }
1639
James Dennett2a4d13c2012-06-15 07:13:21 +00001640 /// \brief Build a new Objective-C \@synchronized statement.
Douglas Gregor6148de72010-04-22 22:01:21 +00001641 ///
Douglas Gregor6148de72010-04-22 22:01:21 +00001642 /// By default, performs semantic analysis to build the new statement.
1643 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001644 StmtResult RebuildObjCAtSynchronizedStmt(SourceLocation AtLoc,
John McCalld9bb7432011-07-27 21:50:02 +00001645 Expr *Object, Stmt *Body) {
1646 return getSema().ActOnObjCAtSynchronizedStmt(AtLoc, Object, Body);
Douglas Gregor6148de72010-04-22 22:01:21 +00001647 }
Douglas Gregorf68a5082010-04-22 23:10:45 +00001648
James Dennett2a4d13c2012-06-15 07:13:21 +00001649 /// \brief Build a new Objective-C \@autoreleasepool statement.
John McCall31168b02011-06-15 23:02:42 +00001650 ///
1651 /// By default, performs semantic analysis to build the new statement.
1652 /// Subclasses may override this routine to provide different behavior.
1653 StmtResult RebuildObjCAutoreleasePoolStmt(SourceLocation AtLoc,
1654 Stmt *Body) {
1655 return getSema().ActOnObjCAutoreleasePoolStmt(AtLoc, Body);
1656 }
John McCall53848232011-07-27 01:07:15 +00001657
Douglas Gregorf68a5082010-04-22 23:10:45 +00001658 /// \brief Build a new Objective-C fast enumeration statement.
1659 ///
1660 /// By default, performs semantic analysis to build the new statement.
1661 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001662 StmtResult RebuildObjCForCollectionStmt(SourceLocation ForLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001663 Stmt *Element,
1664 Expr *Collection,
1665 SourceLocation RParenLoc,
1666 Stmt *Body) {
Sam Panzer2c4ca0f2012-08-16 21:47:25 +00001667 StmtResult ForEachStmt = getSema().ActOnObjCForCollectionStmt(ForLoc,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001668 Element,
John McCallb268a282010-08-23 23:25:46 +00001669 Collection,
Fariborz Jahanian450bb6e2012-07-03 22:00:52 +00001670 RParenLoc);
1671 if (ForEachStmt.isInvalid())
1672 return StmtError();
1673
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001674 return getSema().FinishObjCForCollectionStmt(ForEachStmt.get(), Body);
Douglas Gregorf68a5082010-04-22 23:10:45 +00001675 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001676
Douglas Gregorebe10102009-08-20 07:17:43 +00001677 /// \brief Build a new C++ exception declaration.
1678 ///
1679 /// By default, performs semantic analysis to build the new decaration.
1680 /// Subclasses may override this routine to provide different behavior.
Abramo Bagnaradff19302011-03-08 08:55:46 +00001681 VarDecl *RebuildExceptionDecl(VarDecl *ExceptionDecl,
John McCallbcd03502009-12-07 02:54:59 +00001682 TypeSourceInfo *Declarator,
Abramo Bagnaradff19302011-03-08 08:55:46 +00001683 SourceLocation StartLoc,
1684 SourceLocation IdLoc,
1685 IdentifierInfo *Id) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001686 VarDecl *Var = getSema().BuildExceptionDeclaration(nullptr, Declarator,
Douglas Gregor40965fa2011-04-14 22:32:28 +00001687 StartLoc, IdLoc, Id);
1688 if (Var)
1689 getSema().CurContext->addDecl(Var);
1690 return Var;
Douglas Gregorebe10102009-08-20 07:17:43 +00001691 }
1692
1693 /// \brief Build a new C++ catch statement.
1694 ///
1695 /// By default, performs semantic analysis to build the new statement.
1696 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001697 StmtResult RebuildCXXCatchStmt(SourceLocation CatchLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001698 VarDecl *ExceptionDecl,
1699 Stmt *Handler) {
John McCallb268a282010-08-23 23:25:46 +00001700 return Owned(new (getSema().Context) CXXCatchStmt(CatchLoc, ExceptionDecl,
1701 Handler));
Douglas Gregorebe10102009-08-20 07:17:43 +00001702 }
Mike Stump11289f42009-09-09 15:08:12 +00001703
Douglas Gregorebe10102009-08-20 07:17:43 +00001704 /// \brief Build a new C++ try statement.
1705 ///
1706 /// By default, performs semantic analysis to build the new statement.
1707 /// Subclasses may override this routine to provide different behavior.
Robert Wilhelmcafda822013-08-22 09:20:03 +00001708 StmtResult RebuildCXXTryStmt(SourceLocation TryLoc, Stmt *TryBlock,
1709 ArrayRef<Stmt *> Handlers) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001710 return getSema().ActOnCXXTryBlock(TryLoc, TryBlock, Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00001711 }
Mike Stump11289f42009-09-09 15:08:12 +00001712
Richard Smith02e85f32011-04-14 22:09:26 +00001713 /// \brief Build a new C++0x range-based for statement.
1714 ///
1715 /// By default, performs semantic analysis to build the new statement.
1716 /// Subclasses may override this routine to provide different behavior.
1717 StmtResult RebuildCXXForRangeStmt(SourceLocation ForLoc,
1718 SourceLocation ColonLoc,
1719 Stmt *Range, Stmt *BeginEnd,
1720 Expr *Cond, Expr *Inc,
1721 Stmt *LoopVar,
1722 SourceLocation RParenLoc) {
Douglas Gregorf7106af2013-04-08 18:40:13 +00001723 // If we've just learned that the range is actually an Objective-C
1724 // collection, treat this as an Objective-C fast enumeration loop.
1725 if (DeclStmt *RangeStmt = dyn_cast<DeclStmt>(Range)) {
1726 if (RangeStmt->isSingleDecl()) {
1727 if (VarDecl *RangeVar = dyn_cast<VarDecl>(RangeStmt->getSingleDecl())) {
Douglas Gregor39aaeef2013-05-02 18:35:56 +00001728 if (RangeVar->isInvalidDecl())
1729 return StmtError();
1730
Douglas Gregorf7106af2013-04-08 18:40:13 +00001731 Expr *RangeExpr = RangeVar->getInit();
1732 if (!RangeExpr->isTypeDependent() &&
1733 RangeExpr->getType()->isObjCObjectPointerType())
1734 return getSema().ActOnObjCForCollectionStmt(ForLoc, LoopVar, RangeExpr,
1735 RParenLoc);
1736 }
1737 }
1738 }
1739
Richard Smith02e85f32011-04-14 22:09:26 +00001740 return getSema().BuildCXXForRangeStmt(ForLoc, ColonLoc, Range, BeginEnd,
Richard Smitha05b3b52012-09-20 21:52:32 +00001741 Cond, Inc, LoopVar, RParenLoc,
1742 Sema::BFRK_Rebuild);
Richard Smith02e85f32011-04-14 22:09:26 +00001743 }
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001744
1745 /// \brief Build a new C++0x range-based for statement.
1746 ///
1747 /// By default, performs semantic analysis to build the new statement.
1748 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00001749 StmtResult RebuildMSDependentExistsStmt(SourceLocation KeywordLoc,
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00001750 bool IsIfExists,
1751 NestedNameSpecifierLoc QualifierLoc,
1752 DeclarationNameInfo NameInfo,
1753 Stmt *Nested) {
1754 return getSema().BuildMSDependentExistsStmt(KeywordLoc, IsIfExists,
1755 QualifierLoc, NameInfo, Nested);
1756 }
1757
Richard Smith02e85f32011-04-14 22:09:26 +00001758 /// \brief Attach body to a C++0x range-based for statement.
1759 ///
1760 /// By default, performs semantic analysis to finish the new statement.
1761 /// Subclasses may override this routine to provide different behavior.
1762 StmtResult FinishCXXForRangeStmt(Stmt *ForRange, Stmt *Body) {
1763 return getSema().FinishCXXForRangeStmt(ForRange, Body);
1764 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001765
David Majnemerfad8f482013-10-15 09:33:02 +00001766 StmtResult RebuildSEHTryStmt(bool IsCXXTry, SourceLocation TryLoc,
Warren Huntf6be4cb2014-07-25 20:52:51 +00001767 Stmt *TryBlock, Stmt *Handler) {
1768 return getSema().ActOnSEHTryBlock(IsCXXTry, TryLoc, TryBlock, Handler);
John Wiegley1c0675e2011-04-28 01:08:34 +00001769 }
1770
David Majnemerfad8f482013-10-15 09:33:02 +00001771 StmtResult RebuildSEHExceptStmt(SourceLocation Loc, Expr *FilterExpr,
John Wiegley1c0675e2011-04-28 01:08:34 +00001772 Stmt *Block) {
David Majnemerfad8f482013-10-15 09:33:02 +00001773 return getSema().ActOnSEHExceptBlock(Loc, FilterExpr, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001774 }
1775
David Majnemerfad8f482013-10-15 09:33:02 +00001776 StmtResult RebuildSEHFinallyStmt(SourceLocation Loc, Stmt *Block) {
Nico Weberd64657f2015-03-09 02:47:59 +00001777 return SEHFinallyStmt::Create(getSema().getASTContext(), Loc, Block);
John Wiegley1c0675e2011-04-28 01:08:34 +00001778 }
1779
Alexey Bataevec474782014-10-09 08:45:04 +00001780 /// \brief Build a new predefined expression.
1781 ///
1782 /// By default, performs semantic analysis to build the new expression.
1783 /// Subclasses may override this routine to provide different behavior.
1784 ExprResult RebuildPredefinedExpr(SourceLocation Loc,
1785 PredefinedExpr::IdentType IT) {
1786 return getSema().BuildPredefinedExpr(Loc, IT);
1787 }
1788
Douglas Gregora16548e2009-08-11 05:31:07 +00001789 /// \brief Build a new expression that references a declaration.
1790 ///
1791 /// By default, performs semantic analysis to build the new expression.
1792 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001793 ExprResult RebuildDeclarationNameExpr(const CXXScopeSpec &SS,
John McCallfaf5fb42010-08-26 23:41:50 +00001794 LookupResult &R,
1795 bool RequiresADL) {
John McCalle66edc12009-11-24 19:00:30 +00001796 return getSema().BuildDeclarationNameExpr(SS, R, RequiresADL);
1797 }
1798
1799
1800 /// \brief Build a new expression that references a declaration.
1801 ///
1802 /// By default, performs semantic analysis to build the new expression.
1803 /// Subclasses may override this routine to provide different behavior.
Douglas Gregorea972d32011-02-28 21:54:11 +00001804 ExprResult RebuildDeclRefExpr(NestedNameSpecifierLoc QualifierLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00001805 ValueDecl *VD,
1806 const DeclarationNameInfo &NameInfo,
1807 TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor4bd90e52009-10-23 18:54:35 +00001808 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001809 SS.Adopt(QualifierLoc);
John McCallce546572009-12-08 09:08:17 +00001810
1811 // FIXME: loses template args.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001812
1813 return getSema().BuildDeclarationNameExpr(SS, NameInfo, VD);
Douglas Gregora16548e2009-08-11 05:31:07 +00001814 }
Mike Stump11289f42009-09-09 15:08:12 +00001815
Douglas Gregora16548e2009-08-11 05:31:07 +00001816 /// \brief Build a new expression in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00001817 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001818 /// By default, performs semantic analysis to build the new expression.
1819 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001820 ExprResult RebuildParenExpr(Expr *SubExpr, SourceLocation LParen,
Douglas Gregora16548e2009-08-11 05:31:07 +00001821 SourceLocation RParen) {
John McCallb268a282010-08-23 23:25:46 +00001822 return getSema().ActOnParenExpr(LParen, RParen, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001823 }
1824
Douglas Gregorad8a3362009-09-04 17:36:40 +00001825 /// \brief Build a new pseudo-destructor expression.
Mike Stump11289f42009-09-09 15:08:12 +00001826 ///
Douglas Gregorad8a3362009-09-04 17:36:40 +00001827 /// By default, performs semantic analysis to build the new expression.
1828 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001829 ExprResult RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregora6ce6082011-02-25 18:19:59 +00001830 SourceLocation OperatorLoc,
1831 bool isArrow,
1832 CXXScopeSpec &SS,
1833 TypeSourceInfo *ScopeType,
1834 SourceLocation CCLoc,
1835 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +00001836 PseudoDestructorTypeStorage Destroyed);
Mike Stump11289f42009-09-09 15:08:12 +00001837
Douglas Gregora16548e2009-08-11 05:31:07 +00001838 /// \brief Build a new unary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001839 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001840 /// By default, performs semantic analysis to build the new expression.
1841 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001842 ExprResult RebuildUnaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001843 UnaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001844 Expr *SubExpr) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001845 return getSema().BuildUnaryOp(/*Scope=*/nullptr, OpLoc, Opc, SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001846 }
Mike Stump11289f42009-09-09 15:08:12 +00001847
Douglas Gregor882211c2010-04-28 22:16:22 +00001848 /// \brief Build a new builtin offsetof expression.
1849 ///
1850 /// By default, performs semantic analysis to build the new expression.
1851 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001852 ExprResult RebuildOffsetOfExpr(SourceLocation OperatorLoc,
Craig Topperb5518242015-10-22 04:59:59 +00001853 TypeSourceInfo *Type,
1854 ArrayRef<Sema::OffsetOfComponent> Components,
1855 SourceLocation RParenLoc) {
Douglas Gregor882211c2010-04-28 22:16:22 +00001856 return getSema().BuildBuiltinOffsetOf(OperatorLoc, Type, Components,
Craig Topperb5518242015-10-22 04:59:59 +00001857 RParenLoc);
Douglas Gregor882211c2010-04-28 22:16:22 +00001858 }
Chad Rosier1dcde962012-08-08 18:46:20 +00001859
1860 /// \brief Build a new sizeof, alignof or vec_step expression with a
Peter Collingbournee190dee2011-03-11 19:24:49 +00001861 /// type argument.
Mike Stump11289f42009-09-09 15:08:12 +00001862 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001863 /// By default, performs semantic analysis to build the new expression.
1864 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001865 ExprResult RebuildUnaryExprOrTypeTrait(TypeSourceInfo *TInfo,
1866 SourceLocation OpLoc,
1867 UnaryExprOrTypeTrait ExprKind,
1868 SourceRange R) {
1869 return getSema().CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, R);
Douglas Gregora16548e2009-08-11 05:31:07 +00001870 }
1871
Peter Collingbournee190dee2011-03-11 19:24:49 +00001872 /// \brief Build a new sizeof, alignof or vec step expression with an
1873 /// expression argument.
Mike Stump11289f42009-09-09 15:08:12 +00001874 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001875 /// By default, performs semantic analysis to build the new expression.
1876 /// Subclasses may override this routine to provide different behavior.
Peter Collingbournee190dee2011-03-11 19:24:49 +00001877 ExprResult RebuildUnaryExprOrTypeTrait(Expr *SubExpr, SourceLocation OpLoc,
1878 UnaryExprOrTypeTrait ExprKind,
1879 SourceRange R) {
John McCalldadc5752010-08-24 06:29:42 +00001880 ExprResult Result
Chandler Carrutha923fb22011-05-29 07:32:14 +00001881 = getSema().CreateUnaryExprOrTypeTraitExpr(SubExpr, OpLoc, ExprKind);
Douglas Gregora16548e2009-08-11 05:31:07 +00001882 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001883 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00001884
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001885 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00001886 }
Mike Stump11289f42009-09-09 15:08:12 +00001887
Douglas Gregora16548e2009-08-11 05:31:07 +00001888 /// \brief Build a new array subscript expression.
Mike Stump11289f42009-09-09 15:08:12 +00001889 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001890 /// By default, performs semantic analysis to build the new expression.
1891 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001892 ExprResult RebuildArraySubscriptExpr(Expr *LHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001893 SourceLocation LBracketLoc,
John McCallb268a282010-08-23 23:25:46 +00001894 Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001895 SourceLocation RBracketLoc) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001896 return getSema().ActOnArraySubscriptExpr(/*Scope=*/nullptr, LHS,
John McCallb268a282010-08-23 23:25:46 +00001897 LBracketLoc, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00001898 RBracketLoc);
1899 }
1900
Alexey Bataev1a3320e2015-08-25 14:24:04 +00001901 /// \brief Build a new array section expression.
1902 ///
1903 /// By default, performs semantic analysis to build the new expression.
1904 /// Subclasses may override this routine to provide different behavior.
1905 ExprResult RebuildOMPArraySectionExpr(Expr *Base, SourceLocation LBracketLoc,
1906 Expr *LowerBound,
1907 SourceLocation ColonLoc, Expr *Length,
1908 SourceLocation RBracketLoc) {
1909 return getSema().ActOnOMPArraySectionExpr(Base, LBracketLoc, LowerBound,
1910 ColonLoc, Length, RBracketLoc);
1911 }
1912
Douglas Gregora16548e2009-08-11 05:31:07 +00001913 /// \brief Build a new call expression.
Mike Stump11289f42009-09-09 15:08:12 +00001914 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001915 /// By default, performs semantic analysis to build the new expression.
1916 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001917 ExprResult RebuildCallExpr(Expr *Callee, SourceLocation LParenLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00001918 MultiExprArg Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00001919 SourceLocation RParenLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +00001920 Expr *ExecConfig = nullptr) {
1921 return getSema().ActOnCallExpr(/*Scope=*/nullptr, Callee, LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00001922 Args, RParenLoc, ExecConfig);
Douglas Gregora16548e2009-08-11 05:31:07 +00001923 }
1924
1925 /// \brief Build a new member access expression.
Mike Stump11289f42009-09-09 15:08:12 +00001926 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001927 /// By default, performs semantic analysis to build the new expression.
1928 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001929 ExprResult RebuildMemberExpr(Expr *Base, SourceLocation OpLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001930 bool isArrow,
Douglas Gregorea972d32011-02-28 21:54:11 +00001931 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001932 SourceLocation TemplateKWLoc,
John McCall7decc9e2010-11-18 06:31:45 +00001933 const DeclarationNameInfo &MemberNameInfo,
1934 ValueDecl *Member,
1935 NamedDecl *FoundDecl,
John McCall6b51f282009-11-23 01:53:49 +00001936 const TemplateArgumentListInfo *ExplicitTemplateArgs,
John McCall7decc9e2010-11-18 06:31:45 +00001937 NamedDecl *FirstQualifierInScope) {
Richard Smithcab9a7d2011-10-26 19:06:56 +00001938 ExprResult BaseResult = getSema().PerformMemberExprBaseConversion(Base,
1939 isArrow);
Anders Carlsson5da84842009-09-01 04:26:58 +00001940 if (!Member->getDeclName()) {
John McCall7decc9e2010-11-18 06:31:45 +00001941 // We have a reference to an unnamed field. This is always the
1942 // base of an anonymous struct/union member access, i.e. the
1943 // field is always of record type.
Douglas Gregorea972d32011-02-28 21:54:11 +00001944 assert(!QualifierLoc && "Can't have an unnamed field with a qualifier!");
John McCall7decc9e2010-11-18 06:31:45 +00001945 assert(Member->getType()->isRecordType() &&
1946 "unnamed member not of record type?");
Mike Stump11289f42009-09-09 15:08:12 +00001947
Richard Smithcab9a7d2011-10-26 19:06:56 +00001948 BaseResult =
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001949 getSema().PerformObjectMemberConversion(BaseResult.get(),
John Wiegley01296292011-04-08 18:41:53 +00001950 QualifierLoc.getNestedNameSpecifier(),
1951 FoundDecl, Member);
1952 if (BaseResult.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00001953 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001954 Base = BaseResult.get();
John McCall7decc9e2010-11-18 06:31:45 +00001955 ExprValueKind VK = isArrow ? VK_LValue : Base->getValueKind();
Aaron Ballmanf4cb2be2015-03-24 15:07:53 +00001956 MemberExpr *ME = new (getSema().Context)
1957 MemberExpr(Base, isArrow, OpLoc, Member, MemberNameInfo,
1958 cast<FieldDecl>(Member)->getType(), VK, OK_Ordinary);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00001959 return ME;
Anders Carlsson5da84842009-09-01 04:26:58 +00001960 }
Mike Stump11289f42009-09-09 15:08:12 +00001961
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001962 CXXScopeSpec SS;
Douglas Gregorea972d32011-02-28 21:54:11 +00001963 SS.Adopt(QualifierLoc);
Douglas Gregorf405d7e2009-08-31 23:41:50 +00001964
Nikola Smiljanic01a75982014-05-29 10:55:11 +00001965 Base = BaseResult.get();
John McCallb268a282010-08-23 23:25:46 +00001966 QualType BaseType = Base->getType();
John McCall2d74de92009-12-01 22:10:20 +00001967
John McCall16df1e52010-03-30 21:47:33 +00001968 // FIXME: this involves duplicating earlier analysis in a lot of
1969 // cases; we should avoid this when possible.
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00001970 LookupResult R(getSema(), MemberNameInfo, Sema::LookupMemberName);
John McCall16df1e52010-03-30 21:47:33 +00001971 R.addDecl(FoundDecl);
John McCall38836f02010-01-15 08:34:02 +00001972 R.resolveKind();
1973
John McCallb268a282010-08-23 23:25:46 +00001974 return getSema().BuildMemberReferenceExpr(Base, BaseType, OpLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00001975 SS, TemplateKWLoc,
1976 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00001977 R, ExplicitTemplateArgs,
1978 /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00001979 }
Mike Stump11289f42009-09-09 15:08:12 +00001980
Douglas Gregora16548e2009-08-11 05:31:07 +00001981 /// \brief Build a new binary operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001982 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001983 /// By default, performs semantic analysis to build the new expression.
1984 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001985 ExprResult RebuildBinaryOperator(SourceLocation OpLoc,
John McCalle3027922010-08-25 11:45:40 +00001986 BinaryOperatorKind Opc,
John McCallb268a282010-08-23 23:25:46 +00001987 Expr *LHS, Expr *RHS) {
Craig Topperc3ec1492014-05-26 06:22:03 +00001988 return getSema().BuildBinOp(/*Scope=*/nullptr, OpLoc, Opc, LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00001989 }
1990
1991 /// \brief Build a new conditional operator expression.
Mike Stump11289f42009-09-09 15:08:12 +00001992 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00001993 /// By default, performs semantic analysis to build the new expression.
1994 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00001995 ExprResult RebuildConditionalOperator(Expr *Cond,
John McCallc07a0c72011-02-17 10:25:35 +00001996 SourceLocation QuestionLoc,
1997 Expr *LHS,
1998 SourceLocation ColonLoc,
1999 Expr *RHS) {
John McCallb268a282010-08-23 23:25:46 +00002000 return getSema().ActOnConditionalOp(QuestionLoc, ColonLoc, Cond,
2001 LHS, RHS);
Douglas Gregora16548e2009-08-11 05:31:07 +00002002 }
2003
Douglas Gregora16548e2009-08-11 05:31:07 +00002004 /// \brief Build a new C-style cast expression.
Mike Stump11289f42009-09-09 15:08:12 +00002005 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002006 /// By default, performs semantic analysis to build the new expression.
2007 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002008 ExprResult RebuildCStyleCastExpr(SourceLocation LParenLoc,
John McCall97513962010-01-15 18:39:57 +00002009 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002010 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002011 Expr *SubExpr) {
John McCallebe54742010-01-15 18:56:44 +00002012 return getSema().BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002013 SubExpr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002014 }
Mike Stump11289f42009-09-09 15:08:12 +00002015
Douglas Gregora16548e2009-08-11 05:31:07 +00002016 /// \brief Build a new compound literal expression.
Mike Stump11289f42009-09-09 15:08:12 +00002017 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002018 /// By default, performs semantic analysis to build the new expression.
2019 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002020 ExprResult RebuildCompoundLiteralExpr(SourceLocation LParenLoc,
John McCalle15bbff2010-01-18 19:35:47 +00002021 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002022 SourceLocation RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002023 Expr *Init) {
John McCalle15bbff2010-01-18 19:35:47 +00002024 return getSema().BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002025 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002026 }
Mike Stump11289f42009-09-09 15:08:12 +00002027
Douglas Gregora16548e2009-08-11 05:31:07 +00002028 /// \brief Build a new extended vector element access expression.
Mike Stump11289f42009-09-09 15:08:12 +00002029 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002030 /// By default, performs semantic analysis to build the new expression.
2031 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002032 ExprResult RebuildExtVectorElementExpr(Expr *Base,
Douglas Gregora16548e2009-08-11 05:31:07 +00002033 SourceLocation OpLoc,
2034 SourceLocation AccessorLoc,
2035 IdentifierInfo &Accessor) {
John McCall2d74de92009-12-01 22:10:20 +00002036
John McCall10eae182009-11-30 22:42:35 +00002037 CXXScopeSpec SS;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002038 DeclarationNameInfo NameInfo(&Accessor, AccessorLoc);
John McCallb268a282010-08-23 23:25:46 +00002039 return getSema().BuildMemberReferenceExpr(Base, Base->getType(),
John McCall10eae182009-11-30 22:42:35 +00002040 OpLoc, /*IsArrow*/ false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002041 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002042 /*FirstQualifierInScope*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002043 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002044 /* TemplateArgs */ nullptr,
2045 /*S*/ nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002046 }
Mike Stump11289f42009-09-09 15:08:12 +00002047
Douglas Gregora16548e2009-08-11 05:31:07 +00002048 /// \brief Build a new initializer list expression.
Mike Stump11289f42009-09-09 15:08:12 +00002049 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002050 /// By default, performs semantic analysis to build the new expression.
2051 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002052 ExprResult RebuildInitList(SourceLocation LBraceLoc,
John McCall542e7c62011-07-06 07:30:07 +00002053 MultiExprArg Inits,
2054 SourceLocation RBraceLoc,
2055 QualType ResultTy) {
John McCalldadc5752010-08-24 06:29:42 +00002056 ExprResult Result
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002057 = SemaRef.ActOnInitList(LBraceLoc, Inits, RBraceLoc);
Douglas Gregord3d93062009-11-09 17:16:50 +00002058 if (Result.isInvalid() || ResultTy->isDependentType())
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002059 return Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00002060
Douglas Gregord3d93062009-11-09 17:16:50 +00002061 // Patch in the result type we were given, which may have been computed
2062 // when the initial InitListExpr was built.
2063 InitListExpr *ILE = cast<InitListExpr>((Expr *)Result.get());
2064 ILE->setType(ResultTy);
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002065 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002066 }
Mike Stump11289f42009-09-09 15:08:12 +00002067
Douglas Gregora16548e2009-08-11 05:31:07 +00002068 /// \brief Build a new designated initializer expression.
Mike Stump11289f42009-09-09 15:08:12 +00002069 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002070 /// By default, performs semantic analysis to build the new expression.
2071 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002072 ExprResult RebuildDesignatedInitExpr(Designation &Desig,
Douglas Gregora16548e2009-08-11 05:31:07 +00002073 MultiExprArg ArrayExprs,
2074 SourceLocation EqualOrColonLoc,
2075 bool GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002076 Expr *Init) {
John McCalldadc5752010-08-24 06:29:42 +00002077 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +00002078 = SemaRef.ActOnDesignatedInitializer(Desig, EqualOrColonLoc, GNUSyntax,
John McCallb268a282010-08-23 23:25:46 +00002079 Init);
Douglas Gregora16548e2009-08-11 05:31:07 +00002080 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002081 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00002082
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002083 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +00002084 }
Mike Stump11289f42009-09-09 15:08:12 +00002085
Douglas Gregora16548e2009-08-11 05:31:07 +00002086 /// \brief Build a new value-initialized expression.
Mike Stump11289f42009-09-09 15:08:12 +00002087 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002088 /// By default, builds the implicit value initialization without performing
2089 /// any semantic analysis. Subclasses may override this routine to provide
2090 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002091 ExprResult RebuildImplicitValueInitExpr(QualType T) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002092 return new (SemaRef.Context) ImplicitValueInitExpr(T);
Douglas Gregora16548e2009-08-11 05:31:07 +00002093 }
Mike Stump11289f42009-09-09 15:08:12 +00002094
Douglas Gregora16548e2009-08-11 05:31:07 +00002095 /// \brief Build a new \c va_arg expression.
Mike Stump11289f42009-09-09 15:08:12 +00002096 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002097 /// By default, performs semantic analysis to build the new expression.
2098 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002099 ExprResult RebuildVAArgExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002100 Expr *SubExpr, TypeSourceInfo *TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002101 SourceLocation RParenLoc) {
2102 return getSema().BuildVAArgExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002103 SubExpr, TInfo,
Abramo Bagnara27db2392010-08-10 10:06:15 +00002104 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002105 }
2106
2107 /// \brief Build a new expression list in parentheses.
Mike Stump11289f42009-09-09 15:08:12 +00002108 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002109 /// By default, performs semantic analysis to build the new expression.
2110 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002111 ExprResult RebuildParenListExpr(SourceLocation LParenLoc,
Sebastian Redla9351792012-02-11 23:51:47 +00002112 MultiExprArg SubExprs,
2113 SourceLocation RParenLoc) {
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002114 return getSema().ActOnParenListExpr(LParenLoc, RParenLoc, SubExprs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002115 }
Mike Stump11289f42009-09-09 15:08:12 +00002116
Douglas Gregora16548e2009-08-11 05:31:07 +00002117 /// \brief Build a new address-of-label expression.
Mike Stump11289f42009-09-09 15:08:12 +00002118 ///
2119 /// By default, performs semantic analysis, using the name of the label
Douglas Gregora16548e2009-08-11 05:31:07 +00002120 /// rather than attempting to map the label statement itself.
2121 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002122 ExprResult RebuildAddrLabelExpr(SourceLocation AmpAmpLoc,
Chris Lattnerc8e630e2011-02-17 07:39:24 +00002123 SourceLocation LabelLoc, LabelDecl *Label) {
Chris Lattnercab02a62011-02-17 20:34:02 +00002124 return getSema().ActOnAddrLabel(AmpAmpLoc, LabelLoc, Label);
Douglas Gregora16548e2009-08-11 05:31:07 +00002125 }
Mike Stump11289f42009-09-09 15:08:12 +00002126
Douglas Gregora16548e2009-08-11 05:31:07 +00002127 /// \brief Build a new GNU statement expression.
Mike Stump11289f42009-09-09 15:08:12 +00002128 ///
Douglas Gregora16548e2009-08-11 05:31:07 +00002129 /// By default, performs semantic analysis to build the new expression.
2130 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002131 ExprResult RebuildStmtExpr(SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002132 Stmt *SubStmt,
Douglas Gregora16548e2009-08-11 05:31:07 +00002133 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002134 return getSema().ActOnStmtExpr(LParenLoc, SubStmt, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002135 }
Mike Stump11289f42009-09-09 15:08:12 +00002136
Douglas Gregora16548e2009-08-11 05:31:07 +00002137 /// \brief Build a new __builtin_choose_expr expression.
2138 ///
2139 /// By default, performs semantic analysis to build the new expression.
2140 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002141 ExprResult RebuildChooseExpr(SourceLocation BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002142 Expr *Cond, Expr *LHS, Expr *RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002143 SourceLocation RParenLoc) {
2144 return SemaRef.ActOnChooseExpr(BuiltinLoc,
John McCallb268a282010-08-23 23:25:46 +00002145 Cond, LHS, RHS,
Douglas Gregora16548e2009-08-11 05:31:07 +00002146 RParenLoc);
2147 }
Mike Stump11289f42009-09-09 15:08:12 +00002148
Peter Collingbourne91147592011-04-15 00:35:48 +00002149 /// \brief Build a new generic selection expression.
2150 ///
2151 /// By default, performs semantic analysis to build the new expression.
2152 /// Subclasses may override this routine to provide different behavior.
2153 ExprResult RebuildGenericSelectionExpr(SourceLocation KeyLoc,
2154 SourceLocation DefaultLoc,
2155 SourceLocation RParenLoc,
2156 Expr *ControllingExpr,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002157 ArrayRef<TypeSourceInfo *> Types,
2158 ArrayRef<Expr *> Exprs) {
Peter Collingbourne91147592011-04-15 00:35:48 +00002159 return getSema().CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc,
Dmitri Gribenko82360372013-05-10 13:06:58 +00002160 ControllingExpr, Types, Exprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00002161 }
2162
Douglas Gregora16548e2009-08-11 05:31:07 +00002163 /// \brief Build a new overloaded operator call expression.
2164 ///
2165 /// By default, performs semantic analysis to build the new expression.
2166 /// The semantic analysis provides the behavior of template instantiation,
2167 /// copying with transformations that turn what looks like an overloaded
Mike Stump11289f42009-09-09 15:08:12 +00002168 /// operator call into a use of a builtin operator, performing
Douglas Gregora16548e2009-08-11 05:31:07 +00002169 /// argument-dependent lookup, etc. Subclasses may override this routine to
2170 /// provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002171 ExprResult RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
Douglas Gregora16548e2009-08-11 05:31:07 +00002172 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +00002173 Expr *Callee,
2174 Expr *First,
2175 Expr *Second);
Mike Stump11289f42009-09-09 15:08:12 +00002176
2177 /// \brief Build a new C++ "named" cast expression, such as static_cast or
Douglas Gregora16548e2009-08-11 05:31:07 +00002178 /// reinterpret_cast.
2179 ///
2180 /// By default, this routine dispatches to one of the more-specific routines
Mike Stump11289f42009-09-09 15:08:12 +00002181 /// for a particular named case, e.g., RebuildCXXStaticCastExpr().
Douglas Gregora16548e2009-08-11 05:31:07 +00002182 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002183 ExprResult RebuildCXXNamedCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002184 Stmt::StmtClass Class,
2185 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002186 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002187 SourceLocation RAngleLoc,
2188 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002189 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002190 SourceLocation RParenLoc) {
2191 switch (Class) {
2192 case Stmt::CXXStaticCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002193 return getDerived().RebuildCXXStaticCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002194 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002195 SubExpr, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002196
2197 case Stmt::CXXDynamicCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002198 return getDerived().RebuildCXXDynamicCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002199 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002200 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002201
Douglas Gregora16548e2009-08-11 05:31:07 +00002202 case Stmt::CXXReinterpretCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002203 return getDerived().RebuildCXXReinterpretCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002204 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002205 SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002206 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002207
Douglas Gregora16548e2009-08-11 05:31:07 +00002208 case Stmt::CXXConstCastExprClass:
John McCall97513962010-01-15 18:39:57 +00002209 return getDerived().RebuildCXXConstCastExpr(OpLoc, LAngleLoc, TInfo,
Mike Stump11289f42009-09-09 15:08:12 +00002210 RAngleLoc, LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002211 SubExpr, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002212
Douglas Gregora16548e2009-08-11 05:31:07 +00002213 default:
David Blaikie83d382b2011-09-23 05:06:16 +00002214 llvm_unreachable("Invalid C++ named cast");
Douglas Gregora16548e2009-08-11 05:31:07 +00002215 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002216 }
Mike Stump11289f42009-09-09 15:08:12 +00002217
Douglas Gregora16548e2009-08-11 05:31:07 +00002218 /// \brief Build a new C++ static_cast expression.
2219 ///
2220 /// By default, performs semantic analysis to build the new expression.
2221 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002222 ExprResult RebuildCXXStaticCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002223 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002224 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002225 SourceLocation RAngleLoc,
2226 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002227 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002228 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002229 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_static_cast,
John McCallb268a282010-08-23 23:25:46 +00002230 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002231 SourceRange(LAngleLoc, RAngleLoc),
2232 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002233 }
2234
2235 /// \brief Build a new C++ dynamic_cast expression.
2236 ///
2237 /// By default, performs semantic analysis to build the new expression.
2238 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002239 ExprResult RebuildCXXDynamicCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002240 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002241 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002242 SourceLocation RAngleLoc,
2243 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002244 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002245 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002246 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_dynamic_cast,
John McCallb268a282010-08-23 23:25:46 +00002247 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002248 SourceRange(LAngleLoc, RAngleLoc),
2249 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002250 }
2251
2252 /// \brief Build a new C++ reinterpret_cast expression.
2253 ///
2254 /// By default, performs semantic analysis to build the new expression.
2255 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002256 ExprResult RebuildCXXReinterpretCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002257 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002258 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002259 SourceLocation RAngleLoc,
2260 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002261 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002262 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002263 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_reinterpret_cast,
John McCallb268a282010-08-23 23:25:46 +00002264 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002265 SourceRange(LAngleLoc, RAngleLoc),
2266 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002267 }
2268
2269 /// \brief Build a new C++ const_cast expression.
2270 ///
2271 /// By default, performs semantic analysis to build the new expression.
2272 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002273 ExprResult RebuildCXXConstCastExpr(SourceLocation OpLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002274 SourceLocation LAngleLoc,
John McCall97513962010-01-15 18:39:57 +00002275 TypeSourceInfo *TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002276 SourceLocation RAngleLoc,
2277 SourceLocation LParenLoc,
John McCallb268a282010-08-23 23:25:46 +00002278 Expr *SubExpr,
Douglas Gregora16548e2009-08-11 05:31:07 +00002279 SourceLocation RParenLoc) {
John McCalld377e042010-01-15 19:13:16 +00002280 return getSema().BuildCXXNamedCast(OpLoc, tok::kw_const_cast,
John McCallb268a282010-08-23 23:25:46 +00002281 TInfo, SubExpr,
John McCalld377e042010-01-15 19:13:16 +00002282 SourceRange(LAngleLoc, RAngleLoc),
2283 SourceRange(LParenLoc, RParenLoc));
Douglas Gregora16548e2009-08-11 05:31:07 +00002284 }
Mike Stump11289f42009-09-09 15:08:12 +00002285
Douglas Gregora16548e2009-08-11 05:31:07 +00002286 /// \brief Build a new C++ functional-style cast expression.
2287 ///
2288 /// By default, performs semantic analysis to build the new expression.
2289 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002290 ExprResult RebuildCXXFunctionalCastExpr(TypeSourceInfo *TInfo,
2291 SourceLocation LParenLoc,
2292 Expr *Sub,
2293 SourceLocation RParenLoc) {
2294 return getSema().BuildCXXTypeConstructExpr(TInfo, LParenLoc,
John McCallfaf5fb42010-08-26 23:41:50 +00002295 MultiExprArg(&Sub, 1),
Douglas Gregora16548e2009-08-11 05:31:07 +00002296 RParenLoc);
2297 }
Mike Stump11289f42009-09-09 15:08:12 +00002298
Douglas Gregora16548e2009-08-11 05:31:07 +00002299 /// \brief Build a new C++ typeid(type) expression.
2300 ///
2301 /// By default, performs semantic analysis to build the new expression.
2302 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002303 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002304 SourceLocation TypeidLoc,
2305 TypeSourceInfo *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002306 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002307 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002308 RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002309 }
Mike Stump11289f42009-09-09 15:08:12 +00002310
Francois Pichet9f4f2072010-09-08 12:20:18 +00002311
Douglas Gregora16548e2009-08-11 05:31:07 +00002312 /// \brief Build a new C++ typeid(expr) expression.
2313 ///
2314 /// By default, performs semantic analysis to build the new expression.
2315 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002316 ExprResult RebuildCXXTypeidExpr(QualType TypeInfoType,
Douglas Gregor9da64192010-04-26 22:37:10 +00002317 SourceLocation TypeidLoc,
John McCallb268a282010-08-23 23:25:46 +00002318 Expr *Operand,
Douglas Gregora16548e2009-08-11 05:31:07 +00002319 SourceLocation RParenLoc) {
John McCallb268a282010-08-23 23:25:46 +00002320 return getSema().BuildCXXTypeId(TypeInfoType, TypeidLoc, Operand,
Douglas Gregor9da64192010-04-26 22:37:10 +00002321 RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002322 }
2323
Francois Pichet9f4f2072010-09-08 12:20:18 +00002324 /// \brief Build a new C++ __uuidof(type) expression.
2325 ///
2326 /// By default, performs semantic analysis to build the new expression.
2327 /// Subclasses may override this routine to provide different behavior.
2328 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2329 SourceLocation TypeidLoc,
2330 TypeSourceInfo *Operand,
2331 SourceLocation RParenLoc) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002332 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
Francois Pichet9f4f2072010-09-08 12:20:18 +00002333 RParenLoc);
2334 }
2335
2336 /// \brief Build a new C++ __uuidof(expr) expression.
2337 ///
2338 /// By default, performs semantic analysis to build the new expression.
2339 /// Subclasses may override this routine to provide different behavior.
2340 ExprResult RebuildCXXUuidofExpr(QualType TypeInfoType,
2341 SourceLocation TypeidLoc,
2342 Expr *Operand,
2343 SourceLocation RParenLoc) {
2344 return getSema().BuildCXXUuidof(TypeInfoType, TypeidLoc, Operand,
2345 RParenLoc);
2346 }
2347
Douglas Gregora16548e2009-08-11 05:31:07 +00002348 /// \brief Build a new C++ "this" expression.
2349 ///
2350 /// By default, builds a new "this" expression without performing any
Mike Stump11289f42009-09-09 15:08:12 +00002351 /// semantic analysis. Subclasses may override this routine to provide
Douglas Gregora16548e2009-08-11 05:31:07 +00002352 /// different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002353 ExprResult RebuildCXXThisExpr(SourceLocation ThisLoc,
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00002354 QualType ThisType,
2355 bool isImplicit) {
Eli Friedman20139d32012-01-11 02:36:31 +00002356 getSema().CheckCXXThisCapture(ThisLoc);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002357 return new (getSema().Context) CXXThisExpr(ThisLoc, ThisType, isImplicit);
Douglas Gregora16548e2009-08-11 05:31:07 +00002358 }
2359
2360 /// \brief Build a new C++ throw expression.
2361 ///
2362 /// By default, performs semantic analysis to build the new expression.
2363 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor53e191ed2011-07-06 22:04:06 +00002364 ExprResult RebuildCXXThrowExpr(SourceLocation ThrowLoc, Expr *Sub,
2365 bool IsThrownVariableInScope) {
2366 return getSema().BuildCXXThrow(ThrowLoc, Sub, IsThrownVariableInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00002367 }
2368
2369 /// \brief Build a new C++ default-argument expression.
2370 ///
2371 /// By default, builds a new default-argument expression, which does not
2372 /// require any semantic analysis. Subclasses may override this routine to
2373 /// provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002374 ExprResult RebuildCXXDefaultArgExpr(SourceLocation Loc,
Douglas Gregor033f6752009-12-23 23:03:06 +00002375 ParmVarDecl *Param) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002376 return CXXDefaultArgExpr::Create(getSema().Context, Loc, Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00002377 }
2378
Richard Smith852c9db2013-04-20 22:23:05 +00002379 /// \brief Build a new C++11 default-initialization expression.
2380 ///
2381 /// By default, builds a new default field initialization expression, which
2382 /// does not require any semantic analysis. Subclasses may override this
2383 /// routine to provide different behavior.
2384 ExprResult RebuildCXXDefaultInitExpr(SourceLocation Loc,
2385 FieldDecl *Field) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002386 return CXXDefaultInitExpr::Create(getSema().Context, Loc, Field);
Richard Smith852c9db2013-04-20 22:23:05 +00002387 }
2388
Douglas Gregora16548e2009-08-11 05:31:07 +00002389 /// \brief Build a new C++ zero-initialization expression.
2390 ///
2391 /// By default, performs semantic analysis to build the new expression.
2392 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002393 ExprResult RebuildCXXScalarValueInitExpr(TypeSourceInfo *TSInfo,
2394 SourceLocation LParenLoc,
2395 SourceLocation RParenLoc) {
2396 return getSema().BuildCXXTypeConstructExpr(TSInfo, LParenLoc,
Dmitri Gribenko78852e92013-05-05 20:40:26 +00002397 None, RParenLoc);
Douglas Gregora16548e2009-08-11 05:31:07 +00002398 }
Mike Stump11289f42009-09-09 15:08:12 +00002399
Douglas Gregora16548e2009-08-11 05:31:07 +00002400 /// \brief Build a new C++ "new" expression.
2401 ///
2402 /// By default, performs semantic analysis to build the new expression.
2403 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002404 ExprResult RebuildCXXNewExpr(SourceLocation StartLoc,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002405 bool UseGlobal,
2406 SourceLocation PlacementLParen,
2407 MultiExprArg PlacementArgs,
2408 SourceLocation PlacementRParen,
2409 SourceRange TypeIdParens,
2410 QualType AllocatedType,
2411 TypeSourceInfo *AllocatedTypeInfo,
2412 Expr *ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002413 SourceRange DirectInitRange,
2414 Expr *Initializer) {
Mike Stump11289f42009-09-09 15:08:12 +00002415 return getSema().BuildCXXNew(StartLoc, UseGlobal,
Douglas Gregora16548e2009-08-11 05:31:07 +00002416 PlacementLParen,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002417 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00002418 PlacementRParen,
Douglas Gregorf2753b32010-07-13 15:54:32 +00002419 TypeIdParens,
Douglas Gregor0744ef62010-09-07 21:49:58 +00002420 AllocatedType,
2421 AllocatedTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00002422 ArraySize,
Sebastian Redl6047f072012-02-16 12:22:20 +00002423 DirectInitRange,
2424 Initializer);
Douglas Gregora16548e2009-08-11 05:31:07 +00002425 }
Mike Stump11289f42009-09-09 15:08:12 +00002426
Douglas Gregora16548e2009-08-11 05:31:07 +00002427 /// \brief Build a new C++ "delete" expression.
2428 ///
2429 /// By default, performs semantic analysis to build the new expression.
2430 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002431 ExprResult RebuildCXXDeleteExpr(SourceLocation StartLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00002432 bool IsGlobalDelete,
2433 bool IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002434 Expr *Operand) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002435 return getSema().ActOnCXXDelete(StartLoc, IsGlobalDelete, IsArrayForm,
John McCallb268a282010-08-23 23:25:46 +00002436 Operand);
Douglas Gregora16548e2009-08-11 05:31:07 +00002437 }
Mike Stump11289f42009-09-09 15:08:12 +00002438
Douglas Gregor29c42f22012-02-24 07:38:34 +00002439 /// \brief Build a new type trait expression.
2440 ///
2441 /// By default, performs semantic analysis to build the new expression.
2442 /// Subclasses may override this routine to provide different behavior.
2443 ExprResult RebuildTypeTrait(TypeTrait Trait,
2444 SourceLocation StartLoc,
2445 ArrayRef<TypeSourceInfo *> Args,
2446 SourceLocation RParenLoc) {
2447 return getSema().BuildTypeTrait(Trait, StartLoc, Args, RParenLoc);
2448 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002449
John Wiegley6242b6a2011-04-28 00:16:57 +00002450 /// \brief Build a new array type trait expression.
2451 ///
2452 /// By default, performs semantic analysis to build the new expression.
2453 /// Subclasses may override this routine to provide different behavior.
2454 ExprResult RebuildArrayTypeTrait(ArrayTypeTrait Trait,
2455 SourceLocation StartLoc,
2456 TypeSourceInfo *TSInfo,
2457 Expr *DimExpr,
2458 SourceLocation RParenLoc) {
2459 return getSema().BuildArrayTypeTrait(Trait, StartLoc, TSInfo, DimExpr, RParenLoc);
2460 }
2461
John Wiegleyf9f65842011-04-25 06:54:41 +00002462 /// \brief Build a new expression trait expression.
2463 ///
2464 /// By default, performs semantic analysis to build the new expression.
2465 /// Subclasses may override this routine to provide different behavior.
2466 ExprResult RebuildExpressionTrait(ExpressionTrait Trait,
2467 SourceLocation StartLoc,
2468 Expr *Queried,
2469 SourceLocation RParenLoc) {
2470 return getSema().BuildExpressionTrait(Trait, StartLoc, Queried, RParenLoc);
2471 }
2472
Mike Stump11289f42009-09-09 15:08:12 +00002473 /// \brief Build a new (previously unresolved) declaration reference
Douglas Gregora16548e2009-08-11 05:31:07 +00002474 /// expression.
2475 ///
2476 /// By default, performs semantic analysis to build the new expression.
2477 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002478 ExprResult RebuildDependentScopeDeclRefExpr(
2479 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002480 SourceLocation TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002481 const DeclarationNameInfo &NameInfo,
Richard Smithdb2630f2012-10-21 03:28:35 +00002482 const TemplateArgumentListInfo *TemplateArgs,
Reid Kleckner32506ed2014-06-12 23:03:48 +00002483 bool IsAddressOfOperand,
2484 TypeSourceInfo **RecoveryTSI) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002485 CXXScopeSpec SS;
Douglas Gregor3a43fd62011-02-25 20:49:16 +00002486 SS.Adopt(QualifierLoc);
John McCalle66edc12009-11-24 19:00:30 +00002487
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002488 if (TemplateArgs || TemplateKWLoc.isValid())
Reid Kleckner32506ed2014-06-12 23:03:48 +00002489 return getSema().BuildQualifiedTemplateIdExpr(SS, TemplateKWLoc, NameInfo,
2490 TemplateArgs);
John McCalle66edc12009-11-24 19:00:30 +00002491
Reid Kleckner32506ed2014-06-12 23:03:48 +00002492 return getSema().BuildQualifiedDeclarationNameExpr(
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002493 SS, NameInfo, IsAddressOfOperand, /*S*/nullptr, RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00002494 }
2495
2496 /// \brief Build a new template-id expression.
2497 ///
2498 /// By default, performs semantic analysis to build the new expression.
2499 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002500 ExprResult RebuildTemplateIdExpr(const CXXScopeSpec &SS,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002501 SourceLocation TemplateKWLoc,
2502 LookupResult &R,
2503 bool RequiresADL,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00002504 const TemplateArgumentListInfo *TemplateArgs) {
Abramo Bagnara7945c982012-01-27 09:46:47 +00002505 return getSema().BuildTemplateIdExpr(SS, TemplateKWLoc, R, RequiresADL,
2506 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00002507 }
2508
2509 /// \brief Build a new object-construction expression.
2510 ///
2511 /// By default, performs semantic analysis to build the new expression.
2512 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002513 ExprResult RebuildCXXConstructExpr(QualType T,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002514 SourceLocation Loc,
2515 CXXConstructorDecl *Constructor,
2516 bool IsElidable,
2517 MultiExprArg Args,
2518 bool HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002519 bool ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002520 bool StdInitListInitialization,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002521 bool RequiresZeroInit,
Chandler Carruth01718152010-10-25 08:47:36 +00002522 CXXConstructExpr::ConstructionKind ConstructKind,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002523 SourceRange ParenRange) {
Benjamin Kramerf0623432012-08-23 22:51:59 +00002524 SmallVector<Expr*, 8> ConvertedArgs;
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002525 if (getSema().CompleteConstructorCall(Constructor, Args, Loc,
Douglas Gregordb121ba2009-12-14 16:27:04 +00002526 ConvertedArgs))
John McCallfaf5fb42010-08-26 23:41:50 +00002527 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00002528
Douglas Gregordb121ba2009-12-14 16:27:04 +00002529 return getSema().BuildCXXConstructExpr(Loc, T, Constructor, IsElidable,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002530 ConvertedArgs,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00002531 HadMultipleCandidates,
Richard Smithd59b8322012-12-19 01:39:02 +00002532 ListInitialization,
Richard Smithf8adcdc2014-07-17 05:12:35 +00002533 StdInitListInitialization,
Chandler Carruth01718152010-10-25 08:47:36 +00002534 RequiresZeroInit, ConstructKind,
2535 ParenRange);
Douglas Gregora16548e2009-08-11 05:31:07 +00002536 }
2537
2538 /// \brief Build a new object-construction expression.
2539 ///
2540 /// By default, performs semantic analysis to build the new expression.
2541 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002542 ExprResult RebuildCXXTemporaryObjectExpr(TypeSourceInfo *TSInfo,
2543 SourceLocation LParenLoc,
2544 MultiExprArg Args,
2545 SourceLocation RParenLoc) {
2546 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002547 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002548 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002549 RParenLoc);
2550 }
2551
2552 /// \brief Build a new object-construction expression.
2553 ///
2554 /// By default, performs semantic analysis to build the new expression.
2555 /// Subclasses may override this routine to provide different behavior.
Douglas Gregor2b88c112010-09-08 00:15:04 +00002556 ExprResult RebuildCXXUnresolvedConstructExpr(TypeSourceInfo *TSInfo,
2557 SourceLocation LParenLoc,
2558 MultiExprArg Args,
2559 SourceLocation RParenLoc) {
2560 return getSema().BuildCXXTypeConstructExpr(TSInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002561 LParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002562 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00002563 RParenLoc);
2564 }
Mike Stump11289f42009-09-09 15:08:12 +00002565
Douglas Gregora16548e2009-08-11 05:31:07 +00002566 /// \brief Build a new member reference expression.
2567 ///
2568 /// By default, performs semantic analysis to build the new expression.
2569 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002570 ExprResult RebuildCXXDependentScopeMemberExpr(Expr *BaseE,
Douglas Gregore16af532011-02-28 18:50:33 +00002571 QualType BaseType,
2572 bool IsArrow,
2573 SourceLocation OperatorLoc,
2574 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002575 SourceLocation TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00002576 NamedDecl *FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002577 const DeclarationNameInfo &MemberNameInfo,
John McCall10eae182009-11-30 22:42:35 +00002578 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002579 CXXScopeSpec SS;
Douglas Gregore16af532011-02-28 18:50:33 +00002580 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002581
John McCallb268a282010-08-23 23:25:46 +00002582 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002583 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002584 SS, TemplateKWLoc,
2585 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00002586 MemberNameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002587 TemplateArgs, /*S*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +00002588 }
2589
John McCall10eae182009-11-30 22:42:35 +00002590 /// \brief Build a new member reference expression.
Douglas Gregor308047d2009-09-09 00:23:06 +00002591 ///
2592 /// By default, performs semantic analysis to build the new expression.
2593 /// Subclasses may override this routine to provide different behavior.
Richard Smithcab9a7d2011-10-26 19:06:56 +00002594 ExprResult RebuildUnresolvedMemberExpr(Expr *BaseE, QualType BaseType,
2595 SourceLocation OperatorLoc,
2596 bool IsArrow,
2597 NestedNameSpecifierLoc QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002598 SourceLocation TemplateKWLoc,
Richard Smithcab9a7d2011-10-26 19:06:56 +00002599 NamedDecl *FirstQualifierInScope,
2600 LookupResult &R,
John McCall10eae182009-11-30 22:42:35 +00002601 const TemplateArgumentListInfo *TemplateArgs) {
Douglas Gregor308047d2009-09-09 00:23:06 +00002602 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00002603 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002604
John McCallb268a282010-08-23 23:25:46 +00002605 return SemaRef.BuildMemberReferenceExpr(BaseE, BaseType,
John McCall2d74de92009-12-01 22:10:20 +00002606 OperatorLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002607 SS, TemplateKWLoc,
2608 FirstQualifierInScope,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002609 R, TemplateArgs, /*S*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00002610 }
Mike Stump11289f42009-09-09 15:08:12 +00002611
Sebastian Redl4202c0f2010-09-10 20:55:43 +00002612 /// \brief Build a new noexcept expression.
2613 ///
2614 /// By default, performs semantic analysis to build the new expression.
2615 /// Subclasses may override this routine to provide different behavior.
2616 ExprResult RebuildCXXNoexceptExpr(SourceRange Range, Expr *Arg) {
2617 return SemaRef.BuildCXXNoexceptExpr(Range.getBegin(), Arg, Range.getEnd());
2618 }
2619
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002620 /// \brief Build a new expression to compute the length of a parameter pack.
Richard Smithd784e682015-09-23 21:41:42 +00002621 ExprResult RebuildSizeOfPackExpr(SourceLocation OperatorLoc,
2622 NamedDecl *Pack,
Chad Rosier1dcde962012-08-08 18:46:20 +00002623 SourceLocation PackLoc,
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002624 SourceLocation RParenLoc,
Richard Smithd784e682015-09-23 21:41:42 +00002625 Optional<unsigned> Length,
2626 ArrayRef<TemplateArgument> PartialArgs) {
2627 return SizeOfPackExpr::Create(SemaRef.Context, OperatorLoc, Pack, PackLoc,
2628 RParenLoc, Length, PartialArgs);
Douglas Gregor820ba7b2011-01-04 17:33:58 +00002629 }
Ted Kremeneke65b0862012-03-06 20:05:56 +00002630
Patrick Beard0caa3942012-04-19 00:25:12 +00002631 /// \brief Build a new Objective-C boxed expression.
2632 ///
2633 /// By default, performs semantic analysis to build the new expression.
2634 /// Subclasses may override this routine to provide different behavior.
2635 ExprResult RebuildObjCBoxedExpr(SourceRange SR, Expr *ValueExpr) {
2636 return getSema().BuildObjCBoxedExpr(SR, ValueExpr);
2637 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002638
Ted Kremeneke65b0862012-03-06 20:05:56 +00002639 /// \brief Build a new Objective-C array literal.
2640 ///
2641 /// By default, performs semantic analysis to build the new expression.
2642 /// Subclasses may override this routine to provide different behavior.
2643 ExprResult RebuildObjCArrayLiteral(SourceRange Range,
2644 Expr **Elements, unsigned NumElements) {
Chad Rosier1dcde962012-08-08 18:46:20 +00002645 return getSema().BuildObjCArrayLiteral(Range,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002646 MultiExprArg(Elements, NumElements));
2647 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002648
2649 ExprResult RebuildObjCSubscriptRefExpr(SourceLocation RB,
Ted Kremeneke65b0862012-03-06 20:05:56 +00002650 Expr *Base, Expr *Key,
2651 ObjCMethodDecl *getterMethod,
2652 ObjCMethodDecl *setterMethod) {
2653 return getSema().BuildObjCSubscriptExpression(RB, Base, Key,
2654 getterMethod, setterMethod);
2655 }
2656
2657 /// \brief Build a new Objective-C dictionary literal.
2658 ///
2659 /// By default, performs semantic analysis to build the new expression.
2660 /// Subclasses may override this routine to provide different behavior.
2661 ExprResult RebuildObjCDictionaryLiteral(SourceRange Range,
2662 ObjCDictionaryElement *Elements,
2663 unsigned NumElements) {
2664 return getSema().BuildObjCDictionaryLiteral(Range, Elements, NumElements);
2665 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002666
James Dennett2a4d13c2012-06-15 07:13:21 +00002667 /// \brief Build a new Objective-C \@encode expression.
Douglas Gregora16548e2009-08-11 05:31:07 +00002668 ///
2669 /// By default, performs semantic analysis to build the new expression.
2670 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002671 ExprResult RebuildObjCEncodeExpr(SourceLocation AtLoc,
Douglas Gregorabd9e962010-04-20 15:39:42 +00002672 TypeSourceInfo *EncodeTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00002673 SourceLocation RParenLoc) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002674 return SemaRef.BuildObjCEncodeExpression(AtLoc, EncodeTypeInfo, RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002675 }
Douglas Gregora16548e2009-08-11 05:31:07 +00002676
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002677 /// \brief Build a new Objective-C class message.
John McCalldadc5752010-08-24 06:29:42 +00002678 ExprResult RebuildObjCMessageExpr(TypeSourceInfo *ReceiverTypeInfo,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002679 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002680 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002681 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002682 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002683 MultiExprArg Args,
2684 SourceLocation RBracLoc) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002685 return SemaRef.BuildClassMessage(ReceiverTypeInfo,
2686 ReceiverTypeInfo->getType(),
2687 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002688 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002689 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002690 }
2691
2692 /// \brief Build a new Objective-C instance message.
John McCalldadc5752010-08-24 06:29:42 +00002693 ExprResult RebuildObjCMessageExpr(Expr *Receiver,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002694 Selector Sel,
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002695 ArrayRef<SourceLocation> SelectorLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002696 ObjCMethodDecl *Method,
Chad Rosier1dcde962012-08-08 18:46:20 +00002697 SourceLocation LBracLoc,
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002698 MultiExprArg Args,
2699 SourceLocation RBracLoc) {
John McCallb268a282010-08-23 23:25:46 +00002700 return SemaRef.BuildInstanceMessage(Receiver,
2701 Receiver->getType(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002702 /*SuperLoc=*/SourceLocation(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +00002703 Sel, Method, LBracLoc, SelectorLocs,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00002704 RBracLoc, Args);
Douglas Gregorc298ffc2010-04-22 16:44:27 +00002705 }
2706
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002707 /// \brief Build a new Objective-C instance/class message to 'super'.
2708 ExprResult RebuildObjCMessageExpr(SourceLocation SuperLoc,
2709 Selector Sel,
2710 ArrayRef<SourceLocation> SelectorLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002711 QualType SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002712 ObjCMethodDecl *Method,
2713 SourceLocation LBracLoc,
2714 MultiExprArg Args,
2715 SourceLocation RBracLoc) {
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002716 return Method->isInstanceMethod() ? SemaRef.BuildInstanceMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002717 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002718 SuperLoc,
2719 Sel, Method, LBracLoc, SelectorLocs,
2720 RBracLoc, Args)
2721 : SemaRef.BuildClassMessage(nullptr,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +00002722 SuperType,
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +00002723 SuperLoc,
2724 Sel, Method, LBracLoc, SelectorLocs,
2725 RBracLoc, Args);
2726
2727
2728 }
2729
Douglas Gregord51d90d2010-04-26 20:11:03 +00002730 /// \brief Build a new Objective-C ivar reference expression.
2731 ///
2732 /// By default, performs semantic analysis to build the new expression.
2733 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002734 ExprResult RebuildObjCIvarRefExpr(Expr *BaseArg, ObjCIvarDecl *Ivar,
Douglas Gregord51d90d2010-04-26 20:11:03 +00002735 SourceLocation IvarLoc,
2736 bool IsArrow, bool IsFreeIvar) {
2737 // FIXME: We lose track of the IsFreeIvar bit.
2738 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002739 DeclarationNameInfo NameInfo(Ivar->getDeclName(), IvarLoc);
2740 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Abramo Bagnara7945c982012-01-27 09:46:47 +00002741 /*FIXME:*/IvarLoc, IsArrow,
2742 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002743 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002744 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002745 /*TemplateArgs=*/nullptr,
2746 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002747 }
Douglas Gregor9faee212010-04-26 20:47:02 +00002748
2749 /// \brief Build a new Objective-C property reference expression.
2750 ///
2751 /// By default, performs semantic analysis to build the new expression.
2752 /// Subclasses may override this routine to provide different behavior.
Chad Rosier1dcde962012-08-08 18:46:20 +00002753 ExprResult RebuildObjCPropertyRefExpr(Expr *BaseArg,
John McCall526ab472011-10-25 17:37:35 +00002754 ObjCPropertyDecl *Property,
2755 SourceLocation PropertyLoc) {
Douglas Gregor9faee212010-04-26 20:47:02 +00002756 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002757 DeclarationNameInfo NameInfo(Property->getDeclName(), PropertyLoc);
2758 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
2759 /*FIXME:*/PropertyLoc,
2760 /*IsArrow=*/false,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002761 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002762 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002763 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002764 /*TemplateArgs=*/nullptr,
2765 /*S=*/nullptr);
Douglas Gregor9faee212010-04-26 20:47:02 +00002766 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002767
John McCallb7bd14f2010-12-02 01:19:52 +00002768 /// \brief Build a new Objective-C property reference expression.
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002769 ///
2770 /// By default, performs semantic analysis to build the new expression.
John McCallb7bd14f2010-12-02 01:19:52 +00002771 /// Subclasses may override this routine to provide different behavior.
2772 ExprResult RebuildObjCPropertyRefExpr(Expr *Base, QualType T,
2773 ObjCMethodDecl *Getter,
2774 ObjCMethodDecl *Setter,
2775 SourceLocation PropertyLoc) {
2776 // Since these expressions can only be value-dependent, we do not
2777 // need to perform semantic analysis again.
2778 return Owned(
2779 new (getSema().Context) ObjCPropertyRefExpr(Getter, Setter, T,
2780 VK_LValue, OK_ObjCProperty,
2781 PropertyLoc, Base));
Douglas Gregorb7e20eb2010-04-26 21:04:54 +00002782 }
2783
Douglas Gregord51d90d2010-04-26 20:11:03 +00002784 /// \brief Build a new Objective-C "isa" expression.
2785 ///
2786 /// By default, performs semantic analysis to build the new expression.
2787 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002788 ExprResult RebuildObjCIsaExpr(Expr *BaseArg, SourceLocation IsaLoc,
Richard Smitha0edd302014-05-31 00:18:32 +00002789 SourceLocation OpLoc, bool IsArrow) {
Douglas Gregord51d90d2010-04-26 20:11:03 +00002790 CXXScopeSpec SS;
Richard Smitha0edd302014-05-31 00:18:32 +00002791 DeclarationNameInfo NameInfo(&getSema().Context.Idents.get("isa"), IsaLoc);
2792 return getSema().BuildMemberReferenceExpr(BaseArg, BaseArg->getType(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +00002793 OpLoc, IsArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +00002794 SS, SourceLocation(),
Craig Topperc3ec1492014-05-26 06:22:03 +00002795 /*FirstQualifierInScope=*/nullptr,
Richard Smitha0edd302014-05-31 00:18:32 +00002796 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +00002797 /*TemplateArgs=*/nullptr,
2798 /*S=*/nullptr);
Douglas Gregord51d90d2010-04-26 20:11:03 +00002799 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002800
Douglas Gregora16548e2009-08-11 05:31:07 +00002801 /// \brief Build a new shuffle vector expression.
2802 ///
2803 /// By default, performs semantic analysis to build the new expression.
2804 /// Subclasses may override this routine to provide different behavior.
John McCalldadc5752010-08-24 06:29:42 +00002805 ExprResult RebuildShuffleVectorExpr(SourceLocation BuiltinLoc,
John McCall7decc9e2010-11-18 06:31:45 +00002806 MultiExprArg SubExprs,
2807 SourceLocation RParenLoc) {
Douglas Gregora16548e2009-08-11 05:31:07 +00002808 // Find the declaration for __builtin_shufflevector
Mike Stump11289f42009-09-09 15:08:12 +00002809 const IdentifierInfo &Name
Douglas Gregora16548e2009-08-11 05:31:07 +00002810 = SemaRef.Context.Idents.get("__builtin_shufflevector");
2811 TranslationUnitDecl *TUDecl = SemaRef.Context.getTranslationUnitDecl();
2812 DeclContext::lookup_result Lookup = TUDecl->lookup(DeclarationName(&Name));
David Blaikieff7d47a2012-12-19 00:45:41 +00002813 assert(!Lookup.empty() && "No __builtin_shufflevector?");
Mike Stump11289f42009-09-09 15:08:12 +00002814
Douglas Gregora16548e2009-08-11 05:31:07 +00002815 // Build a reference to the __builtin_shufflevector builtin
David Blaikieff7d47a2012-12-19 00:45:41 +00002816 FunctionDecl *Builtin = cast<FunctionDecl>(Lookup.front());
Eli Friedman34866c72012-08-31 00:14:07 +00002817 Expr *Callee = new (SemaRef.Context) DeclRefExpr(Builtin, false,
2818 SemaRef.Context.BuiltinFnTy,
2819 VK_RValue, BuiltinLoc);
2820 QualType CalleePtrTy = SemaRef.Context.getPointerType(Builtin->getType());
2821 Callee = SemaRef.ImpCastExprToType(Callee, CalleePtrTy,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002822 CK_BuiltinFnToFnPtr).get();
Mike Stump11289f42009-09-09 15:08:12 +00002823
2824 // Build the CallExpr
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002825 ExprResult TheCall = new (SemaRef.Context) CallExpr(
Alp Toker314cc812014-01-25 16:55:45 +00002826 SemaRef.Context, Callee, SubExprs, Builtin->getCallResultType(),
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002827 Expr::getValueKindForType(Builtin->getReturnType()), RParenLoc);
Mike Stump11289f42009-09-09 15:08:12 +00002828
Douglas Gregora16548e2009-08-11 05:31:07 +00002829 // Type-check the __builtin_shufflevector expression.
Nikola Smiljanic01a75982014-05-29 10:55:11 +00002830 return SemaRef.SemaBuiltinShuffleVector(cast<CallExpr>(TheCall.get()));
Douglas Gregora16548e2009-08-11 05:31:07 +00002831 }
John McCall31f82722010-11-12 08:19:04 +00002832
Hal Finkelc4d7c822013-09-18 03:29:45 +00002833 /// \brief Build a new convert vector expression.
2834 ExprResult RebuildConvertVectorExpr(SourceLocation BuiltinLoc,
2835 Expr *SrcExpr, TypeSourceInfo *DstTInfo,
2836 SourceLocation RParenLoc) {
2837 return SemaRef.SemaConvertVectorExpr(SrcExpr, DstTInfo,
2838 BuiltinLoc, RParenLoc);
2839 }
2840
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002841 /// \brief Build a new template argument pack expansion.
2842 ///
2843 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002844 /// for a template argument. Subclasses may override this routine to provide
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002845 /// different behavior.
2846 TemplateArgumentLoc RebuildPackExpansion(TemplateArgumentLoc Pattern,
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002847 SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002848 Optional<unsigned> NumExpansions) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002849 switch (Pattern.getArgument().getKind()) {
Douglas Gregor98318c22011-01-03 21:37:45 +00002850 case TemplateArgument::Expression: {
2851 ExprResult Result
Douglas Gregorb8840002011-01-14 21:20:45 +00002852 = getSema().CheckPackExpansion(Pattern.getSourceExpression(),
2853 EllipsisLoc, NumExpansions);
Douglas Gregor98318c22011-01-03 21:37:45 +00002854 if (Result.isInvalid())
2855 return TemplateArgumentLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00002856
Douglas Gregor98318c22011-01-03 21:37:45 +00002857 return TemplateArgumentLoc(Result.get(), Result.get());
2858 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002859
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002860 case TemplateArgument::Template:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002861 return TemplateArgumentLoc(TemplateArgument(
2862 Pattern.getArgument().getAsTemplate(),
Douglas Gregore1d60df2011-01-14 23:41:42 +00002863 NumExpansions),
Douglas Gregor9d802122011-03-02 17:09:35 +00002864 Pattern.getTemplateQualifierLoc(),
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002865 Pattern.getTemplateNameLoc(),
2866 EllipsisLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00002867
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002868 case TemplateArgument::Null:
2869 case TemplateArgument::Integral:
2870 case TemplateArgument::Declaration:
2871 case TemplateArgument::Pack:
Douglas Gregore4ff4b52011-01-05 18:58:31 +00002872 case TemplateArgument::TemplateExpansion:
Eli Friedmanb826a002012-09-26 02:36:12 +00002873 case TemplateArgument::NullPtr:
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002874 llvm_unreachable("Pack expansion pattern has no parameter packs");
Chad Rosier1dcde962012-08-08 18:46:20 +00002875
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002876 case TemplateArgument::Type:
Chad Rosier1dcde962012-08-08 18:46:20 +00002877 if (TypeSourceInfo *Expansion
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002878 = getSema().CheckPackExpansion(Pattern.getTypeSourceInfo(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00002879 EllipsisLoc,
2880 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002881 return TemplateArgumentLoc(TemplateArgument(Expansion->getType()),
2882 Expansion);
2883 break;
2884 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002885
Douglas Gregor840bd6c2010-12-20 22:05:00 +00002886 return TemplateArgumentLoc();
2887 }
Chad Rosier1dcde962012-08-08 18:46:20 +00002888
Douglas Gregor968f23a2011-01-03 19:31:53 +00002889 /// \brief Build a new expression pack expansion.
2890 ///
2891 /// By default, performs semantic analysis to build a new pack expansion
Chad Rosier1dcde962012-08-08 18:46:20 +00002892 /// for an expression. Subclasses may override this routine to provide
Douglas Gregor968f23a2011-01-03 19:31:53 +00002893 /// different behavior.
Douglas Gregorb8840002011-01-14 21:20:45 +00002894 ExprResult RebuildPackExpansion(Expr *Pattern, SourceLocation EllipsisLoc,
David Blaikie05785d12013-02-20 22:23:23 +00002895 Optional<unsigned> NumExpansions) {
Douglas Gregorb8840002011-01-14 21:20:45 +00002896 return getSema().CheckPackExpansion(Pattern, EllipsisLoc, NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00002897 }
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002898
Richard Smith0f0af192014-11-08 05:07:16 +00002899 /// \brief Build a new C++1z fold-expression.
2900 ///
2901 /// By default, performs semantic analysis in order to build a new fold
2902 /// expression.
2903 ExprResult RebuildCXXFoldExpr(SourceLocation LParenLoc, Expr *LHS,
2904 BinaryOperatorKind Operator,
2905 SourceLocation EllipsisLoc, Expr *RHS,
2906 SourceLocation RParenLoc) {
2907 return getSema().BuildCXXFoldExpr(LParenLoc, LHS, Operator, EllipsisLoc,
2908 RHS, RParenLoc);
2909 }
2910
2911 /// \brief Build an empty C++1z fold-expression with the given operator.
2912 ///
2913 /// By default, produces the fallback value for the fold-expression, or
2914 /// produce an error if there is no fallback value.
2915 ExprResult RebuildEmptyCXXFoldExpr(SourceLocation EllipsisLoc,
2916 BinaryOperatorKind Operator) {
2917 return getSema().BuildEmptyCXXFoldExpr(EllipsisLoc, Operator);
2918 }
2919
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002920 /// \brief Build a new atomic operation expression.
2921 ///
2922 /// By default, performs semantic analysis to build the new expression.
2923 /// Subclasses may override this routine to provide different behavior.
2924 ExprResult RebuildAtomicExpr(SourceLocation BuiltinLoc,
2925 MultiExprArg SubExprs,
2926 QualType RetTy,
2927 AtomicExpr::AtomicOp Op,
2928 SourceLocation RParenLoc) {
2929 // Just create the expression; there is not any interesting semantic
2930 // analysis here because we can't actually build an AtomicExpr until
2931 // we are sure it is semantically sound.
Benjamin Kramerc215e762012-08-24 11:54:20 +00002932 return new (SemaRef.Context) AtomicExpr(BuiltinLoc, SubExprs, RetTy, Op,
Eli Friedman8d3e43f2011-10-14 22:48:56 +00002933 RParenLoc);
2934 }
2935
John McCall31f82722010-11-12 08:19:04 +00002936private:
Douglas Gregor14454802011-02-25 02:25:35 +00002937 TypeLoc TransformTypeInObjectScope(TypeLoc TL,
2938 QualType ObjectType,
2939 NamedDecl *FirstQualifierInScope,
2940 CXXScopeSpec &SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00002941
2942 TypeSourceInfo *TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
2943 QualType ObjectType,
2944 NamedDecl *FirstQualifierInScope,
2945 CXXScopeSpec &SS);
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00002946
2947 TypeSourceInfo *TransformTSIInObjectScope(TypeLoc TL, QualType ObjectType,
2948 NamedDecl *FirstQualifierInScope,
2949 CXXScopeSpec &SS);
Douglas Gregord6ff3322009-08-04 16:50:30 +00002950};
Douglas Gregora16548e2009-08-11 05:31:07 +00002951
Douglas Gregorebe10102009-08-20 07:17:43 +00002952template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00002953StmtResult TreeTransform<Derived>::TransformStmt(Stmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00002954 if (!S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002955 return S;
Mike Stump11289f42009-09-09 15:08:12 +00002956
Douglas Gregorebe10102009-08-20 07:17:43 +00002957 switch (S->getStmtClass()) {
2958 case Stmt::NoStmtClass: break;
Mike Stump11289f42009-09-09 15:08:12 +00002959
Douglas Gregorebe10102009-08-20 07:17:43 +00002960 // Transform individual statement nodes
2961#define STMT(Node, Parent) \
2962 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(S));
John McCallbd066782011-02-09 08:16:59 +00002963#define ABSTRACT_STMT(Node)
Douglas Gregorebe10102009-08-20 07:17:43 +00002964#define EXPR(Node, Parent)
Alexis Hunt656bb312010-05-05 15:24:00 +00002965#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00002966
Douglas Gregorebe10102009-08-20 07:17:43 +00002967 // Transform expressions by calling TransformExpr.
2968#define STMT(Node, Parent)
Alexis Huntabb2ac82010-05-18 06:22:21 +00002969#define ABSTRACT_STMT(Stmt)
Douglas Gregorebe10102009-08-20 07:17:43 +00002970#define EXPR(Node, Parent) case Stmt::Node##Class:
Alexis Hunt656bb312010-05-05 15:24:00 +00002971#include "clang/AST/StmtNodes.inc"
Douglas Gregorebe10102009-08-20 07:17:43 +00002972 {
John McCalldadc5752010-08-24 06:29:42 +00002973 ExprResult E = getDerived().TransformExpr(cast<Expr>(S));
Douglas Gregorebe10102009-08-20 07:17:43 +00002974 if (E.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00002975 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00002976
Richard Smith945f8d32013-01-14 22:39:08 +00002977 return getSema().ActOnExprStmt(E);
Douglas Gregorebe10102009-08-20 07:17:43 +00002978 }
Mike Stump11289f42009-09-09 15:08:12 +00002979 }
2980
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00002981 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00002982}
Mike Stump11289f42009-09-09 15:08:12 +00002983
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00002984template<typename Derived>
2985OMPClause *TreeTransform<Derived>::TransformOMPClause(OMPClause *S) {
2986 if (!S)
2987 return S;
2988
2989 switch (S->getClauseKind()) {
2990 default: break;
2991 // Transform individual clause nodes
2992#define OPENMP_CLAUSE(Name, Class) \
2993 case OMPC_ ## Name : \
2994 return getDerived().Transform ## Class(cast<Class>(S));
2995#include "clang/Basic/OpenMPKinds.def"
2996 }
2997
2998 return S;
2999}
3000
Mike Stump11289f42009-09-09 15:08:12 +00003001
Douglas Gregore922c772009-08-04 22:27:00 +00003002template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00003003ExprResult TreeTransform<Derived>::TransformExpr(Expr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00003004 if (!E)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003005 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00003006
3007 switch (E->getStmtClass()) {
3008 case Stmt::NoStmtClass: break;
3009#define STMT(Node, Parent) case Stmt::Node##Class: break;
Alexis Huntabb2ac82010-05-18 06:22:21 +00003010#define ABSTRACT_STMT(Stmt)
Douglas Gregora16548e2009-08-11 05:31:07 +00003011#define EXPR(Node, Parent) \
John McCall47f29ea2009-12-08 09:21:05 +00003012 case Stmt::Node##Class: return getDerived().Transform##Node(cast<Node>(E));
Alexis Hunt656bb312010-05-05 15:24:00 +00003013#include "clang/AST/StmtNodes.inc"
Mike Stump11289f42009-09-09 15:08:12 +00003014 }
3015
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003016 return E;
Douglas Gregor766b0bb2009-08-06 22:17:10 +00003017}
3018
3019template<typename Derived>
Richard Smithd59b8322012-12-19 01:39:02 +00003020ExprResult TreeTransform<Derived>::TransformInitializer(Expr *Init,
Richard Smithc6abd962014-07-25 01:12:44 +00003021 bool NotCopyInit) {
Richard Smithd59b8322012-12-19 01:39:02 +00003022 // Initializers are instantiated like expressions, except that various outer
3023 // layers are stripped.
3024 if (!Init)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00003025 return Init;
Richard Smithd59b8322012-12-19 01:39:02 +00003026
3027 if (ExprWithCleanups *ExprTemp = dyn_cast<ExprWithCleanups>(Init))
3028 Init = ExprTemp->getSubExpr();
3029
Richard Smithe6ca4752013-05-30 22:40:16 +00003030 if (MaterializeTemporaryExpr *MTE = dyn_cast<MaterializeTemporaryExpr>(Init))
3031 Init = MTE->GetTemporaryExpr();
3032
Richard Smithd59b8322012-12-19 01:39:02 +00003033 while (CXXBindTemporaryExpr *Binder = dyn_cast<CXXBindTemporaryExpr>(Init))
3034 Init = Binder->getSubExpr();
3035
3036 if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(Init))
3037 Init = ICE->getSubExprAsWritten();
3038
Richard Smithcc1b96d2013-06-12 22:31:48 +00003039 if (CXXStdInitializerListExpr *ILE =
3040 dyn_cast<CXXStdInitializerListExpr>(Init))
Richard Smithc6abd962014-07-25 01:12:44 +00003041 return TransformInitializer(ILE->getSubExpr(), NotCopyInit);
Richard Smithcc1b96d2013-06-12 22:31:48 +00003042
Richard Smithc6abd962014-07-25 01:12:44 +00003043 // If this is copy-initialization, we only need to reconstruct
Richard Smith38a549b2012-12-21 08:13:35 +00003044 // InitListExprs. Other forms of copy-initialization will be a no-op if
3045 // the initializer is already the right type.
3046 CXXConstructExpr *Construct = dyn_cast<CXXConstructExpr>(Init);
Richard Smithc6abd962014-07-25 01:12:44 +00003047 if (!NotCopyInit && !(Construct && Construct->isListInitialization()))
Richard Smith38a549b2012-12-21 08:13:35 +00003048 return getDerived().TransformExpr(Init);
3049
3050 // Revert value-initialization back to empty parens.
3051 if (CXXScalarValueInitExpr *VIE = dyn_cast<CXXScalarValueInitExpr>(Init)) {
3052 SourceRange Parens = VIE->getSourceRange();
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003053 return getDerived().RebuildParenListExpr(Parens.getBegin(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003054 Parens.getEnd());
3055 }
3056
3057 // FIXME: We shouldn't build ImplicitValueInitExprs for direct-initialization.
3058 if (isa<ImplicitValueInitExpr>(Init))
Dmitri Gribenko78852e92013-05-05 20:40:26 +00003059 return getDerived().RebuildParenListExpr(SourceLocation(), None,
Richard Smith38a549b2012-12-21 08:13:35 +00003060 SourceLocation());
3061
3062 // Revert initialization by constructor back to a parenthesized or braced list
3063 // of expressions. Any other form of initializer can just be reused directly.
3064 if (!Construct || isa<CXXTemporaryObjectExpr>(Construct))
Richard Smithd59b8322012-12-19 01:39:02 +00003065 return getDerived().TransformExpr(Init);
3066
Richard Smithf8adcdc2014-07-17 05:12:35 +00003067 // If the initialization implicitly converted an initializer list to a
3068 // std::initializer_list object, unwrap the std::initializer_list too.
3069 if (Construct && Construct->isStdInitListInitialization())
Richard Smithc6abd962014-07-25 01:12:44 +00003070 return TransformInitializer(Construct->getArg(0), NotCopyInit);
Richard Smithf8adcdc2014-07-17 05:12:35 +00003071
Richard Smithd59b8322012-12-19 01:39:02 +00003072 SmallVector<Expr*, 8> NewArgs;
3073 bool ArgChanged = false;
3074 if (getDerived().TransformExprs(Construct->getArgs(), Construct->getNumArgs(),
Richard Smithc6abd962014-07-25 01:12:44 +00003075 /*IsCall*/true, NewArgs, &ArgChanged))
Richard Smithd59b8322012-12-19 01:39:02 +00003076 return ExprError();
3077
3078 // If this was list initialization, revert to list form.
3079 if (Construct->isListInitialization())
3080 return getDerived().RebuildInitList(Construct->getLocStart(), NewArgs,
3081 Construct->getLocEnd(),
3082 Construct->getType());
3083
Richard Smithd59b8322012-12-19 01:39:02 +00003084 // Build a ParenListExpr to represent anything else.
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00003085 SourceRange Parens = Construct->getParenOrBraceRange();
Richard Smith95b83e92014-07-10 20:53:43 +00003086 if (Parens.isInvalid()) {
3087 // This was a variable declaration's initialization for which no initializer
3088 // was specified.
3089 assert(NewArgs.empty() &&
3090 "no parens or braces but have direct init with arguments?");
3091 return ExprEmpty();
3092 }
Richard Smithd59b8322012-12-19 01:39:02 +00003093 return getDerived().RebuildParenListExpr(Parens.getBegin(), NewArgs,
3094 Parens.getEnd());
3095}
3096
3097template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00003098bool TreeTransform<Derived>::TransformExprs(Expr **Inputs,
3099 unsigned NumInputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003100 bool IsCall,
Chris Lattner01cf8db2011-07-20 06:58:45 +00003101 SmallVectorImpl<Expr *> &Outputs,
Douglas Gregora3efea12011-01-03 19:04:46 +00003102 bool *ArgChanged) {
3103 for (unsigned I = 0; I != NumInputs; ++I) {
3104 // If requested, drop call arguments that need to be dropped.
3105 if (IsCall && getDerived().DropCallArgument(Inputs[I])) {
3106 if (ArgChanged)
3107 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003108
Douglas Gregora3efea12011-01-03 19:04:46 +00003109 break;
3110 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003111
Douglas Gregor968f23a2011-01-03 19:31:53 +00003112 if (PackExpansionExpr *Expansion = dyn_cast<PackExpansionExpr>(Inputs[I])) {
3113 Expr *Pattern = Expansion->getPattern();
Chad Rosier1dcde962012-08-08 18:46:20 +00003114
Chris Lattner01cf8db2011-07-20 06:58:45 +00003115 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003116 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3117 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003118
Douglas Gregor968f23a2011-01-03 19:31:53 +00003119 // Determine whether the set of unexpanded parameter packs can and should
3120 // be expanded.
3121 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003122 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003123 Optional<unsigned> OrigNumExpansions = Expansion->getNumExpansions();
3124 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor968f23a2011-01-03 19:31:53 +00003125 if (getDerived().TryExpandParameterPacks(Expansion->getEllipsisLoc(),
3126 Pattern->getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003127 Unexpanded,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003128 Expand, RetainExpansion,
3129 NumExpansions))
Douglas Gregor968f23a2011-01-03 19:31:53 +00003130 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003131
Douglas Gregor968f23a2011-01-03 19:31:53 +00003132 if (!Expand) {
3133 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003134 // transformation on the pack expansion, producing another pack
Douglas Gregor968f23a2011-01-03 19:31:53 +00003135 // expansion.
3136 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
3137 ExprResult OutPattern = getDerived().TransformExpr(Pattern);
3138 if (OutPattern.isInvalid())
3139 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003140
3141 ExprResult Out = getDerived().RebuildPackExpansion(OutPattern.get(),
Douglas Gregorb8840002011-01-14 21:20:45 +00003142 Expansion->getEllipsisLoc(),
3143 NumExpansions);
Douglas Gregor968f23a2011-01-03 19:31:53 +00003144 if (Out.isInvalid())
3145 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003146
Douglas Gregor968f23a2011-01-03 19:31:53 +00003147 if (ArgChanged)
3148 *ArgChanged = true;
3149 Outputs.push_back(Out.get());
3150 continue;
3151 }
John McCall542e7c62011-07-06 07:30:07 +00003152
3153 // Record right away that the argument was changed. This needs
3154 // to happen even if the array expands to nothing.
3155 if (ArgChanged) *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003156
Douglas Gregor968f23a2011-01-03 19:31:53 +00003157 // The transform has determined that we should perform an elementwise
3158 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003159 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor968f23a2011-01-03 19:31:53 +00003160 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3161 ExprResult Out = getDerived().TransformExpr(Pattern);
3162 if (Out.isInvalid())
3163 return true;
3164
Richard Smith9467be42014-06-06 17:33:35 +00003165 // FIXME: Can this happen? We should not try to expand the pack
3166 // in this case.
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003167 if (Out.get()->containsUnexpandedParameterPack()) {
Richard Smith9467be42014-06-06 17:33:35 +00003168 Out = getDerived().RebuildPackExpansion(
3169 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003170 if (Out.isInvalid())
3171 return true;
3172 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003173
Douglas Gregor968f23a2011-01-03 19:31:53 +00003174 Outputs.push_back(Out.get());
3175 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003176
Richard Smith9467be42014-06-06 17:33:35 +00003177 // If we're supposed to retain a pack expansion, do so by temporarily
3178 // forgetting the partially-substituted parameter pack.
3179 if (RetainExpansion) {
3180 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
3181
3182 ExprResult Out = getDerived().TransformExpr(Pattern);
3183 if (Out.isInvalid())
3184 return true;
3185
3186 Out = getDerived().RebuildPackExpansion(
3187 Out.get(), Expansion->getEllipsisLoc(), OrigNumExpansions);
3188 if (Out.isInvalid())
3189 return true;
3190
3191 Outputs.push_back(Out.get());
3192 }
3193
Douglas Gregor968f23a2011-01-03 19:31:53 +00003194 continue;
3195 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003196
Richard Smithd59b8322012-12-19 01:39:02 +00003197 ExprResult Result =
3198 IsCall ? getDerived().TransformInitializer(Inputs[I], /*DirectInit*/false)
3199 : getDerived().TransformExpr(Inputs[I]);
Douglas Gregora3efea12011-01-03 19:04:46 +00003200 if (Result.isInvalid())
3201 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003202
Douglas Gregora3efea12011-01-03 19:04:46 +00003203 if (Result.get() != Inputs[I] && ArgChanged)
3204 *ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003205
3206 Outputs.push_back(Result.get());
Douglas Gregora3efea12011-01-03 19:04:46 +00003207 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003208
Douglas Gregora3efea12011-01-03 19:04:46 +00003209 return false;
3210}
3211
3212template<typename Derived>
Douglas Gregor14454802011-02-25 02:25:35 +00003213NestedNameSpecifierLoc
3214TreeTransform<Derived>::TransformNestedNameSpecifierLoc(
3215 NestedNameSpecifierLoc NNS,
3216 QualType ObjectType,
3217 NamedDecl *FirstQualifierInScope) {
Chris Lattner01cf8db2011-07-20 06:58:45 +00003218 SmallVector<NestedNameSpecifierLoc, 4> Qualifiers;
Chad Rosier1dcde962012-08-08 18:46:20 +00003219 for (NestedNameSpecifierLoc Qualifier = NNS; Qualifier;
Douglas Gregor14454802011-02-25 02:25:35 +00003220 Qualifier = Qualifier.getPrefix())
3221 Qualifiers.push_back(Qualifier);
3222
3223 CXXScopeSpec SS;
3224 while (!Qualifiers.empty()) {
3225 NestedNameSpecifierLoc Q = Qualifiers.pop_back_val();
3226 NestedNameSpecifier *QNNS = Q.getNestedNameSpecifier();
Chad Rosier1dcde962012-08-08 18:46:20 +00003227
Douglas Gregor14454802011-02-25 02:25:35 +00003228 switch (QNNS->getKind()) {
3229 case NestedNameSpecifier::Identifier:
Craig Topperc3ec1492014-05-26 06:22:03 +00003230 if (SemaRef.BuildCXXNestedNameSpecifier(/*Scope=*/nullptr,
Douglas Gregor14454802011-02-25 02:25:35 +00003231 *QNNS->getAsIdentifier(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003232 Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003233 Q.getLocalEndLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00003234 ObjectType, false, SS,
Douglas Gregor14454802011-02-25 02:25:35 +00003235 FirstQualifierInScope, false))
3236 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003237
Douglas Gregor14454802011-02-25 02:25:35 +00003238 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003239
Douglas Gregor14454802011-02-25 02:25:35 +00003240 case NestedNameSpecifier::Namespace: {
3241 NamespaceDecl *NS
3242 = cast_or_null<NamespaceDecl>(
3243 getDerived().TransformDecl(
3244 Q.getLocalBeginLoc(),
3245 QNNS->getAsNamespace()));
3246 SS.Extend(SemaRef.Context, NS, Q.getLocalBeginLoc(), Q.getLocalEndLoc());
3247 break;
3248 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003249
Douglas Gregor14454802011-02-25 02:25:35 +00003250 case NestedNameSpecifier::NamespaceAlias: {
3251 NamespaceAliasDecl *Alias
3252 = cast_or_null<NamespaceAliasDecl>(
3253 getDerived().TransformDecl(Q.getLocalBeginLoc(),
3254 QNNS->getAsNamespaceAlias()));
Chad Rosier1dcde962012-08-08 18:46:20 +00003255 SS.Extend(SemaRef.Context, Alias, Q.getLocalBeginLoc(),
Douglas Gregor14454802011-02-25 02:25:35 +00003256 Q.getLocalEndLoc());
3257 break;
3258 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003259
Douglas Gregor14454802011-02-25 02:25:35 +00003260 case NestedNameSpecifier::Global:
3261 // There is no meaningful transformation that one could perform on the
3262 // global scope.
3263 SS.MakeGlobal(SemaRef.Context, Q.getBeginLoc());
3264 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00003265
Nikola Smiljanic67860242014-09-26 00:28:20 +00003266 case NestedNameSpecifier::Super: {
3267 CXXRecordDecl *RD =
3268 cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
3269 SourceLocation(), QNNS->getAsRecordDecl()));
3270 SS.MakeSuper(SemaRef.Context, RD, Q.getBeginLoc(), Q.getEndLoc());
3271 break;
3272 }
3273
Douglas Gregor14454802011-02-25 02:25:35 +00003274 case NestedNameSpecifier::TypeSpecWithTemplate:
3275 case NestedNameSpecifier::TypeSpec: {
3276 TypeLoc TL = TransformTypeInObjectScope(Q.getTypeLoc(), ObjectType,
3277 FirstQualifierInScope, SS);
Chad Rosier1dcde962012-08-08 18:46:20 +00003278
Douglas Gregor14454802011-02-25 02:25:35 +00003279 if (!TL)
3280 return NestedNameSpecifierLoc();
Chad Rosier1dcde962012-08-08 18:46:20 +00003281
Douglas Gregor14454802011-02-25 02:25:35 +00003282 if (TL.getType()->isDependentType() || TL.getType()->isRecordType() ||
Richard Smith2bf7fdb2013-01-02 11:42:31 +00003283 (SemaRef.getLangOpts().CPlusPlus11 &&
Douglas Gregor14454802011-02-25 02:25:35 +00003284 TL.getType()->isEnumeralType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003285 assert(!TL.getType().hasLocalQualifiers() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003286 "Can't get cv-qualifiers here");
Richard Smith91c7bbd2011-10-20 03:28:47 +00003287 if (TL.getType()->isEnumeralType())
3288 SemaRef.Diag(TL.getBeginLoc(),
3289 diag::warn_cxx98_compat_enum_nested_name_spec);
Douglas Gregor14454802011-02-25 02:25:35 +00003290 SS.Extend(SemaRef.Context, /*FIXME:*/SourceLocation(), TL,
3291 Q.getLocalEndLoc());
3292 break;
3293 }
Richard Trieude756fb2011-05-07 01:36:37 +00003294 // If the nested-name-specifier is an invalid type def, don't emit an
3295 // error because a previous error should have already been emitted.
David Blaikie6adc78e2013-02-18 22:06:02 +00003296 TypedefTypeLoc TTL = TL.getAs<TypedefTypeLoc>();
3297 if (!TTL || !TTL.getTypedefNameDecl()->isInvalidDecl()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003298 SemaRef.Diag(TL.getBeginLoc(), diag::err_nested_name_spec_non_tag)
Richard Trieude756fb2011-05-07 01:36:37 +00003299 << TL.getType() << SS.getRange();
3300 }
Douglas Gregor14454802011-02-25 02:25:35 +00003301 return NestedNameSpecifierLoc();
3302 }
Douglas Gregore16af532011-02-28 18:50:33 +00003303 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003304
Douglas Gregore16af532011-02-28 18:50:33 +00003305 // The qualifier-in-scope and object type only apply to the leftmost entity.
Craig Topperc3ec1492014-05-26 06:22:03 +00003306 FirstQualifierInScope = nullptr;
Douglas Gregore16af532011-02-28 18:50:33 +00003307 ObjectType = QualType();
Douglas Gregor14454802011-02-25 02:25:35 +00003308 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003309
Douglas Gregor14454802011-02-25 02:25:35 +00003310 // Don't rebuild the nested-name-specifier if we don't have to.
Chad Rosier1dcde962012-08-08 18:46:20 +00003311 if (SS.getScopeRep() == NNS.getNestedNameSpecifier() &&
Douglas Gregor14454802011-02-25 02:25:35 +00003312 !getDerived().AlwaysRebuild())
3313 return NNS;
Chad Rosier1dcde962012-08-08 18:46:20 +00003314
3315 // If we can re-use the source-location data from the original
Douglas Gregor14454802011-02-25 02:25:35 +00003316 // nested-name-specifier, do so.
3317 if (SS.location_size() == NNS.getDataLength() &&
3318 memcmp(SS.location_data(), NNS.getOpaqueData(), SS.location_size()) == 0)
3319 return NestedNameSpecifierLoc(SS.getScopeRep(), NNS.getOpaqueData());
3320
3321 // Allocate new nested-name-specifier location information.
3322 return SS.getWithLocInContext(SemaRef.Context);
3323}
3324
3325template<typename Derived>
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003326DeclarationNameInfo
3327TreeTransform<Derived>
John McCall31f82722010-11-12 08:19:04 +00003328::TransformDeclarationNameInfo(const DeclarationNameInfo &NameInfo) {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003329 DeclarationName Name = NameInfo.getName();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003330 if (!Name)
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003331 return DeclarationNameInfo();
Douglas Gregorf816bd72009-09-03 22:13:48 +00003332
3333 switch (Name.getNameKind()) {
3334 case DeclarationName::Identifier:
3335 case DeclarationName::ObjCZeroArgSelector:
3336 case DeclarationName::ObjCOneArgSelector:
3337 case DeclarationName::ObjCMultiArgSelector:
3338 case DeclarationName::CXXOperatorName:
Alexis Hunt3d221f22009-11-29 07:34:05 +00003339 case DeclarationName::CXXLiteralOperatorName:
Douglas Gregorf816bd72009-09-03 22:13:48 +00003340 case DeclarationName::CXXUsingDirective:
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003341 return NameInfo;
Mike Stump11289f42009-09-09 15:08:12 +00003342
Douglas Gregorf816bd72009-09-03 22:13:48 +00003343 case DeclarationName::CXXConstructorName:
3344 case DeclarationName::CXXDestructorName:
3345 case DeclarationName::CXXConversionFunctionName: {
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003346 TypeSourceInfo *NewTInfo;
3347 CanQualType NewCanTy;
3348 if (TypeSourceInfo *OldTInfo = NameInfo.getNamedTypeInfo()) {
John McCall31f82722010-11-12 08:19:04 +00003349 NewTInfo = getDerived().TransformType(OldTInfo);
3350 if (!NewTInfo)
3351 return DeclarationNameInfo();
3352 NewCanTy = SemaRef.Context.getCanonicalType(NewTInfo->getType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003353 }
3354 else {
Craig Topperc3ec1492014-05-26 06:22:03 +00003355 NewTInfo = nullptr;
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003356 TemporaryBase Rebase(*this, NameInfo.getLoc(), Name);
John McCall31f82722010-11-12 08:19:04 +00003357 QualType NewT = getDerived().TransformType(Name.getCXXNameType());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003358 if (NewT.isNull())
3359 return DeclarationNameInfo();
3360 NewCanTy = SemaRef.Context.getCanonicalType(NewT);
3361 }
Mike Stump11289f42009-09-09 15:08:12 +00003362
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00003363 DeclarationName NewName
3364 = SemaRef.Context.DeclarationNames.getCXXSpecialName(Name.getNameKind(),
3365 NewCanTy);
3366 DeclarationNameInfo NewNameInfo(NameInfo);
3367 NewNameInfo.setName(NewName);
3368 NewNameInfo.setNamedTypeInfo(NewTInfo);
3369 return NewNameInfo;
Douglas Gregorf816bd72009-09-03 22:13:48 +00003370 }
Mike Stump11289f42009-09-09 15:08:12 +00003371 }
3372
David Blaikie83d382b2011-09-23 05:06:16 +00003373 llvm_unreachable("Unknown name kind.");
Douglas Gregorf816bd72009-09-03 22:13:48 +00003374}
3375
3376template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00003377TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +00003378TreeTransform<Derived>::TransformTemplateName(CXXScopeSpec &SS,
3379 TemplateName Name,
3380 SourceLocation NameLoc,
3381 QualType ObjectType,
3382 NamedDecl *FirstQualifierInScope) {
3383 if (QualifiedTemplateName *QTN = Name.getAsQualifiedTemplateName()) {
3384 TemplateDecl *Template = QTN->getTemplateDecl();
3385 assert(Template && "qualified template name must refer to a template");
Chad Rosier1dcde962012-08-08 18:46:20 +00003386
Douglas Gregor9db53502011-03-02 18:07:45 +00003387 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003388 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003389 Template));
3390 if (!TransTemplate)
3391 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003392
Douglas Gregor9db53502011-03-02 18:07:45 +00003393 if (!getDerived().AlwaysRebuild() &&
3394 SS.getScopeRep() == QTN->getQualifier() &&
3395 TransTemplate == Template)
3396 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003397
Douglas Gregor9db53502011-03-02 18:07:45 +00003398 return getDerived().RebuildTemplateName(SS, QTN->hasTemplateKeyword(),
3399 TransTemplate);
3400 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003401
Douglas Gregor9db53502011-03-02 18:07:45 +00003402 if (DependentTemplateName *DTN = Name.getAsDependentTemplateName()) {
3403 if (SS.getScopeRep()) {
3404 // These apply to the scope specifier, not the template.
3405 ObjectType = QualType();
Craig Topperc3ec1492014-05-26 06:22:03 +00003406 FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003407 }
3408
Douglas Gregor9db53502011-03-02 18:07:45 +00003409 if (!getDerived().AlwaysRebuild() &&
3410 SS.getScopeRep() == DTN->getQualifier() &&
3411 ObjectType.isNull())
3412 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003413
Douglas Gregor9db53502011-03-02 18:07:45 +00003414 if (DTN->isIdentifier()) {
3415 return getDerived().RebuildTemplateName(SS,
Chad Rosier1dcde962012-08-08 18:46:20 +00003416 *DTN->getIdentifier(),
Douglas Gregor9db53502011-03-02 18:07:45 +00003417 NameLoc,
3418 ObjectType,
3419 FirstQualifierInScope);
3420 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003421
Douglas Gregor9db53502011-03-02 18:07:45 +00003422 return getDerived().RebuildTemplateName(SS, DTN->getOperator(), NameLoc,
3423 ObjectType);
3424 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003425
Douglas Gregor9db53502011-03-02 18:07:45 +00003426 if (TemplateDecl *Template = Name.getAsTemplateDecl()) {
3427 TemplateDecl *TransTemplate
Chad Rosier1dcde962012-08-08 18:46:20 +00003428 = cast_or_null<TemplateDecl>(getDerived().TransformDecl(NameLoc,
Douglas Gregor9db53502011-03-02 18:07:45 +00003429 Template));
3430 if (!TransTemplate)
3431 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003432
Douglas Gregor9db53502011-03-02 18:07:45 +00003433 if (!getDerived().AlwaysRebuild() &&
3434 TransTemplate == Template)
3435 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003436
Douglas Gregor9db53502011-03-02 18:07:45 +00003437 return TemplateName(TransTemplate);
3438 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003439
Douglas Gregor9db53502011-03-02 18:07:45 +00003440 if (SubstTemplateTemplateParmPackStorage *SubstPack
3441 = Name.getAsSubstTemplateTemplateParmPack()) {
3442 TemplateTemplateParmDecl *TransParam
3443 = cast_or_null<TemplateTemplateParmDecl>(
3444 getDerived().TransformDecl(NameLoc, SubstPack->getParameterPack()));
3445 if (!TransParam)
3446 return TemplateName();
Chad Rosier1dcde962012-08-08 18:46:20 +00003447
Douglas Gregor9db53502011-03-02 18:07:45 +00003448 if (!getDerived().AlwaysRebuild() &&
3449 TransParam == SubstPack->getParameterPack())
3450 return Name;
Chad Rosier1dcde962012-08-08 18:46:20 +00003451
3452 return getDerived().RebuildTemplateName(TransParam,
Douglas Gregor9db53502011-03-02 18:07:45 +00003453 SubstPack->getArgumentPack());
3454 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003455
Douglas Gregor9db53502011-03-02 18:07:45 +00003456 // These should be getting filtered out before they reach the AST.
3457 llvm_unreachable("overloaded function decl survived to here");
Douglas Gregor9db53502011-03-02 18:07:45 +00003458}
3459
3460template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00003461void TreeTransform<Derived>::InventTemplateArgumentLoc(
3462 const TemplateArgument &Arg,
3463 TemplateArgumentLoc &Output) {
3464 SourceLocation Loc = getDerived().getBaseLocation();
3465 switch (Arg.getKind()) {
3466 case TemplateArgument::Null:
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003467 llvm_unreachable("null template argument in TreeTransform");
John McCall0ad16662009-10-29 08:12:44 +00003468 break;
3469
3470 case TemplateArgument::Type:
3471 Output = TemplateArgumentLoc(Arg,
John McCallbcd03502009-12-07 02:54:59 +00003472 SemaRef.Context.getTrivialTypeSourceInfo(Arg.getAsType(), Loc));
Chad Rosier1dcde962012-08-08 18:46:20 +00003473
John McCall0ad16662009-10-29 08:12:44 +00003474 break;
3475
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003476 case TemplateArgument::Template:
Douglas Gregor9d802122011-03-02 17:09:35 +00003477 case TemplateArgument::TemplateExpansion: {
3478 NestedNameSpecifierLocBuilder Builder;
3479 TemplateName Template = Arg.getAsTemplate();
3480 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName())
3481 Builder.MakeTrivial(SemaRef.Context, DTN->getQualifier(), Loc);
3482 else if (QualifiedTemplateName *QTN = Template.getAsQualifiedTemplateName())
3483 Builder.MakeTrivial(SemaRef.Context, QTN->getQualifier(), Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003484
Douglas Gregor9d802122011-03-02 17:09:35 +00003485 if (Arg.getKind() == TemplateArgument::Template)
Chad Rosier1dcde962012-08-08 18:46:20 +00003486 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003487 Builder.getWithLocInContext(SemaRef.Context),
3488 Loc);
3489 else
Chad Rosier1dcde962012-08-08 18:46:20 +00003490 Output = TemplateArgumentLoc(Arg,
Douglas Gregor9d802122011-03-02 17:09:35 +00003491 Builder.getWithLocInContext(SemaRef.Context),
3492 Loc, Loc);
Chad Rosier1dcde962012-08-08 18:46:20 +00003493
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003494 break;
Douglas Gregor9d802122011-03-02 17:09:35 +00003495 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003496
John McCall0ad16662009-10-29 08:12:44 +00003497 case TemplateArgument::Expression:
3498 Output = TemplateArgumentLoc(Arg, Arg.getAsExpr());
3499 break;
3500
3501 case TemplateArgument::Declaration:
3502 case TemplateArgument::Integral:
3503 case TemplateArgument::Pack:
Eli Friedmanb826a002012-09-26 02:36:12 +00003504 case TemplateArgument::NullPtr:
John McCall0d07eb32009-10-29 18:45:58 +00003505 Output = TemplateArgumentLoc(Arg, TemplateArgumentLocInfo());
John McCall0ad16662009-10-29 08:12:44 +00003506 break;
3507 }
3508}
3509
3510template<typename Derived>
3511bool TreeTransform<Derived>::TransformTemplateArgument(
3512 const TemplateArgumentLoc &Input,
Richard Smithd784e682015-09-23 21:41:42 +00003513 TemplateArgumentLoc &Output, bool Uneval) {
John McCall0ad16662009-10-29 08:12:44 +00003514 const TemplateArgument &Arg = Input.getArgument();
Douglas Gregore922c772009-08-04 22:27:00 +00003515 switch (Arg.getKind()) {
3516 case TemplateArgument::Null:
3517 case TemplateArgument::Integral:
Eli Friedmancda3db82012-09-25 01:02:42 +00003518 case TemplateArgument::Pack:
3519 case TemplateArgument::Declaration:
Eli Friedmanb826a002012-09-26 02:36:12 +00003520 case TemplateArgument::NullPtr:
3521 llvm_unreachable("Unexpected TemplateArgument");
Mike Stump11289f42009-09-09 15:08:12 +00003522
Douglas Gregore922c772009-08-04 22:27:00 +00003523 case TemplateArgument::Type: {
John McCallbcd03502009-12-07 02:54:59 +00003524 TypeSourceInfo *DI = Input.getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00003525 if (!DI)
John McCallbcd03502009-12-07 02:54:59 +00003526 DI = InventTypeSourceInfo(Input.getArgument().getAsType());
John McCall0ad16662009-10-29 08:12:44 +00003527
3528 DI = getDerived().TransformType(DI);
3529 if (!DI) return true;
3530
3531 Output = TemplateArgumentLoc(TemplateArgument(DI->getType()), DI);
3532 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003533 }
Mike Stump11289f42009-09-09 15:08:12 +00003534
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003535 case TemplateArgument::Template: {
Douglas Gregor9d802122011-03-02 17:09:35 +00003536 NestedNameSpecifierLoc QualifierLoc = Input.getTemplateQualifierLoc();
3537 if (QualifierLoc) {
3538 QualifierLoc = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc);
3539 if (!QualifierLoc)
3540 return true;
3541 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003542
Douglas Gregordf846d12011-03-02 18:46:51 +00003543 CXXScopeSpec SS;
3544 SS.Adopt(QualifierLoc);
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003545 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00003546 = getDerived().TransformTemplateName(SS, Arg.getAsTemplate(),
3547 Input.getTemplateNameLoc());
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003548 if (Template.isNull())
3549 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003550
Douglas Gregor9d802122011-03-02 17:09:35 +00003551 Output = TemplateArgumentLoc(TemplateArgument(Template), QualifierLoc,
Douglas Gregor9167f8b2009-11-11 01:00:40 +00003552 Input.getTemplateNameLoc());
3553 return false;
3554 }
Douglas Gregore4ff4b52011-01-05 18:58:31 +00003555
3556 case TemplateArgument::TemplateExpansion:
3557 llvm_unreachable("Caller should expand pack expansions");
3558
Douglas Gregore922c772009-08-04 22:27:00 +00003559 case TemplateArgument::Expression: {
Richard Smith764d2fe2011-12-20 02:08:33 +00003560 // Template argument expressions are constant expressions.
Richard Smithd784e682015-09-23 21:41:42 +00003561 EnterExpressionEvaluationContext Unevaluated(
3562 getSema(), Uneval ? Sema::Unevaluated : Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00003563
John McCall0ad16662009-10-29 08:12:44 +00003564 Expr *InputExpr = Input.getSourceExpression();
3565 if (!InputExpr) InputExpr = Input.getArgument().getAsExpr();
3566
Chris Lattnercdb591a2011-04-25 20:37:58 +00003567 ExprResult E = getDerived().TransformExpr(InputExpr);
Eli Friedmanc6237c62012-02-29 03:16:56 +00003568 E = SemaRef.ActOnConstantExpression(E);
John McCall0ad16662009-10-29 08:12:44 +00003569 if (E.isInvalid()) return true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00003570 Output = TemplateArgumentLoc(TemplateArgument(E.get()), E.get());
John McCall0ad16662009-10-29 08:12:44 +00003571 return false;
Douglas Gregore922c772009-08-04 22:27:00 +00003572 }
Douglas Gregore922c772009-08-04 22:27:00 +00003573 }
Mike Stump11289f42009-09-09 15:08:12 +00003574
Douglas Gregore922c772009-08-04 22:27:00 +00003575 // Work around bogus GCC warning
John McCall0ad16662009-10-29 08:12:44 +00003576 return true;
Douglas Gregore922c772009-08-04 22:27:00 +00003577}
3578
Douglas Gregorfe921a72010-12-20 23:36:19 +00003579/// \brief Iterator adaptor that invents template argument location information
3580/// for each of the template arguments in its underlying iterator.
3581template<typename Derived, typename InputIterator>
3582class TemplateArgumentLocInventIterator {
3583 TreeTransform<Derived> &Self;
3584 InputIterator Iter;
Chad Rosier1dcde962012-08-08 18:46:20 +00003585
Douglas Gregorfe921a72010-12-20 23:36:19 +00003586public:
3587 typedef TemplateArgumentLoc value_type;
3588 typedef TemplateArgumentLoc reference;
3589 typedef typename std::iterator_traits<InputIterator>::difference_type
3590 difference_type;
3591 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00003592
Douglas Gregorfe921a72010-12-20 23:36:19 +00003593 class pointer {
3594 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00003595
Douglas Gregorfe921a72010-12-20 23:36:19 +00003596 public:
3597 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003598
Douglas Gregorfe921a72010-12-20 23:36:19 +00003599 const TemplateArgumentLoc *operator->() const { return &Arg; }
3600 };
Chad Rosier1dcde962012-08-08 18:46:20 +00003601
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00003602 TemplateArgumentLocInventIterator() { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003603
Douglas Gregorfe921a72010-12-20 23:36:19 +00003604 explicit TemplateArgumentLocInventIterator(TreeTransform<Derived> &Self,
3605 InputIterator Iter)
3606 : Self(Self), Iter(Iter) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00003607
Douglas Gregorfe921a72010-12-20 23:36:19 +00003608 TemplateArgumentLocInventIterator &operator++() {
3609 ++Iter;
3610 return *this;
Douglas Gregor62e06f22010-12-20 17:31:10 +00003611 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003612
Douglas Gregorfe921a72010-12-20 23:36:19 +00003613 TemplateArgumentLocInventIterator operator++(int) {
3614 TemplateArgumentLocInventIterator Old(*this);
3615 ++(*this);
3616 return Old;
3617 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003618
Douglas Gregorfe921a72010-12-20 23:36:19 +00003619 reference operator*() const {
3620 TemplateArgumentLoc Result;
3621 Self.InventTemplateArgumentLoc(*Iter, Result);
3622 return Result;
3623 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003624
Douglas Gregorfe921a72010-12-20 23:36:19 +00003625 pointer operator->() const { return pointer(**this); }
Chad Rosier1dcde962012-08-08 18:46:20 +00003626
Douglas Gregorfe921a72010-12-20 23:36:19 +00003627 friend bool operator==(const TemplateArgumentLocInventIterator &X,
3628 const TemplateArgumentLocInventIterator &Y) {
3629 return X.Iter == Y.Iter;
3630 }
Douglas Gregor62e06f22010-12-20 17:31:10 +00003631
Douglas Gregorfe921a72010-12-20 23:36:19 +00003632 friend bool operator!=(const TemplateArgumentLocInventIterator &X,
3633 const TemplateArgumentLocInventIterator &Y) {
3634 return X.Iter != Y.Iter;
3635 }
3636};
Chad Rosier1dcde962012-08-08 18:46:20 +00003637
Douglas Gregor42cafa82010-12-20 17:42:22 +00003638template<typename Derived>
Douglas Gregorfe921a72010-12-20 23:36:19 +00003639template<typename InputIterator>
Richard Smithd784e682015-09-23 21:41:42 +00003640bool TreeTransform<Derived>::TransformTemplateArguments(
3641 InputIterator First, InputIterator Last, TemplateArgumentListInfo &Outputs,
3642 bool Uneval) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00003643 for (; First != Last; ++First) {
Douglas Gregor42cafa82010-12-20 17:42:22 +00003644 TemplateArgumentLoc Out;
Douglas Gregorfe921a72010-12-20 23:36:19 +00003645 TemplateArgumentLoc In = *First;
Chad Rosier1dcde962012-08-08 18:46:20 +00003646
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003647 if (In.getArgument().getKind() == TemplateArgument::Pack) {
3648 // Unpack argument packs, which we translate them into separate
3649 // arguments.
Douglas Gregorfe921a72010-12-20 23:36:19 +00003650 // FIXME: We could do much better if we could guarantee that the
3651 // TemplateArgumentLocInfo for the pack expansion would be usable for
3652 // all of the template arguments in the argument pack.
Chad Rosier1dcde962012-08-08 18:46:20 +00003653 typedef TemplateArgumentLocInventIterator<Derived,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003654 TemplateArgument::pack_iterator>
3655 PackLocIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00003656 if (TransformTemplateArguments(PackLocIterator(*this,
Douglas Gregorfe921a72010-12-20 23:36:19 +00003657 In.getArgument().pack_begin()),
3658 PackLocIterator(*this,
3659 In.getArgument().pack_end()),
Richard Smithd784e682015-09-23 21:41:42 +00003660 Outputs, Uneval))
Douglas Gregorfe921a72010-12-20 23:36:19 +00003661 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003662
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003663 continue;
3664 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003665
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003666 if (In.getArgument().isPackExpansion()) {
3667 // We have a pack expansion, for which we will be substituting into
3668 // the pattern.
3669 SourceLocation Ellipsis;
David Blaikie05785d12013-02-20 22:23:23 +00003670 Optional<unsigned> OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003671 TemplateArgumentLoc Pattern
Eli Friedman94e9eaa2013-06-20 04:11:21 +00003672 = getSema().getTemplateArgumentPackExpansionPattern(
3673 In, Ellipsis, OrigNumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00003674
Chris Lattner01cf8db2011-07-20 06:58:45 +00003675 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003676 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
3677 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
Chad Rosier1dcde962012-08-08 18:46:20 +00003678
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003679 // Determine whether the set of unexpanded parameter packs can and should
3680 // be expanded.
3681 bool Expand = true;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003682 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00003683 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003684 if (getDerived().TryExpandParameterPacks(Ellipsis,
3685 Pattern.getSourceRange(),
David Blaikieb9c168a2011-09-22 02:34:54 +00003686 Unexpanded,
Chad Rosier1dcde962012-08-08 18:46:20 +00003687 Expand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00003688 RetainExpansion,
3689 NumExpansions))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003690 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003691
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003692 if (!Expand) {
3693 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00003694 // transformation on the pack expansion, producing another pack
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003695 // expansion.
3696 TemplateArgumentLoc OutPattern;
3697 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Richard Smithd784e682015-09-23 21:41:42 +00003698 if (getDerived().TransformTemplateArgument(Pattern, OutPattern, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003699 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003700
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003701 Out = getDerived().RebuildPackExpansion(OutPattern, Ellipsis,
3702 NumExpansions);
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003703 if (Out.getArgument().isNull())
3704 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003705
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003706 Outputs.addArgument(Out);
3707 continue;
3708 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003709
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003710 // The transform has determined that we should perform an elementwise
3711 // expansion of the pattern. Do so.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003712 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003713 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
3714
Richard Smithd784e682015-09-23 21:41:42 +00003715 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003716 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003717
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003718 if (Out.getArgument().containsUnexpandedParameterPack()) {
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003719 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3720 OrigNumExpansions);
Douglas Gregor2fcb8632011-01-11 22:21:24 +00003721 if (Out.getArgument().isNull())
3722 return true;
3723 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003724
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003725 Outputs.addArgument(Out);
3726 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003727
Douglas Gregor48d24112011-01-10 20:53:55 +00003728 // If we're supposed to retain a pack expansion, do so by temporarily
3729 // forgetting the partially-substituted parameter pack.
3730 if (RetainExpansion) {
3731 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00003732
Richard Smithd784e682015-09-23 21:41:42 +00003733 if (getDerived().TransformTemplateArgument(Pattern, Out, Uneval))
Douglas Gregor48d24112011-01-10 20:53:55 +00003734 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003735
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00003736 Out = getDerived().RebuildPackExpansion(Out, Ellipsis,
3737 OrigNumExpansions);
Douglas Gregor48d24112011-01-10 20:53:55 +00003738 if (Out.getArgument().isNull())
3739 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003740
Douglas Gregor48d24112011-01-10 20:53:55 +00003741 Outputs.addArgument(Out);
3742 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003743
Douglas Gregor840bd6c2010-12-20 22:05:00 +00003744 continue;
3745 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003746
3747 // The simple case:
Richard Smithd784e682015-09-23 21:41:42 +00003748 if (getDerived().TransformTemplateArgument(In, Out, Uneval))
Douglas Gregor42cafa82010-12-20 17:42:22 +00003749 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00003750
Douglas Gregor42cafa82010-12-20 17:42:22 +00003751 Outputs.addArgument(Out);
3752 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003753
Douglas Gregor42cafa82010-12-20 17:42:22 +00003754 return false;
3755
3756}
3757
Douglas Gregord6ff3322009-08-04 16:50:30 +00003758//===----------------------------------------------------------------------===//
3759// Type transformation
3760//===----------------------------------------------------------------------===//
3761
3762template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003763QualType TreeTransform<Derived>::TransformType(QualType T) {
Douglas Gregord6ff3322009-08-04 16:50:30 +00003764 if (getDerived().AlreadyTransformed(T))
3765 return T;
Mike Stump11289f42009-09-09 15:08:12 +00003766
John McCall550e0c22009-10-21 00:40:46 +00003767 // Temporary workaround. All of these transformations should
3768 // eventually turn into transformations on TypeLocs.
Douglas Gregor2d525f02011-01-25 19:13:18 +00003769 TypeSourceInfo *DI = getSema().Context.getTrivialTypeSourceInfo(T,
3770 getDerived().getBaseLocation());
Chad Rosier1dcde962012-08-08 18:46:20 +00003771
John McCall31f82722010-11-12 08:19:04 +00003772 TypeSourceInfo *NewDI = getDerived().TransformType(DI);
John McCall8ccfcb52009-09-24 19:53:00 +00003773
John McCall550e0c22009-10-21 00:40:46 +00003774 if (!NewDI)
3775 return QualType();
3776
3777 return NewDI->getType();
3778}
3779
3780template<typename Derived>
John McCall31f82722010-11-12 08:19:04 +00003781TypeSourceInfo *TreeTransform<Derived>::TransformType(TypeSourceInfo *DI) {
Richard Smith764d2fe2011-12-20 02:08:33 +00003782 // Refine the base location to the type's location.
3783 TemporaryBase Rebase(*this, DI->getTypeLoc().getBeginLoc(),
3784 getDerived().getBaseEntity());
John McCall550e0c22009-10-21 00:40:46 +00003785 if (getDerived().AlreadyTransformed(DI->getType()))
3786 return DI;
3787
3788 TypeLocBuilder TLB;
3789
3790 TypeLoc TL = DI->getTypeLoc();
3791 TLB.reserve(TL.getFullDataSize());
3792
John McCall31f82722010-11-12 08:19:04 +00003793 QualType Result = getDerived().TransformType(TLB, TL);
John McCall550e0c22009-10-21 00:40:46 +00003794 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003795 return nullptr;
John McCall550e0c22009-10-21 00:40:46 +00003796
John McCallbcd03502009-12-07 02:54:59 +00003797 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
John McCall550e0c22009-10-21 00:40:46 +00003798}
3799
3800template<typename Derived>
3801QualType
John McCall31f82722010-11-12 08:19:04 +00003802TreeTransform<Derived>::TransformType(TypeLocBuilder &TLB, TypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003803 switch (T.getTypeLocClass()) {
3804#define ABSTRACT_TYPELOC(CLASS, PARENT)
David Blaikie6adc78e2013-02-18 22:06:02 +00003805#define TYPELOC(CLASS, PARENT) \
3806 case TypeLoc::CLASS: \
3807 return getDerived().Transform##CLASS##Type(TLB, \
3808 T.castAs<CLASS##TypeLoc>());
John McCall550e0c22009-10-21 00:40:46 +00003809#include "clang/AST/TypeLocNodes.def"
Douglas Gregord6ff3322009-08-04 16:50:30 +00003810 }
Mike Stump11289f42009-09-09 15:08:12 +00003811
Jeffrey Yasskin1615d452009-12-12 05:05:38 +00003812 llvm_unreachable("unhandled type loc!");
John McCall550e0c22009-10-21 00:40:46 +00003813}
3814
3815/// FIXME: By default, this routine adds type qualifiers only to types
3816/// that can have qualifiers, and silently suppresses those qualifiers
3817/// that are not permitted (e.g., qualifiers on reference or function
3818/// types). This is the right thing for template instantiation, but
3819/// probably not for other clients.
3820template<typename Derived>
3821QualType
3822TreeTransform<Derived>::TransformQualifiedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003823 QualifiedTypeLoc T) {
Douglas Gregor1b8fe5b72009-11-16 21:35:15 +00003824 Qualifiers Quals = T.getType().getLocalQualifiers();
John McCall550e0c22009-10-21 00:40:46 +00003825
John McCall31f82722010-11-12 08:19:04 +00003826 QualType Result = getDerived().TransformType(TLB, T.getUnqualifiedLoc());
John McCall550e0c22009-10-21 00:40:46 +00003827 if (Result.isNull())
3828 return QualType();
3829
3830 // Silently suppress qualifiers if the result type can't be qualified.
3831 // FIXME: this is the right thing for template instantiation, but
3832 // probably not for other clients.
3833 if (Result->isFunctionType() || Result->isReferenceType())
Douglas Gregord6ff3322009-08-04 16:50:30 +00003834 return Result;
Mike Stump11289f42009-09-09 15:08:12 +00003835
John McCall31168b02011-06-15 23:02:42 +00003836 // Suppress Objective-C lifetime qualifiers if they don't make sense for the
Douglas Gregore46db902011-06-17 22:11:49 +00003837 // resulting type.
3838 if (Quals.hasObjCLifetime()) {
3839 if (!Result->isObjCLifetimeType() && !Result->isDependentType())
3840 Quals.removeObjCLifetime();
Douglas Gregord7357a92011-06-17 23:16:24 +00003841 else if (Result.getObjCLifetime()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00003842 // Objective-C ARC:
Douglas Gregore46db902011-06-17 22:11:49 +00003843 // A lifetime qualifier applied to a substituted template parameter
3844 // overrides the lifetime qualifier from the template argument.
Douglas Gregorf4e43312013-01-17 23:59:28 +00003845 const AutoType *AutoTy;
Chad Rosier1dcde962012-08-08 18:46:20 +00003846 if (const SubstTemplateTypeParmType *SubstTypeParam
Douglas Gregore46db902011-06-17 22:11:49 +00003847 = dyn_cast<SubstTemplateTypeParmType>(Result)) {
3848 QualType Replacement = SubstTypeParam->getReplacementType();
3849 Qualifiers Qs = Replacement.getQualifiers();
3850 Qs.removeObjCLifetime();
Chad Rosier1dcde962012-08-08 18:46:20 +00003851 Replacement
Douglas Gregore46db902011-06-17 22:11:49 +00003852 = SemaRef.Context.getQualifiedType(Replacement.getUnqualifiedType(),
3853 Qs);
3854 Result = SemaRef.Context.getSubstTemplateTypeParmType(
Chad Rosier1dcde962012-08-08 18:46:20 +00003855 SubstTypeParam->getReplacedParameter(),
Douglas Gregore46db902011-06-17 22:11:49 +00003856 Replacement);
3857 TLB.TypeWasModifiedSafely(Result);
Douglas Gregorf4e43312013-01-17 23:59:28 +00003858 } else if ((AutoTy = dyn_cast<AutoType>(Result)) && AutoTy->isDeduced()) {
3859 // 'auto' types behave the same way as template parameters.
3860 QualType Deduced = AutoTy->getDeducedType();
3861 Qualifiers Qs = Deduced.getQualifiers();
3862 Qs.removeObjCLifetime();
3863 Deduced = SemaRef.Context.getQualifiedType(Deduced.getUnqualifiedType(),
3864 Qs);
Faisal Vali2b391ab2013-09-26 19:54:12 +00003865 Result = SemaRef.Context.getAutoType(Deduced, AutoTy->isDecltypeAuto(),
3866 AutoTy->isDependentType());
Douglas Gregorf4e43312013-01-17 23:59:28 +00003867 TLB.TypeWasModifiedSafely(Result);
Douglas Gregore46db902011-06-17 22:11:49 +00003868 } else {
Douglas Gregord7357a92011-06-17 23:16:24 +00003869 // Otherwise, complain about the addition of a qualifier to an
3870 // already-qualified type.
Eli Friedman7152fbe2013-06-07 20:31:48 +00003871 SourceRange R = T.getUnqualifiedLoc().getSourceRange();
Argyrios Kyrtzidiscff00d92011-06-24 00:08:59 +00003872 SemaRef.Diag(R.getBegin(), diag::err_attr_objc_ownership_redundant)
Douglas Gregord7357a92011-06-17 23:16:24 +00003873 << Result << R;
Chad Rosier1dcde962012-08-08 18:46:20 +00003874
Douglas Gregore46db902011-06-17 22:11:49 +00003875 Quals.removeObjCLifetime();
3876 }
3877 }
3878 }
John McCallcb0f89a2010-06-05 06:41:15 +00003879 if (!Quals.empty()) {
3880 Result = SemaRef.BuildQualifiedType(Result, T.getBeginLoc(), Quals);
Richard Smithdeec0742013-03-27 23:36:39 +00003881 // BuildQualifiedType might not add qualifiers if they are invalid.
3882 if (Result.hasLocalQualifiers())
3883 TLB.push<QualifiedTypeLoc>(Result);
John McCallcb0f89a2010-06-05 06:41:15 +00003884 // No location information to preserve.
3885 }
John McCall550e0c22009-10-21 00:40:46 +00003886
3887 return Result;
3888}
3889
Douglas Gregor14454802011-02-25 02:25:35 +00003890template<typename Derived>
3891TypeLoc
3892TreeTransform<Derived>::TransformTypeInObjectScope(TypeLoc TL,
3893 QualType ObjectType,
3894 NamedDecl *UnqualLookup,
3895 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003896 if (getDerived().AlreadyTransformed(TL.getType()))
Douglas Gregor14454802011-02-25 02:25:35 +00003897 return TL;
Chad Rosier1dcde962012-08-08 18:46:20 +00003898
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003899 TypeSourceInfo *TSI =
3900 TransformTSIInObjectScope(TL, ObjectType, UnqualLookup, SS);
3901 if (TSI)
3902 return TSI->getTypeLoc();
3903 return TypeLoc();
Douglas Gregor14454802011-02-25 02:25:35 +00003904}
3905
Douglas Gregor579c15f2011-03-02 18:32:08 +00003906template<typename Derived>
3907TypeSourceInfo *
3908TreeTransform<Derived>::TransformTypeInObjectScope(TypeSourceInfo *TSInfo,
3909 QualType ObjectType,
3910 NamedDecl *UnqualLookup,
3911 CXXScopeSpec &SS) {
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003912 if (getDerived().AlreadyTransformed(TSInfo->getType()))
Douglas Gregor579c15f2011-03-02 18:32:08 +00003913 return TSInfo;
Chad Rosier1dcde962012-08-08 18:46:20 +00003914
Reid Klecknerfeb8ac92013-12-04 22:51:51 +00003915 return TransformTSIInObjectScope(TSInfo->getTypeLoc(), ObjectType,
3916 UnqualLookup, SS);
3917}
3918
3919template <typename Derived>
3920TypeSourceInfo *TreeTransform<Derived>::TransformTSIInObjectScope(
3921 TypeLoc TL, QualType ObjectType, NamedDecl *UnqualLookup,
3922 CXXScopeSpec &SS) {
3923 QualType T = TL.getType();
3924 assert(!getDerived().AlreadyTransformed(T));
3925
Douglas Gregor579c15f2011-03-02 18:32:08 +00003926 TypeLocBuilder TLB;
3927 QualType Result;
Chad Rosier1dcde962012-08-08 18:46:20 +00003928
Douglas Gregor579c15f2011-03-02 18:32:08 +00003929 if (isa<TemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003930 TemplateSpecializationTypeLoc SpecTL =
3931 TL.castAs<TemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003932
Douglas Gregor579c15f2011-03-02 18:32:08 +00003933 TemplateName Template
3934 = getDerived().TransformTemplateName(SS,
3935 SpecTL.getTypePtr()->getTemplateName(),
3936 SpecTL.getTemplateNameLoc(),
3937 ObjectType, UnqualLookup);
Chad Rosier1dcde962012-08-08 18:46:20 +00003938 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003939 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003940
3941 Result = getDerived().TransformTemplateSpecializationType(TLB, SpecTL,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003942 Template);
3943 } else if (isa<DependentTemplateSpecializationType>(T)) {
David Blaikie6adc78e2013-02-18 22:06:02 +00003944 DependentTemplateSpecializationTypeLoc SpecTL =
3945 TL.castAs<DependentTemplateSpecializationTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00003946
Douglas Gregor579c15f2011-03-02 18:32:08 +00003947 TemplateName Template
Chad Rosier1dcde962012-08-08 18:46:20 +00003948 = getDerived().RebuildTemplateName(SS,
3949 *SpecTL.getTypePtr()->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00003950 SpecTL.getTemplateNameLoc(),
Douglas Gregor579c15f2011-03-02 18:32:08 +00003951 ObjectType, UnqualLookup);
3952 if (Template.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003953 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003954
3955 Result = getDerived().TransformDependentTemplateSpecializationType(TLB,
Douglas Gregor579c15f2011-03-02 18:32:08 +00003956 SpecTL,
Douglas Gregor23648d72011-03-04 18:53:13 +00003957 Template,
3958 SS);
Douglas Gregor579c15f2011-03-02 18:32:08 +00003959 } else {
3960 // Nothing special needs to be done for these.
3961 Result = getDerived().TransformType(TLB, TL);
3962 }
Chad Rosier1dcde962012-08-08 18:46:20 +00003963
3964 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00003965 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00003966
Douglas Gregor579c15f2011-03-02 18:32:08 +00003967 return TLB.getTypeSourceInfo(SemaRef.Context, Result);
3968}
3969
John McCall550e0c22009-10-21 00:40:46 +00003970template <class TyLoc> static inline
3971QualType TransformTypeSpecType(TypeLocBuilder &TLB, TyLoc T) {
3972 TyLoc NewT = TLB.push<TyLoc>(T.getType());
3973 NewT.setNameLoc(T.getNameLoc());
3974 return T.getType();
3975}
3976
John McCall550e0c22009-10-21 00:40:46 +00003977template<typename Derived>
3978QualType TreeTransform<Derived>::TransformBuiltinType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003979 BuiltinTypeLoc T) {
Douglas Gregorc9b7a592010-01-18 18:04:31 +00003980 BuiltinTypeLoc NewT = TLB.push<BuiltinTypeLoc>(T.getType());
3981 NewT.setBuiltinLoc(T.getBuiltinLoc());
3982 if (T.needsExtraLocalData())
3983 NewT.getWrittenBuiltinSpecs() = T.getWrittenBuiltinSpecs();
3984 return T.getType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00003985}
Mike Stump11289f42009-09-09 15:08:12 +00003986
Douglas Gregord6ff3322009-08-04 16:50:30 +00003987template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00003988QualType TreeTransform<Derived>::TransformComplexType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00003989 ComplexTypeLoc T) {
John McCall550e0c22009-10-21 00:40:46 +00003990 // FIXME: recurse?
3991 return TransformTypeSpecType(TLB, T);
Douglas Gregord6ff3322009-08-04 16:50:30 +00003992}
Mike Stump11289f42009-09-09 15:08:12 +00003993
Reid Kleckner0503a872013-12-05 01:23:43 +00003994template <typename Derived>
3995QualType TreeTransform<Derived>::TransformAdjustedType(TypeLocBuilder &TLB,
3996 AdjustedTypeLoc TL) {
3997 // Adjustments applied during transformation are handled elsewhere.
3998 return getDerived().TransformType(TLB, TL.getOriginalLoc());
3999}
4000
Douglas Gregord6ff3322009-08-04 16:50:30 +00004001template<typename Derived>
Reid Kleckner8a365022013-06-24 17:51:48 +00004002QualType TreeTransform<Derived>::TransformDecayedType(TypeLocBuilder &TLB,
4003 DecayedTypeLoc TL) {
4004 QualType OriginalType = getDerived().TransformType(TLB, TL.getOriginalLoc());
4005 if (OriginalType.isNull())
4006 return QualType();
4007
4008 QualType Result = TL.getType();
4009 if (getDerived().AlwaysRebuild() ||
4010 OriginalType != TL.getOriginalLoc().getType())
4011 Result = SemaRef.Context.getDecayedType(OriginalType);
4012 TLB.push<DecayedTypeLoc>(Result);
4013 // Nothing to set for DecayedTypeLoc.
4014 return Result;
4015}
4016
4017template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004018QualType TreeTransform<Derived>::TransformPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004019 PointerTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004020 QualType PointeeType
4021 = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004022 if (PointeeType.isNull())
4023 return QualType();
4024
4025 QualType Result = TL.getType();
John McCall8b07ec22010-05-15 11:32:37 +00004026 if (PointeeType->getAs<ObjCObjectType>()) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004027 // A dependent pointer type 'T *' has is being transformed such
4028 // that an Objective-C class type is being replaced for 'T'. The
4029 // resulting pointer type is an ObjCObjectPointerType, not a
4030 // PointerType.
John McCall8b07ec22010-05-15 11:32:37 +00004031 Result = SemaRef.Context.getObjCObjectPointerType(PointeeType);
Chad Rosier1dcde962012-08-08 18:46:20 +00004032
John McCall8b07ec22010-05-15 11:32:37 +00004033 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
4034 NewT.setStarLoc(TL.getStarLoc());
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004035 return Result;
4036 }
John McCall31f82722010-11-12 08:19:04 +00004037
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004038 if (getDerived().AlwaysRebuild() ||
4039 PointeeType != TL.getPointeeLoc().getType()) {
4040 Result = getDerived().RebuildPointerType(PointeeType, TL.getSigilLoc());
4041 if (Result.isNull())
4042 return QualType();
4043 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004044
John McCall31168b02011-06-15 23:02:42 +00004045 // Objective-C ARC can add lifetime qualifiers to the type that we're
4046 // pointing to.
4047 TLB.TypeWasModifiedSafely(Result->getPointeeType());
Chad Rosier1dcde962012-08-08 18:46:20 +00004048
Douglas Gregorc298ffc2010-04-22 16:44:27 +00004049 PointerTypeLoc NewT = TLB.push<PointerTypeLoc>(Result);
4050 NewT.setSigilLoc(TL.getSigilLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00004051 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004052}
Mike Stump11289f42009-09-09 15:08:12 +00004053
4054template<typename Derived>
4055QualType
John McCall550e0c22009-10-21 00:40:46 +00004056TreeTransform<Derived>::TransformBlockPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004057 BlockPointerTypeLoc TL) {
Douglas Gregore1f79e82010-04-22 16:46:21 +00004058 QualType PointeeType
Chad Rosier1dcde962012-08-08 18:46:20 +00004059 = getDerived().TransformType(TLB, TL.getPointeeLoc());
4060 if (PointeeType.isNull())
4061 return QualType();
4062
4063 QualType Result = TL.getType();
4064 if (getDerived().AlwaysRebuild() ||
4065 PointeeType != TL.getPointeeLoc().getType()) {
4066 Result = getDerived().RebuildBlockPointerType(PointeeType,
Douglas Gregore1f79e82010-04-22 16:46:21 +00004067 TL.getSigilLoc());
4068 if (Result.isNull())
4069 return QualType();
4070 }
4071
Douglas Gregor049211a2010-04-22 16:50:51 +00004072 BlockPointerTypeLoc NewT = TLB.push<BlockPointerTypeLoc>(Result);
Douglas Gregore1f79e82010-04-22 16:46:21 +00004073 NewT.setSigilLoc(TL.getSigilLoc());
4074 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004075}
4076
John McCall70dd5f62009-10-30 00:06:24 +00004077/// Transforms a reference type. Note that somewhat paradoxically we
4078/// don't care whether the type itself is an l-value type or an r-value
4079/// type; we only care if the type was *written* as an l-value type
4080/// or an r-value type.
4081template<typename Derived>
4082QualType
4083TreeTransform<Derived>::TransformReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004084 ReferenceTypeLoc TL) {
John McCall70dd5f62009-10-30 00:06:24 +00004085 const ReferenceType *T = TL.getTypePtr();
4086
4087 // Note that this works with the pointee-as-written.
4088 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
4089 if (PointeeType.isNull())
4090 return QualType();
4091
4092 QualType Result = TL.getType();
4093 if (getDerived().AlwaysRebuild() ||
4094 PointeeType != T->getPointeeTypeAsWritten()) {
4095 Result = getDerived().RebuildReferenceType(PointeeType,
4096 T->isSpelledAsLValue(),
4097 TL.getSigilLoc());
4098 if (Result.isNull())
4099 return QualType();
4100 }
4101
John McCall31168b02011-06-15 23:02:42 +00004102 // Objective-C ARC can add lifetime qualifiers to the type that we're
4103 // referring to.
4104 TLB.TypeWasModifiedSafely(
4105 Result->getAs<ReferenceType>()->getPointeeTypeAsWritten());
4106
John McCall70dd5f62009-10-30 00:06:24 +00004107 // r-value references can be rebuilt as l-value references.
4108 ReferenceTypeLoc NewTL;
4109 if (isa<LValueReferenceType>(Result))
4110 NewTL = TLB.push<LValueReferenceTypeLoc>(Result);
4111 else
4112 NewTL = TLB.push<RValueReferenceTypeLoc>(Result);
4113 NewTL.setSigilLoc(TL.getSigilLoc());
4114
4115 return Result;
4116}
4117
Mike Stump11289f42009-09-09 15:08:12 +00004118template<typename Derived>
4119QualType
John McCall550e0c22009-10-21 00:40:46 +00004120TreeTransform<Derived>::TransformLValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004121 LValueReferenceTypeLoc TL) {
4122 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004123}
4124
Mike Stump11289f42009-09-09 15:08:12 +00004125template<typename Derived>
4126QualType
John McCall550e0c22009-10-21 00:40:46 +00004127TreeTransform<Derived>::TransformRValueReferenceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004128 RValueReferenceTypeLoc TL) {
4129 return TransformReferenceType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004130}
Mike Stump11289f42009-09-09 15:08:12 +00004131
Douglas Gregord6ff3322009-08-04 16:50:30 +00004132template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004133QualType
John McCall550e0c22009-10-21 00:40:46 +00004134TreeTransform<Derived>::TransformMemberPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004135 MemberPointerTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00004136 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004137 if (PointeeType.isNull())
4138 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004139
Abramo Bagnara509357842011-03-05 14:42:21 +00004140 TypeSourceInfo* OldClsTInfo = TL.getClassTInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004141 TypeSourceInfo *NewClsTInfo = nullptr;
Abramo Bagnara509357842011-03-05 14:42:21 +00004142 if (OldClsTInfo) {
4143 NewClsTInfo = getDerived().TransformType(OldClsTInfo);
4144 if (!NewClsTInfo)
4145 return QualType();
4146 }
4147
4148 const MemberPointerType *T = TL.getTypePtr();
4149 QualType OldClsType = QualType(T->getClass(), 0);
4150 QualType NewClsType;
4151 if (NewClsTInfo)
4152 NewClsType = NewClsTInfo->getType();
4153 else {
4154 NewClsType = getDerived().TransformType(OldClsType);
4155 if (NewClsType.isNull())
4156 return QualType();
4157 }
Mike Stump11289f42009-09-09 15:08:12 +00004158
John McCall550e0c22009-10-21 00:40:46 +00004159 QualType Result = TL.getType();
4160 if (getDerived().AlwaysRebuild() ||
4161 PointeeType != T->getPointeeType() ||
Abramo Bagnara509357842011-03-05 14:42:21 +00004162 NewClsType != OldClsType) {
4163 Result = getDerived().RebuildMemberPointerType(PointeeType, NewClsType,
John McCall70dd5f62009-10-30 00:06:24 +00004164 TL.getStarLoc());
John McCall550e0c22009-10-21 00:40:46 +00004165 if (Result.isNull())
4166 return QualType();
4167 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00004168
Reid Kleckner0503a872013-12-05 01:23:43 +00004169 // If we had to adjust the pointee type when building a member pointer, make
4170 // sure to push TypeLoc info for it.
4171 const MemberPointerType *MPT = Result->getAs<MemberPointerType>();
4172 if (MPT && PointeeType != MPT->getPointeeType()) {
4173 assert(isa<AdjustedType>(MPT->getPointeeType()));
4174 TLB.push<AdjustedTypeLoc>(MPT->getPointeeType());
4175 }
4176
John McCall550e0c22009-10-21 00:40:46 +00004177 MemberPointerTypeLoc NewTL = TLB.push<MemberPointerTypeLoc>(Result);
4178 NewTL.setSigilLoc(TL.getSigilLoc());
Abramo Bagnara509357842011-03-05 14:42:21 +00004179 NewTL.setClassTInfo(NewClsTInfo);
John McCall550e0c22009-10-21 00:40:46 +00004180
4181 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004182}
4183
Mike Stump11289f42009-09-09 15:08:12 +00004184template<typename Derived>
4185QualType
John McCall550e0c22009-10-21 00:40:46 +00004186TreeTransform<Derived>::TransformConstantArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004187 ConstantArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004188 const ConstantArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004189 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004190 if (ElementType.isNull())
4191 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004192
John McCall550e0c22009-10-21 00:40:46 +00004193 QualType Result = TL.getType();
4194 if (getDerived().AlwaysRebuild() ||
4195 ElementType != T->getElementType()) {
4196 Result = getDerived().RebuildConstantArrayType(ElementType,
4197 T->getSizeModifier(),
4198 T->getSize(),
John McCall70dd5f62009-10-30 00:06:24 +00004199 T->getIndexTypeCVRQualifiers(),
4200 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004201 if (Result.isNull())
4202 return QualType();
4203 }
Eli Friedmanf7f102f2012-01-25 22:19:07 +00004204
4205 // We might have either a ConstantArrayType or a VariableArrayType now:
4206 // a ConstantArrayType is allowed to have an element type which is a
4207 // VariableArrayType if the type is dependent. Fortunately, all array
4208 // types have the same location layout.
4209 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004210 NewTL.setLBracketLoc(TL.getLBracketLoc());
4211 NewTL.setRBracketLoc(TL.getRBracketLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004212
John McCall550e0c22009-10-21 00:40:46 +00004213 Expr *Size = TL.getSizeExpr();
4214 if (Size) {
Richard Smith764d2fe2011-12-20 02:08:33 +00004215 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4216 Sema::ConstantEvaluated);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004217 Size = getDerived().TransformExpr(Size).template getAs<Expr>();
4218 Size = SemaRef.ActOnConstantExpression(Size).get();
John McCall550e0c22009-10-21 00:40:46 +00004219 }
4220 NewTL.setSizeExpr(Size);
4221
4222 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004223}
Mike Stump11289f42009-09-09 15:08:12 +00004224
Douglas Gregord6ff3322009-08-04 16:50:30 +00004225template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004226QualType TreeTransform<Derived>::TransformIncompleteArrayType(
John McCall550e0c22009-10-21 00:40:46 +00004227 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004228 IncompleteArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004229 const IncompleteArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004230 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004231 if (ElementType.isNull())
4232 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004233
John McCall550e0c22009-10-21 00:40:46 +00004234 QualType Result = TL.getType();
4235 if (getDerived().AlwaysRebuild() ||
4236 ElementType != T->getElementType()) {
4237 Result = getDerived().RebuildIncompleteArrayType(ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +00004238 T->getSizeModifier(),
John McCall70dd5f62009-10-30 00:06:24 +00004239 T->getIndexTypeCVRQualifiers(),
4240 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004241 if (Result.isNull())
4242 return QualType();
4243 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004244
John McCall550e0c22009-10-21 00:40:46 +00004245 IncompleteArrayTypeLoc NewTL = TLB.push<IncompleteArrayTypeLoc>(Result);
4246 NewTL.setLBracketLoc(TL.getLBracketLoc());
4247 NewTL.setRBracketLoc(TL.getRBracketLoc());
Craig Topperc3ec1492014-05-26 06:22:03 +00004248 NewTL.setSizeExpr(nullptr);
John McCall550e0c22009-10-21 00:40:46 +00004249
4250 return Result;
4251}
4252
4253template<typename Derived>
4254QualType
4255TreeTransform<Derived>::TransformVariableArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004256 VariableArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004257 const VariableArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004258 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4259 if (ElementType.isNull())
4260 return QualType();
4261
John McCalldadc5752010-08-24 06:29:42 +00004262 ExprResult SizeResult
John McCall550e0c22009-10-21 00:40:46 +00004263 = getDerived().TransformExpr(T->getSizeExpr());
4264 if (SizeResult.isInvalid())
4265 return QualType();
4266
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004267 Expr *Size = SizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004268
4269 QualType Result = TL.getType();
4270 if (getDerived().AlwaysRebuild() ||
4271 ElementType != T->getElementType() ||
4272 Size != T->getSizeExpr()) {
4273 Result = getDerived().RebuildVariableArrayType(ElementType,
4274 T->getSizeModifier(),
John McCallb268a282010-08-23 23:25:46 +00004275 Size,
John McCall550e0c22009-10-21 00:40:46 +00004276 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004277 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004278 if (Result.isNull())
4279 return QualType();
4280 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004281
Serge Pavlov774c6d02014-02-06 03:49:11 +00004282 // We might have constant size array now, but fortunately it has the same
4283 // location layout.
4284 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
John McCall550e0c22009-10-21 00:40:46 +00004285 NewTL.setLBracketLoc(TL.getLBracketLoc());
4286 NewTL.setRBracketLoc(TL.getRBracketLoc());
4287 NewTL.setSizeExpr(Size);
4288
4289 return Result;
4290}
4291
4292template<typename Derived>
4293QualType
4294TreeTransform<Derived>::TransformDependentSizedArrayType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004295 DependentSizedArrayTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004296 const DependentSizedArrayType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004297 QualType ElementType = getDerived().TransformType(TLB, TL.getElementLoc());
4298 if (ElementType.isNull())
4299 return QualType();
4300
Richard Smith764d2fe2011-12-20 02:08:33 +00004301 // Array bounds are constant expressions.
4302 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4303 Sema::ConstantEvaluated);
John McCall550e0c22009-10-21 00:40:46 +00004304
John McCall33ddac02011-01-19 10:06:00 +00004305 // Prefer the expression from the TypeLoc; the other may have been uniqued.
4306 Expr *origSize = TL.getSizeExpr();
4307 if (!origSize) origSize = T->getSizeExpr();
4308
4309 ExprResult sizeResult
4310 = getDerived().TransformExpr(origSize);
Eli Friedmanc6237c62012-02-29 03:16:56 +00004311 sizeResult = SemaRef.ActOnConstantExpression(sizeResult);
John McCall33ddac02011-01-19 10:06:00 +00004312 if (sizeResult.isInvalid())
John McCall550e0c22009-10-21 00:40:46 +00004313 return QualType();
4314
John McCall33ddac02011-01-19 10:06:00 +00004315 Expr *size = sizeResult.get();
John McCall550e0c22009-10-21 00:40:46 +00004316
4317 QualType Result = TL.getType();
4318 if (getDerived().AlwaysRebuild() ||
4319 ElementType != T->getElementType() ||
John McCall33ddac02011-01-19 10:06:00 +00004320 size != origSize) {
John McCall550e0c22009-10-21 00:40:46 +00004321 Result = getDerived().RebuildDependentSizedArrayType(ElementType,
4322 T->getSizeModifier(),
John McCall33ddac02011-01-19 10:06:00 +00004323 size,
John McCall550e0c22009-10-21 00:40:46 +00004324 T->getIndexTypeCVRQualifiers(),
John McCall70dd5f62009-10-30 00:06:24 +00004325 TL.getBracketsRange());
John McCall550e0c22009-10-21 00:40:46 +00004326 if (Result.isNull())
4327 return QualType();
4328 }
John McCall550e0c22009-10-21 00:40:46 +00004329
4330 // We might have any sort of array type now, but fortunately they
4331 // all have the same location layout.
4332 ArrayTypeLoc NewTL = TLB.push<ArrayTypeLoc>(Result);
4333 NewTL.setLBracketLoc(TL.getLBracketLoc());
4334 NewTL.setRBracketLoc(TL.getRBracketLoc());
John McCall33ddac02011-01-19 10:06:00 +00004335 NewTL.setSizeExpr(size);
John McCall550e0c22009-10-21 00:40:46 +00004336
4337 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004338}
Mike Stump11289f42009-09-09 15:08:12 +00004339
4340template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004341QualType TreeTransform<Derived>::TransformDependentSizedExtVectorType(
John McCall550e0c22009-10-21 00:40:46 +00004342 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004343 DependentSizedExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004344 const DependentSizedExtVectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004345
4346 // FIXME: ext vector locs should be nested
Douglas Gregord6ff3322009-08-04 16:50:30 +00004347 QualType ElementType = getDerived().TransformType(T->getElementType());
4348 if (ElementType.isNull())
4349 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004350
Richard Smith764d2fe2011-12-20 02:08:33 +00004351 // Vector sizes are constant expressions.
4352 EnterExpressionEvaluationContext Unevaluated(SemaRef,
4353 Sema::ConstantEvaluated);
Douglas Gregore922c772009-08-04 22:27:00 +00004354
John McCalldadc5752010-08-24 06:29:42 +00004355 ExprResult Size = getDerived().TransformExpr(T->getSizeExpr());
Eli Friedmanc6237c62012-02-29 03:16:56 +00004356 Size = SemaRef.ActOnConstantExpression(Size);
Douglas Gregord6ff3322009-08-04 16:50:30 +00004357 if (Size.isInvalid())
4358 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004359
John McCall550e0c22009-10-21 00:40:46 +00004360 QualType Result = TL.getType();
4361 if (getDerived().AlwaysRebuild() ||
John McCall24e7cb62009-10-23 17:55:45 +00004362 ElementType != T->getElementType() ||
4363 Size.get() != T->getSizeExpr()) {
John McCall550e0c22009-10-21 00:40:46 +00004364 Result = getDerived().RebuildDependentSizedExtVectorType(ElementType,
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004365 Size.get(),
Douglas Gregord6ff3322009-08-04 16:50:30 +00004366 T->getAttributeLoc());
John McCall550e0c22009-10-21 00:40:46 +00004367 if (Result.isNull())
4368 return QualType();
4369 }
John McCall550e0c22009-10-21 00:40:46 +00004370
4371 // Result might be dependent or not.
4372 if (isa<DependentSizedExtVectorType>(Result)) {
4373 DependentSizedExtVectorTypeLoc NewTL
4374 = TLB.push<DependentSizedExtVectorTypeLoc>(Result);
4375 NewTL.setNameLoc(TL.getNameLoc());
4376 } else {
4377 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4378 NewTL.setNameLoc(TL.getNameLoc());
4379 }
4380
4381 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004382}
Mike Stump11289f42009-09-09 15:08:12 +00004383
4384template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004385QualType TreeTransform<Derived>::TransformVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004386 VectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004387 const VectorType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004388 QualType ElementType = getDerived().TransformType(T->getElementType());
4389 if (ElementType.isNull())
4390 return QualType();
4391
John McCall550e0c22009-10-21 00:40:46 +00004392 QualType Result = TL.getType();
4393 if (getDerived().AlwaysRebuild() ||
4394 ElementType != T->getElementType()) {
John Thompson22334602010-02-05 00:12:22 +00004395 Result = getDerived().RebuildVectorType(ElementType, T->getNumElements(),
Bob Wilsonaeb56442010-11-10 21:56:12 +00004396 T->getVectorKind());
John McCall550e0c22009-10-21 00:40:46 +00004397 if (Result.isNull())
4398 return QualType();
4399 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004400
John McCall550e0c22009-10-21 00:40:46 +00004401 VectorTypeLoc NewTL = TLB.push<VectorTypeLoc>(Result);
4402 NewTL.setNameLoc(TL.getNameLoc());
Mike Stump11289f42009-09-09 15:08:12 +00004403
John McCall550e0c22009-10-21 00:40:46 +00004404 return Result;
4405}
4406
4407template<typename Derived>
4408QualType TreeTransform<Derived>::TransformExtVectorType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004409 ExtVectorTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004410 const VectorType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00004411 QualType ElementType = getDerived().TransformType(T->getElementType());
4412 if (ElementType.isNull())
4413 return QualType();
4414
4415 QualType Result = TL.getType();
4416 if (getDerived().AlwaysRebuild() ||
4417 ElementType != T->getElementType()) {
4418 Result = getDerived().RebuildExtVectorType(ElementType,
4419 T->getNumElements(),
4420 /*FIXME*/ SourceLocation());
4421 if (Result.isNull())
4422 return QualType();
4423 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004424
John McCall550e0c22009-10-21 00:40:46 +00004425 ExtVectorTypeLoc NewTL = TLB.push<ExtVectorTypeLoc>(Result);
4426 NewTL.setNameLoc(TL.getNameLoc());
4427
4428 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004429}
Mike Stump11289f42009-09-09 15:08:12 +00004430
David Blaikie05785d12013-02-20 22:23:23 +00004431template <typename Derived>
4432ParmVarDecl *TreeTransform<Derived>::TransformFunctionTypeParam(
4433 ParmVarDecl *OldParm, int indexAdjustment, Optional<unsigned> NumExpansions,
4434 bool ExpectParameterPack) {
John McCall58f10c32010-03-11 09:03:00 +00004435 TypeSourceInfo *OldDI = OldParm->getTypeSourceInfo();
Craig Topperc3ec1492014-05-26 06:22:03 +00004436 TypeSourceInfo *NewDI = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004437
Douglas Gregor715e4612011-01-14 22:40:04 +00004438 if (NumExpansions && isa<PackExpansionType>(OldDI->getType())) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004439 // If we're substituting into a pack expansion type and we know the
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004440 // length we want to expand to, just substitute for the pattern.
Douglas Gregor715e4612011-01-14 22:40:04 +00004441 TypeLoc OldTL = OldDI->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004442 PackExpansionTypeLoc OldExpansionTL = OldTL.castAs<PackExpansionTypeLoc>();
Chad Rosier1dcde962012-08-08 18:46:20 +00004443
Douglas Gregor715e4612011-01-14 22:40:04 +00004444 TypeLocBuilder TLB;
4445 TypeLoc NewTL = OldDI->getTypeLoc();
4446 TLB.reserve(NewTL.getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00004447
4448 QualType Result = getDerived().TransformType(TLB,
Douglas Gregor715e4612011-01-14 22:40:04 +00004449 OldExpansionTL.getPatternLoc());
4450 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004451 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004452
4453 Result = RebuildPackExpansionType(Result,
4454 OldExpansionTL.getPatternLoc().getSourceRange(),
Douglas Gregor715e4612011-01-14 22:40:04 +00004455 OldExpansionTL.getEllipsisLoc(),
4456 NumExpansions);
4457 if (Result.isNull())
Craig Topperc3ec1492014-05-26 06:22:03 +00004458 return nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00004459
Douglas Gregor715e4612011-01-14 22:40:04 +00004460 PackExpansionTypeLoc NewExpansionTL
4461 = TLB.push<PackExpansionTypeLoc>(Result);
4462 NewExpansionTL.setEllipsisLoc(OldExpansionTL.getEllipsisLoc());
4463 NewDI = TLB.getTypeSourceInfo(SemaRef.Context, Result);
4464 } else
4465 NewDI = getDerived().TransformType(OldDI);
John McCall58f10c32010-03-11 09:03:00 +00004466 if (!NewDI)
Craig Topperc3ec1492014-05-26 06:22:03 +00004467 return nullptr;
John McCall58f10c32010-03-11 09:03:00 +00004468
John McCall8fb0d9d2011-05-01 22:35:37 +00004469 if (NewDI == OldDI && indexAdjustment == 0)
John McCall58f10c32010-03-11 09:03:00 +00004470 return OldParm;
John McCall8fb0d9d2011-05-01 22:35:37 +00004471
4472 ParmVarDecl *newParm = ParmVarDecl::Create(SemaRef.Context,
4473 OldParm->getDeclContext(),
4474 OldParm->getInnerLocStart(),
4475 OldParm->getLocation(),
4476 OldParm->getIdentifier(),
4477 NewDI->getType(),
4478 NewDI,
4479 OldParm->getStorageClass(),
Craig Topperc3ec1492014-05-26 06:22:03 +00004480 /* DefArg */ nullptr);
John McCall8fb0d9d2011-05-01 22:35:37 +00004481 newParm->setScopeInfo(OldParm->getFunctionScopeDepth(),
4482 OldParm->getFunctionScopeIndex() + indexAdjustment);
4483 return newParm;
John McCall58f10c32010-03-11 09:03:00 +00004484}
4485
4486template<typename Derived>
4487bool TreeTransform<Derived>::
Douglas Gregordd472162011-01-07 00:20:55 +00004488 TransformFunctionTypeParams(SourceLocation Loc,
4489 ParmVarDecl **Params, unsigned NumParams,
4490 const QualType *ParamTypes,
Chris Lattner01cf8db2011-07-20 06:58:45 +00004491 SmallVectorImpl<QualType> &OutParamTypes,
4492 SmallVectorImpl<ParmVarDecl*> *PVars) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004493 int indexAdjustment = 0;
4494
Douglas Gregordd472162011-01-07 00:20:55 +00004495 for (unsigned i = 0; i != NumParams; ++i) {
4496 if (ParmVarDecl *OldParm = Params[i]) {
John McCall8fb0d9d2011-05-01 22:35:37 +00004497 assert(OldParm->getFunctionScopeIndex() == i);
4498
David Blaikie05785d12013-02-20 22:23:23 +00004499 Optional<unsigned> NumExpansions;
Craig Topperc3ec1492014-05-26 06:22:03 +00004500 ParmVarDecl *NewParm = nullptr;
Douglas Gregor5499af42011-01-05 23:12:31 +00004501 if (OldParm->isParameterPack()) {
4502 // We have a function parameter pack that may need to be expanded.
Chris Lattner01cf8db2011-07-20 06:58:45 +00004503 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
John McCall58f10c32010-03-11 09:03:00 +00004504
Douglas Gregor5499af42011-01-05 23:12:31 +00004505 // Find the parameter packs that could be expanded.
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004506 TypeLoc TL = OldParm->getTypeSourceInfo()->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00004507 PackExpansionTypeLoc ExpansionTL = TL.castAs<PackExpansionTypeLoc>();
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004508 TypeLoc Pattern = ExpansionTL.getPatternLoc();
4509 SemaRef.collectUnexpandedParameterPacks(Pattern, Unexpanded);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004510 assert(Unexpanded.size() > 0 && "Could not find parameter packs!");
4511
Douglas Gregor5499af42011-01-05 23:12:31 +00004512 // Determine whether we should expand the parameter packs.
4513 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004514 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004515 Optional<unsigned> OrigNumExpansions =
4516 ExpansionTL.getTypePtr()->getNumExpansions();
Douglas Gregor715e4612011-01-14 22:40:04 +00004517 NumExpansions = OrigNumExpansions;
Douglas Gregorf6272cd2011-01-05 23:16:57 +00004518 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
4519 Pattern.getSourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004520 Unexpanded,
4521 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004522 RetainExpansion,
4523 NumExpansions)) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004524 return true;
4525 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004526
Douglas Gregor5499af42011-01-05 23:12:31 +00004527 if (ShouldExpand) {
4528 // Expand the function parameter pack into multiple, separate
4529 // parameters.
Douglas Gregorf3010112011-01-07 16:43:16 +00004530 getDerived().ExpandingFunctionParameterPack(OldParm);
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004531 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004532 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
Chad Rosier1dcde962012-08-08 18:46:20 +00004533 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004534 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004535 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004536 OrigNumExpansions,
4537 /*ExpectParameterPack=*/false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004538 if (!NewParm)
4539 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004540
Douglas Gregordd472162011-01-07 00:20:55 +00004541 OutParamTypes.push_back(NewParm->getType());
4542 if (PVars)
4543 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004544 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004545
4546 // If we're supposed to retain a pack expansion, do so by temporarily
4547 // forgetting the partially-substituted parameter pack.
4548 if (RetainExpansion) {
4549 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
Chad Rosier1dcde962012-08-08 18:46:20 +00004550 ParmVarDecl *NewParm
Douglas Gregor715e4612011-01-14 22:40:04 +00004551 = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004552 indexAdjustment++,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004553 OrigNumExpansions,
4554 /*ExpectParameterPack=*/false);
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004555 if (!NewParm)
4556 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004557
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004558 OutParamTypes.push_back(NewParm->getType());
4559 if (PVars)
4560 PVars->push_back(NewParm);
4561 }
4562
John McCall8fb0d9d2011-05-01 22:35:37 +00004563 // The next parameter should have the same adjustment as the
4564 // last thing we pushed, but we post-incremented indexAdjustment
4565 // on every push. Also, if we push nothing, the adjustment should
4566 // go down by one.
4567 indexAdjustment--;
4568
Douglas Gregor5499af42011-01-05 23:12:31 +00004569 // We're done with the pack expansion.
4570 continue;
4571 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004572
4573 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004574 // expansion.
Douglas Gregorc52264e2011-03-02 02:04:06 +00004575 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4576 NewParm = getDerived().TransformFunctionTypeParam(OldParm,
John McCall8fb0d9d2011-05-01 22:35:37 +00004577 indexAdjustment,
Douglas Gregor0dd22bc2012-01-25 16:15:54 +00004578 NumExpansions,
4579 /*ExpectParameterPack=*/true);
Douglas Gregorc52264e2011-03-02 02:04:06 +00004580 } else {
David Blaikie05785d12013-02-20 22:23:23 +00004581 NewParm = getDerived().TransformFunctionTypeParam(
David Blaikie7a30dc52013-02-21 01:47:18 +00004582 OldParm, indexAdjustment, None, /*ExpectParameterPack=*/ false);
Douglas Gregor5499af42011-01-05 23:12:31 +00004583 }
Douglas Gregorc52264e2011-03-02 02:04:06 +00004584
John McCall58f10c32010-03-11 09:03:00 +00004585 if (!NewParm)
4586 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004587
Douglas Gregordd472162011-01-07 00:20:55 +00004588 OutParamTypes.push_back(NewParm->getType());
4589 if (PVars)
4590 PVars->push_back(NewParm);
Douglas Gregor5499af42011-01-05 23:12:31 +00004591 continue;
4592 }
John McCall58f10c32010-03-11 09:03:00 +00004593
4594 // Deal with the possibility that we don't have a parameter
4595 // declaration for this parameter.
Douglas Gregordd472162011-01-07 00:20:55 +00004596 QualType OldType = ParamTypes[i];
Douglas Gregor5499af42011-01-05 23:12:31 +00004597 bool IsPackExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00004598 Optional<unsigned> NumExpansions;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004599 QualType NewType;
Chad Rosier1dcde962012-08-08 18:46:20 +00004600 if (const PackExpansionType *Expansion
Douglas Gregor5499af42011-01-05 23:12:31 +00004601 = dyn_cast<PackExpansionType>(OldType)) {
4602 // We have a function parameter pack that may need to be expanded.
4603 QualType Pattern = Expansion->getPattern();
Chris Lattner01cf8db2011-07-20 06:58:45 +00004604 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
Douglas Gregor5499af42011-01-05 23:12:31 +00004605 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00004606
Douglas Gregor5499af42011-01-05 23:12:31 +00004607 // Determine whether we should expand the parameter packs.
4608 bool ShouldExpand = false;
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004609 bool RetainExpansion = false;
Douglas Gregordd472162011-01-07 00:20:55 +00004610 if (getDerived().TryExpandParameterPacks(Loc, SourceRange(),
Chad Rosier1dcde962012-08-08 18:46:20 +00004611 Unexpanded,
4612 ShouldExpand,
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004613 RetainExpansion,
4614 NumExpansions)) {
John McCall58f10c32010-03-11 09:03:00 +00004615 return true;
Douglas Gregor5499af42011-01-05 23:12:31 +00004616 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004617
Douglas Gregor5499af42011-01-05 23:12:31 +00004618 if (ShouldExpand) {
Chad Rosier1dcde962012-08-08 18:46:20 +00004619 // Expand the function parameter pack into multiple, separate
Douglas Gregor5499af42011-01-05 23:12:31 +00004620 // parameters.
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004621 for (unsigned I = 0; I != *NumExpansions; ++I) {
Douglas Gregor5499af42011-01-05 23:12:31 +00004622 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
4623 QualType NewType = getDerived().TransformType(Pattern);
4624 if (NewType.isNull())
4625 return true;
John McCall58f10c32010-03-11 09:03:00 +00004626
Douglas Gregordd472162011-01-07 00:20:55 +00004627 OutParamTypes.push_back(NewType);
4628 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004629 PVars->push_back(nullptr);
Douglas Gregor5499af42011-01-05 23:12:31 +00004630 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004631
Douglas Gregor5499af42011-01-05 23:12:31 +00004632 // We're done with the pack expansion.
4633 continue;
4634 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004635
Douglas Gregor48d24112011-01-10 20:53:55 +00004636 // If we're supposed to retain a pack expansion, do so by temporarily
4637 // forgetting the partially-substituted parameter pack.
4638 if (RetainExpansion) {
4639 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
4640 QualType NewType = getDerived().TransformType(Pattern);
4641 if (NewType.isNull())
4642 return true;
Chad Rosier1dcde962012-08-08 18:46:20 +00004643
Douglas Gregor48d24112011-01-10 20:53:55 +00004644 OutParamTypes.push_back(NewType);
4645 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004646 PVars->push_back(nullptr);
Douglas Gregor48d24112011-01-10 20:53:55 +00004647 }
Douglas Gregora8bac7f2011-01-10 07:32:04 +00004648
Chad Rosier1dcde962012-08-08 18:46:20 +00004649 // We'll substitute the parameter now without expanding the pack
Douglas Gregor5499af42011-01-05 23:12:31 +00004650 // expansion.
4651 OldType = Expansion->getPattern();
4652 IsPackExpansion = true;
Douglas Gregorc52264e2011-03-02 02:04:06 +00004653 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4654 NewType = getDerived().TransformType(OldType);
4655 } else {
4656 NewType = getDerived().TransformType(OldType);
Douglas Gregor5499af42011-01-05 23:12:31 +00004657 }
Chad Rosier1dcde962012-08-08 18:46:20 +00004658
Douglas Gregor5499af42011-01-05 23:12:31 +00004659 if (NewType.isNull())
4660 return true;
4661
4662 if (IsPackExpansion)
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00004663 NewType = getSema().Context.getPackExpansionType(NewType,
4664 NumExpansions);
Chad Rosier1dcde962012-08-08 18:46:20 +00004665
Douglas Gregordd472162011-01-07 00:20:55 +00004666 OutParamTypes.push_back(NewType);
4667 if (PVars)
Craig Topperc3ec1492014-05-26 06:22:03 +00004668 PVars->push_back(nullptr);
John McCall58f10c32010-03-11 09:03:00 +00004669 }
4670
John McCall8fb0d9d2011-05-01 22:35:37 +00004671#ifndef NDEBUG
4672 if (PVars) {
4673 for (unsigned i = 0, e = PVars->size(); i != e; ++i)
4674 if (ParmVarDecl *parm = (*PVars)[i])
4675 assert(parm->getFunctionScopeIndex() == i);
Douglas Gregor5499af42011-01-05 23:12:31 +00004676 }
John McCall8fb0d9d2011-05-01 22:35:37 +00004677#endif
4678
4679 return false;
4680}
John McCall58f10c32010-03-11 09:03:00 +00004681
4682template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +00004683QualType
John McCall550e0c22009-10-21 00:40:46 +00004684TreeTransform<Derived>::TransformFunctionProtoType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004685 FunctionProtoTypeLoc TL) {
Richard Smith2e321552014-11-12 02:00:47 +00004686 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00004687 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00004688 return getDerived().TransformFunctionProtoType(
4689 TLB, TL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00004690 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
4691 return This->TransformExceptionSpec(TL.getBeginLoc(), ESI,
4692 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00004693 });
Douglas Gregor3024f072012-04-16 07:05:22 +00004694}
4695
Richard Smith2e321552014-11-12 02:00:47 +00004696template<typename Derived> template<typename Fn>
4697QualType TreeTransform<Derived>::TransformFunctionProtoType(
4698 TypeLocBuilder &TLB, FunctionProtoTypeLoc TL, CXXRecordDecl *ThisContext,
4699 unsigned ThisTypeQuals, Fn TransformExceptionSpec) {
Douglas Gregor4afc2362010-08-31 00:26:14 +00004700 // Transform the parameters and return type.
4701 //
Richard Smithf623c962012-04-17 00:58:00 +00004702 // We are required to instantiate the params and return type in source order.
Douglas Gregor7fb25412010-10-01 18:44:50 +00004703 // When the function has a trailing return type, we instantiate the
4704 // parameters before the return type, since the return type can then refer
4705 // to the parameters themselves (via decltype, sizeof, etc.).
4706 //
Chris Lattner01cf8db2011-07-20 06:58:45 +00004707 SmallVector<QualType, 4> ParamTypes;
4708 SmallVector<ParmVarDecl*, 4> ParamDecls;
John McCall424cec92011-01-19 06:33:43 +00004709 const FunctionProtoType *T = TL.getTypePtr();
Douglas Gregor4afc2362010-08-31 00:26:14 +00004710
Douglas Gregor7fb25412010-10-01 18:44:50 +00004711 QualType ResultType;
4712
Richard Smith1226c602012-08-14 22:51:13 +00004713 if (T->hasTrailingReturn()) {
Alp Toker9cacbab2014-01-20 20:26:09 +00004714 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004715 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004716 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004717 return QualType();
4718
Douglas Gregor3024f072012-04-16 07:05:22 +00004719 {
4720 // C++11 [expr.prim.general]p3:
Chad Rosier1dcde962012-08-08 18:46:20 +00004721 // If a declaration declares a member function or member function
4722 // template of a class X, the expression this is a prvalue of type
Douglas Gregor3024f072012-04-16 07:05:22 +00004723 // "pointer to cv-qualifier-seq X" between the optional cv-qualifer-seq
Chad Rosier1dcde962012-08-08 18:46:20 +00004724 // and the end of the function-definition, member-declarator, or
Douglas Gregor3024f072012-04-16 07:05:22 +00004725 // declarator.
4726 Sema::CXXThisScopeRAII ThisScope(SemaRef, ThisContext, ThisTypeQuals);
Chad Rosier1dcde962012-08-08 18:46:20 +00004727
Alp Toker42a16a62014-01-25 23:51:36 +00004728 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor3024f072012-04-16 07:05:22 +00004729 if (ResultType.isNull())
4730 return QualType();
4731 }
Douglas Gregor7fb25412010-10-01 18:44:50 +00004732 }
4733 else {
Alp Toker42a16a62014-01-25 23:51:36 +00004734 ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
Douglas Gregor7fb25412010-10-01 18:44:50 +00004735 if (ResultType.isNull())
4736 return QualType();
4737
Alp Toker9cacbab2014-01-20 20:26:09 +00004738 if (getDerived().TransformFunctionTypeParams(
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004739 TL.getBeginLoc(), TL.getParmArray(), TL.getNumParams(),
Alp Toker9cacbab2014-01-20 20:26:09 +00004740 TL.getTypePtr()->param_type_begin(), ParamTypes, &ParamDecls))
Douglas Gregor7fb25412010-10-01 18:44:50 +00004741 return QualType();
4742 }
4743
Richard Smith2e321552014-11-12 02:00:47 +00004744 FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
4745
4746 bool EPIChanged = false;
4747 if (TransformExceptionSpec(EPI.ExceptionSpec, EPIChanged))
4748 return QualType();
4749
4750 // FIXME: Need to transform ConsumedParameters for variadic template
4751 // expansion.
Richard Smithf623c962012-04-17 00:58:00 +00004752
John McCall550e0c22009-10-21 00:40:46 +00004753 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004754 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType() ||
Benjamin Kramere1c08b02015-08-18 08:10:39 +00004755 T->getParamTypes() != llvm::makeArrayRef(ParamTypes) || EPIChanged) {
Richard Smith2e321552014-11-12 02:00:47 +00004756 Result = getDerived().RebuildFunctionProtoType(ResultType, ParamTypes, EPI);
John McCall550e0c22009-10-21 00:40:46 +00004757 if (Result.isNull())
4758 return QualType();
4759 }
Mike Stump11289f42009-09-09 15:08:12 +00004760
John McCall550e0c22009-10-21 00:40:46 +00004761 FunctionProtoTypeLoc NewTL = TLB.push<FunctionProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004762 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004763 NewTL.setLParenLoc(TL.getLParenLoc());
4764 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004765 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
Alp Tokerb3fd5cf2014-01-21 00:32:38 +00004766 for (unsigned i = 0, e = NewTL.getNumParams(); i != e; ++i)
4767 NewTL.setParam(i, ParamDecls[i]);
John McCall550e0c22009-10-21 00:40:46 +00004768
4769 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004770}
Mike Stump11289f42009-09-09 15:08:12 +00004771
Douglas Gregord6ff3322009-08-04 16:50:30 +00004772template<typename Derived>
Richard Smith2e321552014-11-12 02:00:47 +00004773bool TreeTransform<Derived>::TransformExceptionSpec(
4774 SourceLocation Loc, FunctionProtoType::ExceptionSpecInfo &ESI,
4775 SmallVectorImpl<QualType> &Exceptions, bool &Changed) {
4776 assert(ESI.Type != EST_Uninstantiated && ESI.Type != EST_Unevaluated);
4777
4778 // Instantiate a dynamic noexcept expression, if any.
4779 if (ESI.Type == EST_ComputedNoexcept) {
4780 EnterExpressionEvaluationContext Unevaluated(getSema(),
4781 Sema::ConstantEvaluated);
4782 ExprResult NoexceptExpr = getDerived().TransformExpr(ESI.NoexceptExpr);
4783 if (NoexceptExpr.isInvalid())
4784 return true;
4785
4786 NoexceptExpr = getSema().CheckBooleanCondition(
4787 NoexceptExpr.get(), NoexceptExpr.get()->getLocStart());
4788 if (NoexceptExpr.isInvalid())
4789 return true;
4790
4791 if (!NoexceptExpr.get()->isValueDependent()) {
4792 NoexceptExpr = getSema().VerifyIntegerConstantExpression(
4793 NoexceptExpr.get(), nullptr,
4794 diag::err_noexcept_needs_constant_expression,
4795 /*AllowFold*/false);
4796 if (NoexceptExpr.isInvalid())
4797 return true;
4798 }
4799
4800 if (ESI.NoexceptExpr != NoexceptExpr.get())
4801 Changed = true;
4802 ESI.NoexceptExpr = NoexceptExpr.get();
4803 }
4804
4805 if (ESI.Type != EST_Dynamic)
4806 return false;
4807
4808 // Instantiate a dynamic exception specification's type.
4809 for (QualType T : ESI.Exceptions) {
4810 if (const PackExpansionType *PackExpansion =
4811 T->getAs<PackExpansionType>()) {
4812 Changed = true;
4813
4814 // We have a pack expansion. Instantiate it.
4815 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
4816 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
4817 Unexpanded);
4818 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
4819
4820 // Determine whether the set of unexpanded parameter packs can and
4821 // should
4822 // be expanded.
4823 bool Expand = false;
4824 bool RetainExpansion = false;
4825 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
4826 // FIXME: Track the location of the ellipsis (and track source location
4827 // information for the types in the exception specification in general).
4828 if (getDerived().TryExpandParameterPacks(
4829 Loc, SourceRange(), Unexpanded, Expand,
4830 RetainExpansion, NumExpansions))
4831 return true;
4832
4833 if (!Expand) {
4834 // We can't expand this pack expansion into separate arguments yet;
4835 // just substitute into the pattern and create a new pack expansion
4836 // type.
4837 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
4838 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4839 if (U.isNull())
4840 return true;
4841
4842 U = SemaRef.Context.getPackExpansionType(U, NumExpansions);
4843 Exceptions.push_back(U);
4844 continue;
4845 }
4846
4847 // Substitute into the pack expansion pattern for each slice of the
4848 // pack.
4849 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
4850 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
4851
4852 QualType U = getDerived().TransformType(PackExpansion->getPattern());
4853 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4854 return true;
4855
4856 Exceptions.push_back(U);
4857 }
4858 } else {
4859 QualType U = getDerived().TransformType(T);
4860 if (U.isNull() || SemaRef.CheckSpecifiedExceptionType(U, Loc))
4861 return true;
4862 if (T != U)
4863 Changed = true;
4864
4865 Exceptions.push_back(U);
4866 }
4867 }
4868
4869 ESI.Exceptions = Exceptions;
4870 return false;
4871}
4872
4873template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +00004874QualType TreeTransform<Derived>::TransformFunctionNoProtoType(
John McCall550e0c22009-10-21 00:40:46 +00004875 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004876 FunctionNoProtoTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004877 const FunctionNoProtoType *T = TL.getTypePtr();
Alp Toker42a16a62014-01-25 23:51:36 +00004878 QualType ResultType = getDerived().TransformType(TLB, TL.getReturnLoc());
John McCall550e0c22009-10-21 00:40:46 +00004879 if (ResultType.isNull())
4880 return QualType();
4881
4882 QualType Result = TL.getType();
Alp Toker314cc812014-01-25 16:55:45 +00004883 if (getDerived().AlwaysRebuild() || ResultType != T->getReturnType())
John McCall550e0c22009-10-21 00:40:46 +00004884 Result = getDerived().RebuildFunctionNoProtoType(ResultType);
4885
4886 FunctionNoProtoTypeLoc NewTL = TLB.push<FunctionNoProtoTypeLoc>(Result);
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004887 NewTL.setLocalRangeBegin(TL.getLocalRangeBegin());
Abramo Bagnaraaeeb9892012-10-04 21:42:10 +00004888 NewTL.setLParenLoc(TL.getLParenLoc());
4889 NewTL.setRParenLoc(TL.getRParenLoc());
Abramo Bagnaraf2a79d92011-03-12 11:17:06 +00004890 NewTL.setLocalRangeEnd(TL.getLocalRangeEnd());
John McCall550e0c22009-10-21 00:40:46 +00004891
4892 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004893}
Mike Stump11289f42009-09-09 15:08:12 +00004894
John McCallb96ec562009-12-04 22:46:56 +00004895template<typename Derived> QualType
4896TreeTransform<Derived>::TransformUnresolvedUsingType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004897 UnresolvedUsingTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004898 const UnresolvedUsingType *T = TL.getTypePtr();
Douglas Gregora04f2ca2010-03-01 15:56:25 +00004899 Decl *D = getDerived().TransformDecl(TL.getNameLoc(), T->getDecl());
John McCallb96ec562009-12-04 22:46:56 +00004900 if (!D)
4901 return QualType();
4902
4903 QualType Result = TL.getType();
4904 if (getDerived().AlwaysRebuild() || D != T->getDecl()) {
4905 Result = getDerived().RebuildUnresolvedUsingType(D);
4906 if (Result.isNull())
4907 return QualType();
4908 }
4909
4910 // We might get an arbitrary type spec type back. We should at
4911 // least always get a type spec type, though.
4912 TypeSpecTypeLoc NewTL = TLB.pushTypeSpec(Result);
4913 NewTL.setNameLoc(TL.getNameLoc());
4914
4915 return Result;
4916}
4917
Douglas Gregord6ff3322009-08-04 16:50:30 +00004918template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004919QualType TreeTransform<Derived>::TransformTypedefType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004920 TypedefTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00004921 const TypedefType *T = TL.getTypePtr();
Richard Smithdda56e42011-04-15 14:24:37 +00004922 TypedefNameDecl *Typedef
4923 = cast_or_null<TypedefNameDecl>(getDerived().TransformDecl(TL.getNameLoc(),
4924 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00004925 if (!Typedef)
4926 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004927
John McCall550e0c22009-10-21 00:40:46 +00004928 QualType Result = TL.getType();
4929 if (getDerived().AlwaysRebuild() ||
4930 Typedef != T->getDecl()) {
4931 Result = getDerived().RebuildTypedefType(Typedef);
4932 if (Result.isNull())
4933 return QualType();
4934 }
Mike Stump11289f42009-09-09 15:08:12 +00004935
John McCall550e0c22009-10-21 00:40:46 +00004936 TypedefTypeLoc NewTL = TLB.push<TypedefTypeLoc>(Result);
4937 NewTL.setNameLoc(TL.getNameLoc());
4938
4939 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004940}
Mike Stump11289f42009-09-09 15:08:12 +00004941
Douglas Gregord6ff3322009-08-04 16:50:30 +00004942template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004943QualType TreeTransform<Derived>::TransformTypeOfExprType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004944 TypeOfExprTypeLoc TL) {
Douglas Gregore922c772009-08-04 22:27:00 +00004945 // typeof expressions are not potentially evaluated contexts
Eli Friedman15681d62012-09-26 04:34:21 +00004946 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
4947 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00004948
John McCalldadc5752010-08-24 06:29:42 +00004949 ExprResult E = getDerived().TransformExpr(TL.getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00004950 if (E.isInvalid())
4951 return QualType();
4952
Eli Friedmane4f22df2012-02-29 04:03:55 +00004953 E = SemaRef.HandleExprEvaluationContextForTypeof(E.get());
4954 if (E.isInvalid())
4955 return QualType();
4956
John McCall550e0c22009-10-21 00:40:46 +00004957 QualType Result = TL.getType();
4958 if (getDerived().AlwaysRebuild() ||
John McCalle8595032010-01-13 20:03:27 +00004959 E.get() != TL.getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00004960 Result = getDerived().RebuildTypeOfExprType(E.get(), TL.getTypeofLoc());
John McCall550e0c22009-10-21 00:40:46 +00004961 if (Result.isNull())
4962 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00004963 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00004964 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00004965
John McCall550e0c22009-10-21 00:40:46 +00004966 TypeOfExprTypeLoc NewTL = TLB.push<TypeOfExprTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004967 NewTL.setTypeofLoc(TL.getTypeofLoc());
4968 NewTL.setLParenLoc(TL.getLParenLoc());
4969 NewTL.setRParenLoc(TL.getRParenLoc());
John McCall550e0c22009-10-21 00:40:46 +00004970
4971 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004972}
Mike Stump11289f42009-09-09 15:08:12 +00004973
4974template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004975QualType TreeTransform<Derived>::TransformTypeOfType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00004976 TypeOfTypeLoc TL) {
John McCalle8595032010-01-13 20:03:27 +00004977 TypeSourceInfo* Old_Under_TI = TL.getUnderlyingTInfo();
4978 TypeSourceInfo* New_Under_TI = getDerived().TransformType(Old_Under_TI);
4979 if (!New_Under_TI)
Douglas Gregord6ff3322009-08-04 16:50:30 +00004980 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00004981
John McCall550e0c22009-10-21 00:40:46 +00004982 QualType Result = TL.getType();
John McCalle8595032010-01-13 20:03:27 +00004983 if (getDerived().AlwaysRebuild() || New_Under_TI != Old_Under_TI) {
4984 Result = getDerived().RebuildTypeOfType(New_Under_TI->getType());
John McCall550e0c22009-10-21 00:40:46 +00004985 if (Result.isNull())
4986 return QualType();
4987 }
Mike Stump11289f42009-09-09 15:08:12 +00004988
John McCall550e0c22009-10-21 00:40:46 +00004989 TypeOfTypeLoc NewTL = TLB.push<TypeOfTypeLoc>(Result);
John McCalle8595032010-01-13 20:03:27 +00004990 NewTL.setTypeofLoc(TL.getTypeofLoc());
4991 NewTL.setLParenLoc(TL.getLParenLoc());
4992 NewTL.setRParenLoc(TL.getRParenLoc());
4993 NewTL.setUnderlyingTInfo(New_Under_TI);
John McCall550e0c22009-10-21 00:40:46 +00004994
4995 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00004996}
Mike Stump11289f42009-09-09 15:08:12 +00004997
4998template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00004999QualType TreeTransform<Derived>::TransformDecltypeType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005000 DecltypeTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005001 const DecltypeType *T = TL.getTypePtr();
John McCall550e0c22009-10-21 00:40:46 +00005002
Douglas Gregore922c772009-08-04 22:27:00 +00005003 // decltype expressions are not potentially evaluated contexts
Craig Topperc3ec1492014-05-26 06:22:03 +00005004 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
5005 nullptr, /*IsDecltype=*/ true);
Mike Stump11289f42009-09-09 15:08:12 +00005006
John McCalldadc5752010-08-24 06:29:42 +00005007 ExprResult E = getDerived().TransformExpr(T->getUnderlyingExpr());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005008 if (E.isInvalid())
5009 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005010
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005011 E = getSema().ActOnDecltypeExpression(E.get());
Richard Smithfd555f62012-02-22 02:04:18 +00005012 if (E.isInvalid())
5013 return QualType();
5014
John McCall550e0c22009-10-21 00:40:46 +00005015 QualType Result = TL.getType();
5016 if (getDerived().AlwaysRebuild() ||
5017 E.get() != T->getUnderlyingExpr()) {
John McCall36e7fe32010-10-12 00:20:44 +00005018 Result = getDerived().RebuildDecltypeType(E.get(), TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005019 if (Result.isNull())
5020 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005021 }
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005022 else E.get();
Mike Stump11289f42009-09-09 15:08:12 +00005023
John McCall550e0c22009-10-21 00:40:46 +00005024 DecltypeTypeLoc NewTL = TLB.push<DecltypeTypeLoc>(Result);
5025 NewTL.setNameLoc(TL.getNameLoc());
5026
5027 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005028}
5029
5030template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +00005031QualType TreeTransform<Derived>::TransformUnaryTransformType(
5032 TypeLocBuilder &TLB,
5033 UnaryTransformTypeLoc TL) {
5034 QualType Result = TL.getType();
5035 if (Result->isDependentType()) {
5036 const UnaryTransformType *T = TL.getTypePtr();
5037 QualType NewBase =
5038 getDerived().TransformType(TL.getUnderlyingTInfo())->getType();
5039 Result = getDerived().RebuildUnaryTransformType(NewBase,
5040 T->getUTTKind(),
5041 TL.getKWLoc());
5042 if (Result.isNull())
5043 return QualType();
5044 }
5045
5046 UnaryTransformTypeLoc NewTL = TLB.push<UnaryTransformTypeLoc>(Result);
5047 NewTL.setKWLoc(TL.getKWLoc());
5048 NewTL.setParensRange(TL.getParensRange());
5049 NewTL.setUnderlyingTInfo(TL.getUnderlyingTInfo());
5050 return Result;
5051}
5052
5053template<typename Derived>
Richard Smith30482bc2011-02-20 03:19:35 +00005054QualType TreeTransform<Derived>::TransformAutoType(TypeLocBuilder &TLB,
5055 AutoTypeLoc TL) {
5056 const AutoType *T = TL.getTypePtr();
5057 QualType OldDeduced = T->getDeducedType();
5058 QualType NewDeduced;
5059 if (!OldDeduced.isNull()) {
5060 NewDeduced = getDerived().TransformType(OldDeduced);
5061 if (NewDeduced.isNull())
5062 return QualType();
5063 }
5064
5065 QualType Result = TL.getType();
Richard Smith27d807c2013-04-30 13:56:41 +00005066 if (getDerived().AlwaysRebuild() || NewDeduced != OldDeduced ||
5067 T->isDependentType()) {
Richard Smith74aeef52013-04-26 16:15:35 +00005068 Result = getDerived().RebuildAutoType(NewDeduced, T->isDecltypeAuto());
Richard Smith30482bc2011-02-20 03:19:35 +00005069 if (Result.isNull())
5070 return QualType();
5071 }
5072
5073 AutoTypeLoc NewTL = TLB.push<AutoTypeLoc>(Result);
5074 NewTL.setNameLoc(TL.getNameLoc());
5075
5076 return Result;
5077}
5078
5079template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005080QualType TreeTransform<Derived>::TransformRecordType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005081 RecordTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005082 const RecordType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005083 RecordDecl *Record
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005084 = cast_or_null<RecordDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5085 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005086 if (!Record)
5087 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005088
John McCall550e0c22009-10-21 00:40:46 +00005089 QualType Result = TL.getType();
5090 if (getDerived().AlwaysRebuild() ||
5091 Record != T->getDecl()) {
5092 Result = getDerived().RebuildRecordType(Record);
5093 if (Result.isNull())
5094 return QualType();
5095 }
Mike Stump11289f42009-09-09 15:08:12 +00005096
John McCall550e0c22009-10-21 00:40:46 +00005097 RecordTypeLoc NewTL = TLB.push<RecordTypeLoc>(Result);
5098 NewTL.setNameLoc(TL.getNameLoc());
5099
5100 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005101}
Mike Stump11289f42009-09-09 15:08:12 +00005102
5103template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005104QualType TreeTransform<Derived>::TransformEnumType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005105 EnumTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005106 const EnumType *T = TL.getTypePtr();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005107 EnumDecl *Enum
Douglas Gregora04f2ca2010-03-01 15:56:25 +00005108 = cast_or_null<EnumDecl>(getDerived().TransformDecl(TL.getNameLoc(),
5109 T->getDecl()));
Douglas Gregord6ff3322009-08-04 16:50:30 +00005110 if (!Enum)
5111 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005112
John McCall550e0c22009-10-21 00:40:46 +00005113 QualType Result = TL.getType();
5114 if (getDerived().AlwaysRebuild() ||
5115 Enum != T->getDecl()) {
5116 Result = getDerived().RebuildEnumType(Enum);
5117 if (Result.isNull())
5118 return QualType();
5119 }
Mike Stump11289f42009-09-09 15:08:12 +00005120
John McCall550e0c22009-10-21 00:40:46 +00005121 EnumTypeLoc NewTL = TLB.push<EnumTypeLoc>(Result);
5122 NewTL.setNameLoc(TL.getNameLoc());
5123
5124 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005125}
John McCallfcc33b02009-09-05 00:15:47 +00005126
John McCalle78aac42010-03-10 03:28:59 +00005127template<typename Derived>
5128QualType TreeTransform<Derived>::TransformInjectedClassNameType(
5129 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005130 InjectedClassNameTypeLoc TL) {
John McCalle78aac42010-03-10 03:28:59 +00005131 Decl *D = getDerived().TransformDecl(TL.getNameLoc(),
5132 TL.getTypePtr()->getDecl());
5133 if (!D) return QualType();
5134
5135 QualType T = SemaRef.Context.getTypeDeclType(cast<TypeDecl>(D));
5136 TLB.pushTypeSpec(T).setNameLoc(TL.getNameLoc());
5137 return T;
5138}
5139
Douglas Gregord6ff3322009-08-04 16:50:30 +00005140template<typename Derived>
5141QualType TreeTransform<Derived>::TransformTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005142 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005143 TemplateTypeParmTypeLoc TL) {
John McCall550e0c22009-10-21 00:40:46 +00005144 return TransformTypeSpecType(TLB, TL);
Douglas Gregord6ff3322009-08-04 16:50:30 +00005145}
5146
Mike Stump11289f42009-09-09 15:08:12 +00005147template<typename Derived>
John McCallcebee162009-10-18 09:09:24 +00005148QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmType(
John McCall550e0c22009-10-21 00:40:46 +00005149 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005150 SubstTemplateTypeParmTypeLoc TL) {
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005151 const SubstTemplateTypeParmType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005152
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005153 // Substitute into the replacement type, which itself might involve something
5154 // that needs to be transformed. This only tends to occur with default
5155 // template arguments of template template parameters.
5156 TemporaryBase Rebase(*this, TL.getNameLoc(), DeclarationName());
5157 QualType Replacement = getDerived().TransformType(T->getReplacementType());
5158 if (Replacement.isNull())
5159 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005160
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005161 // Always canonicalize the replacement type.
5162 Replacement = SemaRef.Context.getCanonicalType(Replacement);
5163 QualType Result
Chad Rosier1dcde962012-08-08 18:46:20 +00005164 = SemaRef.Context.getSubstTemplateTypeParmType(T->getReplacedParameter(),
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005165 Replacement);
Chad Rosier1dcde962012-08-08 18:46:20 +00005166
Douglas Gregor20bf98b2011-03-05 17:19:27 +00005167 // Propagate type-source information.
5168 SubstTemplateTypeParmTypeLoc NewTL
5169 = TLB.push<SubstTemplateTypeParmTypeLoc>(Result);
5170 NewTL.setNameLoc(TL.getNameLoc());
5171 return Result;
5172
John McCallcebee162009-10-18 09:09:24 +00005173}
5174
5175template<typename Derived>
Douglas Gregorada4b792011-01-14 02:55:32 +00005176QualType TreeTransform<Derived>::TransformSubstTemplateTypeParmPackType(
5177 TypeLocBuilder &TLB,
5178 SubstTemplateTypeParmPackTypeLoc TL) {
5179 return TransformTypeSpecType(TLB, TL);
5180}
5181
5182template<typename Derived>
John McCall0ad16662009-10-29 08:12:44 +00005183QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +00005184 TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005185 TemplateSpecializationTypeLoc TL) {
John McCall0ad16662009-10-29 08:12:44 +00005186 const TemplateSpecializationType *T = TL.getTypePtr();
5187
Douglas Gregordf846d12011-03-02 18:46:51 +00005188 // The nested-name-specifier never matters in a TemplateSpecializationType,
5189 // because we can't have a dependent nested-name-specifier anyway.
5190 CXXScopeSpec SS;
Mike Stump11289f42009-09-09 15:08:12 +00005191 TemplateName Template
Douglas Gregordf846d12011-03-02 18:46:51 +00005192 = getDerived().TransformTemplateName(SS, T->getTemplateName(),
5193 TL.getTemplateNameLoc());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005194 if (Template.isNull())
5195 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005196
John McCall31f82722010-11-12 08:19:04 +00005197 return getDerived().TransformTemplateSpecializationType(TLB, TL, Template);
5198}
5199
Eli Friedman0dfb8892011-10-06 23:00:33 +00005200template<typename Derived>
5201QualType TreeTransform<Derived>::TransformAtomicType(TypeLocBuilder &TLB,
5202 AtomicTypeLoc TL) {
5203 QualType ValueType = getDerived().TransformType(TLB, TL.getValueLoc());
5204 if (ValueType.isNull())
5205 return QualType();
5206
5207 QualType Result = TL.getType();
5208 if (getDerived().AlwaysRebuild() ||
5209 ValueType != TL.getValueLoc().getType()) {
5210 Result = getDerived().RebuildAtomicType(ValueType, TL.getKWLoc());
5211 if (Result.isNull())
5212 return QualType();
5213 }
5214
5215 AtomicTypeLoc NewTL = TLB.push<AtomicTypeLoc>(Result);
5216 NewTL.setKWLoc(TL.getKWLoc());
5217 NewTL.setLParenLoc(TL.getLParenLoc());
5218 NewTL.setRParenLoc(TL.getRParenLoc());
5219
5220 return Result;
5221}
5222
Chad Rosier1dcde962012-08-08 18:46:20 +00005223 /// \brief Simple iterator that traverses the template arguments in a
Douglas Gregorfe921a72010-12-20 23:36:19 +00005224 /// container that provides a \c getArgLoc() member function.
5225 ///
5226 /// This iterator is intended to be used with the iterator form of
5227 /// \c TreeTransform<Derived>::TransformTemplateArguments().
5228 template<typename ArgLocContainer>
5229 class TemplateArgumentLocContainerIterator {
5230 ArgLocContainer *Container;
5231 unsigned Index;
Chad Rosier1dcde962012-08-08 18:46:20 +00005232
Douglas Gregorfe921a72010-12-20 23:36:19 +00005233 public:
5234 typedef TemplateArgumentLoc value_type;
5235 typedef TemplateArgumentLoc reference;
5236 typedef int difference_type;
5237 typedef std::input_iterator_tag iterator_category;
Chad Rosier1dcde962012-08-08 18:46:20 +00005238
Douglas Gregorfe921a72010-12-20 23:36:19 +00005239 class pointer {
5240 TemplateArgumentLoc Arg;
Chad Rosier1dcde962012-08-08 18:46:20 +00005241
Douglas Gregorfe921a72010-12-20 23:36:19 +00005242 public:
5243 explicit pointer(TemplateArgumentLoc Arg) : Arg(Arg) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005244
Douglas Gregorfe921a72010-12-20 23:36:19 +00005245 const TemplateArgumentLoc *operator->() const {
5246 return &Arg;
5247 }
5248 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005249
5250
Angel Garcia Gomez637d1e62015-10-20 13:23:58 +00005251 TemplateArgumentLocContainerIterator() {}
Chad Rosier1dcde962012-08-08 18:46:20 +00005252
Douglas Gregorfe921a72010-12-20 23:36:19 +00005253 TemplateArgumentLocContainerIterator(ArgLocContainer &Container,
5254 unsigned Index)
5255 : Container(&Container), Index(Index) { }
Chad Rosier1dcde962012-08-08 18:46:20 +00005256
Douglas Gregorfe921a72010-12-20 23:36:19 +00005257 TemplateArgumentLocContainerIterator &operator++() {
5258 ++Index;
5259 return *this;
5260 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005261
Douglas Gregorfe921a72010-12-20 23:36:19 +00005262 TemplateArgumentLocContainerIterator operator++(int) {
5263 TemplateArgumentLocContainerIterator Old(*this);
5264 ++(*this);
5265 return Old;
5266 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005267
Douglas Gregorfe921a72010-12-20 23:36:19 +00005268 TemplateArgumentLoc operator*() const {
5269 return Container->getArgLoc(Index);
5270 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005271
Douglas Gregorfe921a72010-12-20 23:36:19 +00005272 pointer operator->() const {
5273 return pointer(Container->getArgLoc(Index));
5274 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005275
Douglas Gregorfe921a72010-12-20 23:36:19 +00005276 friend bool operator==(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005277 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005278 return X.Container == Y.Container && X.Index == Y.Index;
5279 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005280
Douglas Gregorfe921a72010-12-20 23:36:19 +00005281 friend bool operator!=(const TemplateArgumentLocContainerIterator &X,
Douglas Gregor5c7aa982010-12-21 21:51:48 +00005282 const TemplateArgumentLocContainerIterator &Y) {
Douglas Gregorfe921a72010-12-20 23:36:19 +00005283 return !(X == Y);
5284 }
5285 };
Chad Rosier1dcde962012-08-08 18:46:20 +00005286
5287
John McCall31f82722010-11-12 08:19:04 +00005288template <typename Derived>
5289QualType TreeTransform<Derived>::TransformTemplateSpecializationType(
5290 TypeLocBuilder &TLB,
5291 TemplateSpecializationTypeLoc TL,
5292 TemplateName Template) {
John McCall6b51f282009-11-23 01:53:49 +00005293 TemplateArgumentListInfo NewTemplateArgs;
5294 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5295 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregorfe921a72010-12-20 23:36:19 +00005296 typedef TemplateArgumentLocContainerIterator<TemplateSpecializationTypeLoc>
5297 ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005298 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregorfe921a72010-12-20 23:36:19 +00005299 ArgIterator(TL, TL.getNumArgs()),
5300 NewTemplateArgs))
Douglas Gregor42cafa82010-12-20 17:42:22 +00005301 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005302
John McCall0ad16662009-10-29 08:12:44 +00005303 // FIXME: maybe don't rebuild if all the template arguments are the same.
5304
5305 QualType Result =
5306 getDerived().RebuildTemplateSpecializationType(Template,
5307 TL.getTemplateNameLoc(),
John McCall6b51f282009-11-23 01:53:49 +00005308 NewTemplateArgs);
John McCall0ad16662009-10-29 08:12:44 +00005309
5310 if (!Result.isNull()) {
Richard Smith3f1b5d02011-05-05 21:57:07 +00005311 // Specializations of template template parameters are represented as
5312 // TemplateSpecializationTypes, and substitution of type alias templates
5313 // within a dependent context can transform them into
5314 // DependentTemplateSpecializationTypes.
5315 if (isa<DependentTemplateSpecializationType>(Result)) {
5316 DependentTemplateSpecializationTypeLoc NewTL
5317 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005318 NewTL.setElaboratedKeywordLoc(SourceLocation());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005319 NewTL.setQualifierLoc(NestedNameSpecifierLoc());
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005320 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005321 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Richard Smith3f1b5d02011-05-05 21:57:07 +00005322 NewTL.setLAngleLoc(TL.getLAngleLoc());
5323 NewTL.setRAngleLoc(TL.getRAngleLoc());
5324 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5325 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5326 return Result;
5327 }
5328
John McCall0ad16662009-10-29 08:12:44 +00005329 TemplateSpecializationTypeLoc NewTL
5330 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005331 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
John McCall0ad16662009-10-29 08:12:44 +00005332 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
5333 NewTL.setLAngleLoc(TL.getLAngleLoc());
5334 NewTL.setRAngleLoc(TL.getRAngleLoc());
5335 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5336 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
Douglas Gregord6ff3322009-08-04 16:50:30 +00005337 }
Mike Stump11289f42009-09-09 15:08:12 +00005338
John McCall0ad16662009-10-29 08:12:44 +00005339 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005340}
Mike Stump11289f42009-09-09 15:08:12 +00005341
Douglas Gregor5a064722011-02-28 17:23:35 +00005342template <typename Derived>
5343QualType TreeTransform<Derived>::TransformDependentTemplateSpecializationType(
5344 TypeLocBuilder &TLB,
5345 DependentTemplateSpecializationTypeLoc TL,
Douglas Gregor23648d72011-03-04 18:53:13 +00005346 TemplateName Template,
5347 CXXScopeSpec &SS) {
Douglas Gregor5a064722011-02-28 17:23:35 +00005348 TemplateArgumentListInfo NewTemplateArgs;
5349 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5350 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
5351 typedef TemplateArgumentLocContainerIterator<
5352 DependentTemplateSpecializationTypeLoc> ArgIterator;
Chad Rosier1dcde962012-08-08 18:46:20 +00005353 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
Douglas Gregor5a064722011-02-28 17:23:35 +00005354 ArgIterator(TL, TL.getNumArgs()),
5355 NewTemplateArgs))
5356 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005357
Douglas Gregor5a064722011-02-28 17:23:35 +00005358 // FIXME: maybe don't rebuild if all the template arguments are the same.
Chad Rosier1dcde962012-08-08 18:46:20 +00005359
Douglas Gregor5a064722011-02-28 17:23:35 +00005360 if (DependentTemplateName *DTN = Template.getAsDependentTemplateName()) {
5361 QualType Result
5362 = getSema().Context.getDependentTemplateSpecializationType(
5363 TL.getTypePtr()->getKeyword(),
5364 DTN->getQualifier(),
5365 DTN->getIdentifier(),
5366 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005367
Douglas Gregor5a064722011-02-28 17:23:35 +00005368 DependentTemplateSpecializationTypeLoc NewTL
5369 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005370 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005371 NewTL.setQualifierLoc(SS.getWithLocInContext(SemaRef.Context));
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005372 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005373 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005374 NewTL.setLAngleLoc(TL.getLAngleLoc());
5375 NewTL.setRAngleLoc(TL.getRAngleLoc());
5376 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5377 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5378 return Result;
5379 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005380
5381 QualType Result
Douglas Gregor5a064722011-02-28 17:23:35 +00005382 = getDerived().RebuildTemplateSpecializationType(Template,
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005383 TL.getTemplateNameLoc(),
Douglas Gregor5a064722011-02-28 17:23:35 +00005384 NewTemplateArgs);
Chad Rosier1dcde962012-08-08 18:46:20 +00005385
Douglas Gregor5a064722011-02-28 17:23:35 +00005386 if (!Result.isNull()) {
5387 /// FIXME: Wrap this in an elaborated-type-specifier?
5388 TemplateSpecializationTypeLoc NewTL
5389 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005390 NewTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005391 NewTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor5a064722011-02-28 17:23:35 +00005392 NewTL.setLAngleLoc(TL.getLAngleLoc());
5393 NewTL.setRAngleLoc(TL.getRAngleLoc());
5394 for (unsigned i = 0, e = NewTemplateArgs.size(); i != e; ++i)
5395 NewTL.setArgLocInfo(i, NewTemplateArgs[i].getLocInfo());
5396 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005397
Douglas Gregor5a064722011-02-28 17:23:35 +00005398 return Result;
5399}
5400
Mike Stump11289f42009-09-09 15:08:12 +00005401template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005402QualType
Abramo Bagnara6150c882010-05-11 21:36:43 +00005403TreeTransform<Derived>::TransformElaboratedType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005404 ElaboratedTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005405 const ElaboratedType *T = TL.getTypePtr();
Abramo Bagnara6150c882010-05-11 21:36:43 +00005406
Douglas Gregor844cb502011-03-01 18:12:44 +00005407 NestedNameSpecifierLoc QualifierLoc;
Abramo Bagnara6150c882010-05-11 21:36:43 +00005408 // NOTE: the qualifier in an ElaboratedType is optional.
Douglas Gregor844cb502011-03-01 18:12:44 +00005409 if (TL.getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005410 QualifierLoc
Douglas Gregor844cb502011-03-01 18:12:44 +00005411 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5412 if (!QualifierLoc)
Abramo Bagnara6150c882010-05-11 21:36:43 +00005413 return QualType();
5414 }
Mike Stump11289f42009-09-09 15:08:12 +00005415
John McCall31f82722010-11-12 08:19:04 +00005416 QualType NamedT = getDerived().TransformType(TLB, TL.getNamedTypeLoc());
5417 if (NamedT.isNull())
5418 return QualType();
Daniel Dunbar4707cef2010-05-14 16:34:09 +00005419
Richard Smith3f1b5d02011-05-05 21:57:07 +00005420 // C++0x [dcl.type.elab]p2:
5421 // If the identifier resolves to a typedef-name or the simple-template-id
5422 // resolves to an alias template specialization, the
5423 // elaborated-type-specifier is ill-formed.
Richard Smith0c4a34b2011-05-14 15:04:18 +00005424 if (T->getKeyword() != ETK_None && T->getKeyword() != ETK_Typename) {
5425 if (const TemplateSpecializationType *TST =
5426 NamedT->getAs<TemplateSpecializationType>()) {
5427 TemplateName Template = TST->getTemplateName();
Nico Weberc153d242014-07-28 00:02:09 +00005428 if (TypeAliasTemplateDecl *TAT = dyn_cast_or_null<TypeAliasTemplateDecl>(
5429 Template.getAsTemplateDecl())) {
Richard Smith0c4a34b2011-05-14 15:04:18 +00005430 SemaRef.Diag(TL.getNamedTypeLoc().getBeginLoc(),
5431 diag::err_tag_reference_non_tag) << 4;
5432 SemaRef.Diag(TAT->getLocation(), diag::note_declared_at);
5433 }
Richard Smith3f1b5d02011-05-05 21:57:07 +00005434 }
5435 }
5436
John McCall550e0c22009-10-21 00:40:46 +00005437 QualType Result = TL.getType();
5438 if (getDerived().AlwaysRebuild() ||
Douglas Gregor844cb502011-03-01 18:12:44 +00005439 QualifierLoc != TL.getQualifierLoc() ||
Abramo Bagnarad7548482010-05-19 21:37:53 +00005440 NamedT != T->getNamedType()) {
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005441 Result = getDerived().RebuildElaboratedType(TL.getElaboratedKeywordLoc(),
Chad Rosier1dcde962012-08-08 18:46:20 +00005442 T->getKeyword(),
Douglas Gregor844cb502011-03-01 18:12:44 +00005443 QualifierLoc, NamedT);
John McCall550e0c22009-10-21 00:40:46 +00005444 if (Result.isNull())
5445 return QualType();
5446 }
Douglas Gregord6ff3322009-08-04 16:50:30 +00005447
Abramo Bagnara6150c882010-05-11 21:36:43 +00005448 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005449 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005450 NewTL.setQualifierLoc(QualifierLoc);
John McCall550e0c22009-10-21 00:40:46 +00005451 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005452}
Mike Stump11289f42009-09-09 15:08:12 +00005453
5454template<typename Derived>
John McCall81904512011-01-06 01:58:22 +00005455QualType TreeTransform<Derived>::TransformAttributedType(
5456 TypeLocBuilder &TLB,
5457 AttributedTypeLoc TL) {
5458 const AttributedType *oldType = TL.getTypePtr();
5459 QualType modifiedType = getDerived().TransformType(TLB, TL.getModifiedLoc());
5460 if (modifiedType.isNull())
5461 return QualType();
5462
5463 QualType result = TL.getType();
5464
5465 // FIXME: dependent operand expressions?
5466 if (getDerived().AlwaysRebuild() ||
5467 modifiedType != oldType->getModifiedType()) {
5468 // TODO: this is really lame; we should really be rebuilding the
5469 // equivalent type from first principles.
5470 QualType equivalentType
5471 = getDerived().TransformType(oldType->getEquivalentType());
5472 if (equivalentType.isNull())
5473 return QualType();
Douglas Gregor261a89b2015-06-19 17:51:05 +00005474
5475 // Check whether we can add nullability; it is only represented as
5476 // type sugar, and therefore cannot be diagnosed in any other way.
5477 if (auto nullability = oldType->getImmediateNullability()) {
5478 if (!modifiedType->canHaveNullability()) {
5479 SemaRef.Diag(TL.getAttrNameLoc(), diag::err_nullability_nonpointer)
Douglas Gregoraea7afd2015-06-24 22:02:08 +00005480 << DiagNullabilityKind(*nullability, false) << modifiedType;
Douglas Gregor261a89b2015-06-19 17:51:05 +00005481 return QualType();
5482 }
5483 }
5484
John McCall81904512011-01-06 01:58:22 +00005485 result = SemaRef.Context.getAttributedType(oldType->getAttrKind(),
5486 modifiedType,
5487 equivalentType);
5488 }
5489
5490 AttributedTypeLoc newTL = TLB.push<AttributedTypeLoc>(result);
5491 newTL.setAttrNameLoc(TL.getAttrNameLoc());
5492 if (TL.hasAttrOperand())
5493 newTL.setAttrOperandParensRange(TL.getAttrOperandParensRange());
5494 if (TL.hasAttrExprOperand())
5495 newTL.setAttrExprOperand(TL.getAttrExprOperand());
5496 else if (TL.hasAttrEnumOperand())
5497 newTL.setAttrEnumOperandLoc(TL.getAttrEnumOperandLoc());
5498
5499 return result;
5500}
5501
5502template<typename Derived>
Abramo Bagnara924a8f32010-12-10 16:29:40 +00005503QualType
5504TreeTransform<Derived>::TransformParenType(TypeLocBuilder &TLB,
5505 ParenTypeLoc TL) {
5506 QualType Inner = getDerived().TransformType(TLB, TL.getInnerLoc());
5507 if (Inner.isNull())
5508 return QualType();
5509
5510 QualType Result = TL.getType();
5511 if (getDerived().AlwaysRebuild() ||
5512 Inner != TL.getInnerLoc().getType()) {
5513 Result = getDerived().RebuildParenType(Inner);
5514 if (Result.isNull())
5515 return QualType();
5516 }
5517
5518 ParenTypeLoc NewTL = TLB.push<ParenTypeLoc>(Result);
5519 NewTL.setLParenLoc(TL.getLParenLoc());
5520 NewTL.setRParenLoc(TL.getRParenLoc());
5521 return Result;
5522}
5523
5524template<typename Derived>
Douglas Gregorc1d2d8a2010-03-31 17:34:00 +00005525QualType TreeTransform<Derived>::TransformDependentNameType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005526 DependentNameTypeLoc TL) {
John McCall424cec92011-01-19 06:33:43 +00005527 const DependentNameType *T = TL.getTypePtr();
John McCall0ad16662009-10-29 08:12:44 +00005528
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005529 NestedNameSpecifierLoc QualifierLoc
5530 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5531 if (!QualifierLoc)
Douglas Gregord6ff3322009-08-04 16:50:30 +00005532 return QualType();
Mike Stump11289f42009-09-09 15:08:12 +00005533
John McCallc392f372010-06-11 00:33:02 +00005534 QualType Result
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005535 = getDerived().RebuildDependentNameType(T->getKeyword(),
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005536 TL.getElaboratedKeywordLoc(),
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005537 QualifierLoc,
5538 T->getIdentifier(),
John McCallc392f372010-06-11 00:33:02 +00005539 TL.getNameLoc());
John McCall550e0c22009-10-21 00:40:46 +00005540 if (Result.isNull())
5541 return QualType();
Douglas Gregord6ff3322009-08-04 16:50:30 +00005542
Abramo Bagnarad7548482010-05-19 21:37:53 +00005543 if (const ElaboratedType* ElabT = Result->getAs<ElaboratedType>()) {
5544 QualType NamedT = ElabT->getNamedType();
John McCallc392f372010-06-11 00:33:02 +00005545 TLB.pushTypeSpec(NamedT).setNameLoc(TL.getNameLoc());
5546
Abramo Bagnarad7548482010-05-19 21:37:53 +00005547 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005548 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor844cb502011-03-01 18:12:44 +00005549 NewTL.setQualifierLoc(QualifierLoc);
John McCallc392f372010-06-11 00:33:02 +00005550 } else {
Abramo Bagnarad7548482010-05-19 21:37:53 +00005551 DependentNameTypeLoc NewTL = TLB.push<DependentNameTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005552 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor3d0da5f2011-03-01 01:34:45 +00005553 NewTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarad7548482010-05-19 21:37:53 +00005554 NewTL.setNameLoc(TL.getNameLoc());
5555 }
John McCall550e0c22009-10-21 00:40:46 +00005556 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005557}
Mike Stump11289f42009-09-09 15:08:12 +00005558
Douglas Gregord6ff3322009-08-04 16:50:30 +00005559template<typename Derived>
John McCallc392f372010-06-11 00:33:02 +00005560QualType TreeTransform<Derived>::
5561 TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005562 DependentTemplateSpecializationTypeLoc TL) {
Douglas Gregora7a795b2011-03-01 20:11:18 +00005563 NestedNameSpecifierLoc QualifierLoc;
5564 if (TL.getQualifierLoc()) {
5565 QualifierLoc
5566 = getDerived().TransformNestedNameSpecifierLoc(TL.getQualifierLoc());
5567 if (!QualifierLoc)
Douglas Gregor5a064722011-02-28 17:23:35 +00005568 return QualType();
5569 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005570
John McCall31f82722010-11-12 08:19:04 +00005571 return getDerived()
Douglas Gregora7a795b2011-03-01 20:11:18 +00005572 .TransformDependentTemplateSpecializationType(TLB, TL, QualifierLoc);
John McCall31f82722010-11-12 08:19:04 +00005573}
5574
5575template<typename Derived>
5576QualType TreeTransform<Derived>::
Douglas Gregora7a795b2011-03-01 20:11:18 +00005577TransformDependentTemplateSpecializationType(TypeLocBuilder &TLB,
5578 DependentTemplateSpecializationTypeLoc TL,
5579 NestedNameSpecifierLoc QualifierLoc) {
5580 const DependentTemplateSpecializationType *T = TL.getTypePtr();
Chad Rosier1dcde962012-08-08 18:46:20 +00005581
Douglas Gregora7a795b2011-03-01 20:11:18 +00005582 TemplateArgumentListInfo NewTemplateArgs;
5583 NewTemplateArgs.setLAngleLoc(TL.getLAngleLoc());
5584 NewTemplateArgs.setRAngleLoc(TL.getRAngleLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00005585
Douglas Gregora7a795b2011-03-01 20:11:18 +00005586 typedef TemplateArgumentLocContainerIterator<
5587 DependentTemplateSpecializationTypeLoc> ArgIterator;
5588 if (getDerived().TransformTemplateArguments(ArgIterator(TL, 0),
5589 ArgIterator(TL, TL.getNumArgs()),
5590 NewTemplateArgs))
5591 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005592
Douglas Gregora7a795b2011-03-01 20:11:18 +00005593 QualType Result
5594 = getDerived().RebuildDependentTemplateSpecializationType(T->getKeyword(),
5595 QualifierLoc,
5596 T->getIdentifier(),
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005597 TL.getTemplateNameLoc(),
Douglas Gregora7a795b2011-03-01 20:11:18 +00005598 NewTemplateArgs);
5599 if (Result.isNull())
5600 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005601
Douglas Gregora7a795b2011-03-01 20:11:18 +00005602 if (const ElaboratedType *ElabT = dyn_cast<ElaboratedType>(Result)) {
5603 QualType NamedT = ElabT->getNamedType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005604
Douglas Gregora7a795b2011-03-01 20:11:18 +00005605 // Copy information relevant to the template specialization.
5606 TemplateSpecializationTypeLoc NamedTL
Douglas Gregor43f788f2011-03-07 02:33:33 +00005607 = TLB.push<TemplateSpecializationTypeLoc>(NamedT);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005608 NamedTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005609 NamedTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005610 NamedTL.setLAngleLoc(TL.getLAngleLoc());
5611 NamedTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005612 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005613 NamedTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Chad Rosier1dcde962012-08-08 18:46:20 +00005614
Douglas Gregora7a795b2011-03-01 20:11:18 +00005615 // Copy information relevant to the elaborated type.
5616 ElaboratedTypeLoc NewTL = TLB.push<ElaboratedTypeLoc>(Result);
Abramo Bagnara9033e2b2012-02-06 19:09:27 +00005617 NewTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005618 NewTL.setQualifierLoc(QualifierLoc);
Douglas Gregor43f788f2011-03-07 02:33:33 +00005619 } else if (isa<DependentTemplateSpecializationType>(Result)) {
5620 DependentTemplateSpecializationTypeLoc SpecTL
5621 = TLB.push<DependentTemplateSpecializationTypeLoc>(Result);
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005622 SpecTL.setElaboratedKeywordLoc(TL.getElaboratedKeywordLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005623 SpecTL.setQualifierLoc(QualifierLoc);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005624 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005625 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005626 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5627 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005628 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005629 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005630 } else {
Douglas Gregor43f788f2011-03-07 02:33:33 +00005631 TemplateSpecializationTypeLoc SpecTL
5632 = TLB.push<TemplateSpecializationTypeLoc>(Result);
Abramo Bagnarae0a70b22012-02-06 22:45:07 +00005633 SpecTL.setTemplateKeywordLoc(TL.getTemplateKeywordLoc());
Abramo Bagnara48c05be2012-02-06 14:41:24 +00005634 SpecTL.setTemplateNameLoc(TL.getTemplateNameLoc());
Douglas Gregor43f788f2011-03-07 02:33:33 +00005635 SpecTL.setLAngleLoc(TL.getLAngleLoc());
5636 SpecTL.setRAngleLoc(TL.getRAngleLoc());
Douglas Gregor11ddf132011-03-07 15:13:34 +00005637 for (unsigned I = 0, E = NewTemplateArgs.size(); I != E; ++I)
Douglas Gregor43f788f2011-03-07 02:33:33 +00005638 SpecTL.setArgLocInfo(I, NewTemplateArgs[I].getLocInfo());
Douglas Gregora7a795b2011-03-01 20:11:18 +00005639 }
5640 return Result;
5641}
5642
5643template<typename Derived>
Douglas Gregord2fa7662010-12-20 02:24:11 +00005644QualType TreeTransform<Derived>::TransformPackExpansionType(TypeLocBuilder &TLB,
5645 PackExpansionTypeLoc TL) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005646 QualType Pattern
5647 = getDerived().TransformType(TLB, TL.getPatternLoc());
Douglas Gregor822d0302011-01-12 17:07:58 +00005648 if (Pattern.isNull())
5649 return QualType();
Chad Rosier1dcde962012-08-08 18:46:20 +00005650
5651 QualType Result = TL.getType();
Douglas Gregor822d0302011-01-12 17:07:58 +00005652 if (getDerived().AlwaysRebuild() ||
5653 Pattern != TL.getPatternLoc().getType()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00005654 Result = getDerived().RebuildPackExpansionType(Pattern,
Douglas Gregor822d0302011-01-12 17:07:58 +00005655 TL.getPatternLoc().getSourceRange(),
Douglas Gregor0dca5fd2011-01-14 17:04:44 +00005656 TL.getEllipsisLoc(),
5657 TL.getTypePtr()->getNumExpansions());
Douglas Gregor822d0302011-01-12 17:07:58 +00005658 if (Result.isNull())
5659 return QualType();
5660 }
Chad Rosier1dcde962012-08-08 18:46:20 +00005661
Douglas Gregor822d0302011-01-12 17:07:58 +00005662 PackExpansionTypeLoc NewT = TLB.push<PackExpansionTypeLoc>(Result);
5663 NewT.setEllipsisLoc(TL.getEllipsisLoc());
5664 return Result;
Douglas Gregord2fa7662010-12-20 02:24:11 +00005665}
5666
5667template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005668QualType
5669TreeTransform<Derived>::TransformObjCInterfaceType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005670 ObjCInterfaceTypeLoc TL) {
Douglas Gregor21515a92010-04-22 17:28:13 +00005671 // ObjCInterfaceType is never dependent.
John McCall8b07ec22010-05-15 11:32:37 +00005672 TLB.pushFullCopy(TL);
5673 return TL.getType();
5674}
5675
5676template<typename Derived>
5677QualType
5678TreeTransform<Derived>::TransformObjCObjectType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005679 ObjCObjectTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005680 // Transform base type.
5681 QualType BaseType = getDerived().TransformType(TLB, TL.getBaseLoc());
5682 if (BaseType.isNull())
5683 return QualType();
5684
5685 bool AnyChanged = BaseType != TL.getBaseLoc().getType();
5686
5687 // Transform type arguments.
5688 SmallVector<TypeSourceInfo *, 4> NewTypeArgInfos;
5689 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i) {
5690 TypeSourceInfo *TypeArgInfo = TL.getTypeArgTInfo(i);
5691 TypeLoc TypeArgLoc = TypeArgInfo->getTypeLoc();
5692 QualType TypeArg = TypeArgInfo->getType();
5693 if (auto PackExpansionLoc = TypeArgLoc.getAs<PackExpansionTypeLoc>()) {
5694 AnyChanged = true;
5695
5696 // We have a pack expansion. Instantiate it.
5697 const auto *PackExpansion = PackExpansionLoc.getType()
5698 ->castAs<PackExpansionType>();
5699 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
5700 SemaRef.collectUnexpandedParameterPacks(PackExpansion->getPattern(),
5701 Unexpanded);
5702 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
5703
5704 // Determine whether the set of unexpanded parameter packs can
5705 // and should be expanded.
5706 TypeLoc PatternLoc = PackExpansionLoc.getPatternLoc();
5707 bool Expand = false;
5708 bool RetainExpansion = false;
5709 Optional<unsigned> NumExpansions = PackExpansion->getNumExpansions();
5710 if (getDerived().TryExpandParameterPacks(
5711 PackExpansionLoc.getEllipsisLoc(), PatternLoc.getSourceRange(),
5712 Unexpanded, Expand, RetainExpansion, NumExpansions))
5713 return QualType();
5714
5715 if (!Expand) {
5716 // We can't expand this pack expansion into separate arguments yet;
5717 // just substitute into the pattern and create a new pack expansion
5718 // type.
5719 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
5720
5721 TypeLocBuilder TypeArgBuilder;
5722 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5723 QualType NewPatternType = getDerived().TransformType(TypeArgBuilder,
5724 PatternLoc);
5725 if (NewPatternType.isNull())
5726 return QualType();
5727
5728 QualType NewExpansionType = SemaRef.Context.getPackExpansionType(
5729 NewPatternType, NumExpansions);
5730 auto NewExpansionLoc = TLB.push<PackExpansionTypeLoc>(NewExpansionType);
5731 NewExpansionLoc.setEllipsisLoc(PackExpansionLoc.getEllipsisLoc());
5732 NewTypeArgInfos.push_back(
5733 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewExpansionType));
5734 continue;
5735 }
5736
5737 // Substitute into the pack expansion pattern for each slice of the
5738 // pack.
5739 for (unsigned ArgIdx = 0; ArgIdx != *NumExpansions; ++ArgIdx) {
5740 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), ArgIdx);
5741
5742 TypeLocBuilder TypeArgBuilder;
5743 TypeArgBuilder.reserve(PatternLoc.getFullDataSize());
5744
5745 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder,
5746 PatternLoc);
5747 if (NewTypeArg.isNull())
5748 return QualType();
5749
5750 NewTypeArgInfos.push_back(
5751 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5752 }
5753
5754 continue;
5755 }
5756
5757 TypeLocBuilder TypeArgBuilder;
5758 TypeArgBuilder.reserve(TypeArgLoc.getFullDataSize());
5759 QualType NewTypeArg = getDerived().TransformType(TypeArgBuilder, TypeArgLoc);
5760 if (NewTypeArg.isNull())
5761 return QualType();
5762
5763 // If nothing changed, just keep the old TypeSourceInfo.
5764 if (NewTypeArg == TypeArg) {
5765 NewTypeArgInfos.push_back(TypeArgInfo);
5766 continue;
5767 }
5768
5769 NewTypeArgInfos.push_back(
5770 TypeArgBuilder.getTypeSourceInfo(SemaRef.Context, NewTypeArg));
5771 AnyChanged = true;
5772 }
5773
5774 QualType Result = TL.getType();
5775 if (getDerived().AlwaysRebuild() || AnyChanged) {
5776 // Rebuild the type.
5777 Result = getDerived().RebuildObjCObjectType(
5778 BaseType,
5779 TL.getLocStart(),
5780 TL.getTypeArgsLAngleLoc(),
5781 NewTypeArgInfos,
5782 TL.getTypeArgsRAngleLoc(),
5783 TL.getProtocolLAngleLoc(),
5784 llvm::makeArrayRef(TL.getTypePtr()->qual_begin(),
5785 TL.getNumProtocols()),
5786 TL.getProtocolLocs(),
5787 TL.getProtocolRAngleLoc());
5788
5789 if (Result.isNull())
5790 return QualType();
5791 }
5792
5793 ObjCObjectTypeLoc NewT = TLB.push<ObjCObjectTypeLoc>(Result);
5794 assert(TL.hasBaseTypeAsWritten() && "Can't be dependent");
5795 NewT.setHasBaseTypeAsWritten(true);
5796 NewT.setTypeArgsLAngleLoc(TL.getTypeArgsLAngleLoc());
5797 for (unsigned i = 0, n = TL.getNumTypeArgs(); i != n; ++i)
5798 NewT.setTypeArgTInfo(i, NewTypeArgInfos[i]);
5799 NewT.setTypeArgsRAngleLoc(TL.getTypeArgsRAngleLoc());
5800 NewT.setProtocolLAngleLoc(TL.getProtocolLAngleLoc());
5801 for (unsigned i = 0, n = TL.getNumProtocols(); i != n; ++i)
5802 NewT.setProtocolLoc(i, TL.getProtocolLoc(i));
5803 NewT.setProtocolRAngleLoc(TL.getProtocolRAngleLoc());
5804 return Result;
Douglas Gregord6ff3322009-08-04 16:50:30 +00005805}
Mike Stump11289f42009-09-09 15:08:12 +00005806
5807template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +00005808QualType
5809TreeTransform<Derived>::TransformObjCObjectPointerType(TypeLocBuilder &TLB,
John McCall31f82722010-11-12 08:19:04 +00005810 ObjCObjectPointerTypeLoc TL) {
Douglas Gregor9bda6cf2015-07-07 03:58:14 +00005811 QualType PointeeType = getDerived().TransformType(TLB, TL.getPointeeLoc());
5812 if (PointeeType.isNull())
5813 return QualType();
5814
5815 QualType Result = TL.getType();
5816 if (getDerived().AlwaysRebuild() ||
5817 PointeeType != TL.getPointeeLoc().getType()) {
5818 Result = getDerived().RebuildObjCObjectPointerType(PointeeType,
5819 TL.getStarLoc());
5820 if (Result.isNull())
5821 return QualType();
5822 }
5823
5824 ObjCObjectPointerTypeLoc NewT = TLB.push<ObjCObjectPointerTypeLoc>(Result);
5825 NewT.setStarLoc(TL.getStarLoc());
5826 return Result;
Argyrios Kyrtzidisa7a36df2009-09-29 19:42:55 +00005827}
5828
Douglas Gregord6ff3322009-08-04 16:50:30 +00005829//===----------------------------------------------------------------------===//
Douglas Gregorebe10102009-08-20 07:17:43 +00005830// Statement transformation
5831//===----------------------------------------------------------------------===//
5832template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005833StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005834TreeTransform<Derived>::TransformNullStmt(NullStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005835 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005836}
5837
5838template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005839StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00005840TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S) {
5841 return getDerived().TransformCompoundStmt(S, false);
5842}
5843
5844template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005845StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005846TreeTransform<Derived>::TransformCompoundStmt(CompoundStmt *S,
Douglas Gregorebe10102009-08-20 07:17:43 +00005847 bool IsStmtExpr) {
Dmitri Gribenko800ddf32012-02-14 22:14:32 +00005848 Sema::CompoundScopeRAII CompoundScope(getSema());
5849
John McCall1ababa62010-08-27 19:56:05 +00005850 bool SubStmtInvalid = false;
Douglas Gregorebe10102009-08-20 07:17:43 +00005851 bool SubStmtChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00005852 SmallVector<Stmt*, 8> Statements;
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005853 for (auto *B : S->body()) {
5854 StmtResult Result = getDerived().TransformStmt(B);
John McCall1ababa62010-08-27 19:56:05 +00005855 if (Result.isInvalid()) {
5856 // Immediately fail if this was a DeclStmt, since it's very
5857 // likely that this will cause problems for future statements.
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005858 if (isa<DeclStmt>(B))
John McCall1ababa62010-08-27 19:56:05 +00005859 return StmtError();
5860
5861 // Otherwise, just keep processing substatements and fail later.
5862 SubStmtInvalid = true;
5863 continue;
5864 }
Mike Stump11289f42009-09-09 15:08:12 +00005865
Aaron Ballmanc7e4e212014-03-17 14:19:37 +00005866 SubStmtChanged = SubStmtChanged || Result.get() != B;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00005867 Statements.push_back(Result.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00005868 }
Mike Stump11289f42009-09-09 15:08:12 +00005869
John McCall1ababa62010-08-27 19:56:05 +00005870 if (SubStmtInvalid)
5871 return StmtError();
5872
Douglas Gregorebe10102009-08-20 07:17:43 +00005873 if (!getDerived().AlwaysRebuild() &&
5874 !SubStmtChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00005875 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00005876
5877 return getDerived().RebuildCompoundStmt(S->getLBracLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00005878 Statements,
Douglas Gregorebe10102009-08-20 07:17:43 +00005879 S->getRBracLoc(),
5880 IsStmtExpr);
5881}
Mike Stump11289f42009-09-09 15:08:12 +00005882
Douglas Gregorebe10102009-08-20 07:17:43 +00005883template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005884StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005885TreeTransform<Derived>::TransformCaseStmt(CaseStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005886 ExprResult LHS, RHS;
Eli Friedman06577382009-11-19 03:14:00 +00005887 {
Eli Friedman1f4f9dd2012-01-18 02:54:10 +00005888 EnterExpressionEvaluationContext Unevaluated(SemaRef,
5889 Sema::ConstantEvaluated);
Mike Stump11289f42009-09-09 15:08:12 +00005890
Eli Friedman06577382009-11-19 03:14:00 +00005891 // Transform the left-hand case value.
5892 LHS = getDerived().TransformExpr(S->getLHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005893 LHS = SemaRef.ActOnConstantExpression(LHS);
Eli Friedman06577382009-11-19 03:14:00 +00005894 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005895 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005896
Eli Friedman06577382009-11-19 03:14:00 +00005897 // Transform the right-hand case value (for the GNU case-range extension).
5898 RHS = getDerived().TransformExpr(S->getRHS());
Eli Friedmanc6237c62012-02-29 03:16:56 +00005899 RHS = SemaRef.ActOnConstantExpression(RHS);
Eli Friedman06577382009-11-19 03:14:00 +00005900 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005901 return StmtError();
Eli Friedman06577382009-11-19 03:14:00 +00005902 }
Mike Stump11289f42009-09-09 15:08:12 +00005903
Douglas Gregorebe10102009-08-20 07:17:43 +00005904 // Build the case statement.
5905 // Case statements are always rebuilt so that they will attached to their
5906 // transformed switch statement.
John McCalldadc5752010-08-24 06:29:42 +00005907 StmtResult Case = getDerived().RebuildCaseStmt(S->getCaseLoc(),
John McCallb268a282010-08-23 23:25:46 +00005908 LHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005909 S->getEllipsisLoc(),
John McCallb268a282010-08-23 23:25:46 +00005910 RHS.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00005911 S->getColonLoc());
5912 if (Case.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005913 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005914
Douglas Gregorebe10102009-08-20 07:17:43 +00005915 // Transform the statement following the case
John McCalldadc5752010-08-24 06:29:42 +00005916 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005917 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005918 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005919
Douglas Gregorebe10102009-08-20 07:17:43 +00005920 // Attach the body to the case statement
John McCallb268a282010-08-23 23:25:46 +00005921 return getDerived().RebuildCaseStmtBody(Case.get(), SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005922}
5923
5924template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005925StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005926TreeTransform<Derived>::TransformDefaultStmt(DefaultStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005927 // Transform the statement following the default case
John McCalldadc5752010-08-24 06:29:42 +00005928 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005929 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005930 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005931
Douglas Gregorebe10102009-08-20 07:17:43 +00005932 // Default statements are always rebuilt
5933 return getDerived().RebuildDefaultStmt(S->getDefaultLoc(), S->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00005934 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005935}
Mike Stump11289f42009-09-09 15:08:12 +00005936
Douglas Gregorebe10102009-08-20 07:17:43 +00005937template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00005938StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005939TreeTransform<Derived>::TransformLabelStmt(LabelStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00005940 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
Douglas Gregorebe10102009-08-20 07:17:43 +00005941 if (SubStmt.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00005942 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00005943
Chris Lattnercab02a62011-02-17 20:34:02 +00005944 Decl *LD = getDerived().TransformDecl(S->getDecl()->getLocation(),
5945 S->getDecl());
5946 if (!LD)
5947 return StmtError();
Richard Smithc202b282012-04-14 00:33:13 +00005948
5949
Douglas Gregorebe10102009-08-20 07:17:43 +00005950 // FIXME: Pass the real colon location in.
Chris Lattnerc8e630e2011-02-17 07:39:24 +00005951 return getDerived().RebuildLabelStmt(S->getIdentLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00005952 cast<LabelDecl>(LD), SourceLocation(),
5953 SubStmt.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00005954}
Mike Stump11289f42009-09-09 15:08:12 +00005955
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005956template <typename Derived>
5957const Attr *TreeTransform<Derived>::TransformAttr(const Attr *R) {
5958 if (!R)
5959 return R;
5960
5961 switch (R->getKind()) {
5962// Transform attributes with a pragma spelling by calling TransformXXXAttr.
5963#define ATTR(X)
5964#define PRAGMA_SPELLING_ATTR(X) \
5965 case attr::X: \
5966 return getDerived().Transform##X##Attr(cast<X##Attr>(R));
5967#include "clang/Basic/AttrList.inc"
5968 default:
5969 return R;
5970 }
5971}
5972
5973template <typename Derived>
5974StmtResult TreeTransform<Derived>::TransformAttributedStmt(AttributedStmt *S) {
5975 bool AttrsChanged = false;
5976 SmallVector<const Attr *, 1> Attrs;
5977
5978 // Visit attributes and keep track if any are transformed.
5979 for (const auto *I : S->getAttrs()) {
5980 const Attr *R = getDerived().TransformAttr(I);
5981 AttrsChanged |= (I != R);
5982 Attrs.push_back(R);
5983 }
5984
Richard Smithc202b282012-04-14 00:33:13 +00005985 StmtResult SubStmt = getDerived().TransformStmt(S->getSubStmt());
5986 if (SubStmt.isInvalid())
5987 return StmtError();
5988
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005989 if (SubStmt.get() == S->getSubStmt() && !AttrsChanged)
Richard Smithc202b282012-04-14 00:33:13 +00005990 return S;
5991
Tyler Nowickic724a83e2014-10-12 20:46:07 +00005992 return getDerived().RebuildAttributedStmt(S->getAttrLoc(), Attrs,
Richard Smithc202b282012-04-14 00:33:13 +00005993 SubStmt.get());
5994}
5995
5996template<typename Derived>
5997StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00005998TreeTransform<Derived>::TransformIfStmt(IfStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00005999 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006000 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006001 VarDecl *ConditionVar = nullptr;
Douglas Gregor633caca2009-11-23 23:44:04 +00006002 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006003 ConditionVar
Douglas Gregor633caca2009-11-23 23:44:04 +00006004 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006005 getDerived().TransformDefinition(
6006 S->getConditionVariable()->getLocation(),
6007 S->getConditionVariable()));
Douglas Gregor633caca2009-11-23 23:44:04 +00006008 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006009 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006010 } else {
Douglas Gregor633caca2009-11-23 23:44:04 +00006011 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006012
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006013 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006014 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006015
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006016 // Convert the condition to a boolean value.
Douglas Gregor6d319c62010-05-08 23:34:38 +00006017 if (S->getCond()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006018 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr, S->getIfLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006019 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006020 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006021 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006022
John McCallb268a282010-08-23 23:25:46 +00006023 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006024 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006025 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006026
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006027 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006028 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006029 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006030
Douglas Gregorebe10102009-08-20 07:17:43 +00006031 // Transform the "then" branch.
John McCalldadc5752010-08-24 06:29:42 +00006032 StmtResult Then = getDerived().TransformStmt(S->getThen());
Douglas Gregorebe10102009-08-20 07:17:43 +00006033 if (Then.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006034 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006035
Douglas Gregorebe10102009-08-20 07:17:43 +00006036 // Transform the "else" branch.
John McCalldadc5752010-08-24 06:29:42 +00006037 StmtResult Else = getDerived().TransformStmt(S->getElse());
Douglas Gregorebe10102009-08-20 07:17:43 +00006038 if (Else.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006039 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006040
Douglas Gregorebe10102009-08-20 07:17:43 +00006041 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006042 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006043 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006044 Then.get() == S->getThen() &&
6045 Else.get() == S->getElse())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006046 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006047
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006048 return getDerived().RebuildIfStmt(S->getIfLoc(), FullCond, ConditionVar,
Argyrios Kyrtzidisde2bdf62010-11-20 02:04:01 +00006049 Then.get(),
John McCallb268a282010-08-23 23:25:46 +00006050 S->getElseLoc(), Else.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006051}
6052
6053template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006054StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006055TreeTransform<Derived>::TransformSwitchStmt(SwitchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006056 // Transform the condition.
John McCalldadc5752010-08-24 06:29:42 +00006057 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006058 VarDecl *ConditionVar = nullptr;
Douglas Gregordcf19622009-11-24 17:07:59 +00006059 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006060 ConditionVar
Douglas Gregordcf19622009-11-24 17:07:59 +00006061 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006062 getDerived().TransformDefinition(
6063 S->getConditionVariable()->getLocation(),
6064 S->getConditionVariable()));
Douglas Gregordcf19622009-11-24 17:07:59 +00006065 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006066 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006067 } else {
Douglas Gregordcf19622009-11-24 17:07:59 +00006068 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006069
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006070 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006071 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006072 }
Mike Stump11289f42009-09-09 15:08:12 +00006073
Douglas Gregorebe10102009-08-20 07:17:43 +00006074 // Rebuild the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006075 StmtResult Switch
John McCallb268a282010-08-23 23:25:46 +00006076 = getDerived().RebuildSwitchStmtStart(S->getSwitchLoc(), Cond.get(),
Douglas Gregore60e41a2010-05-06 17:25:47 +00006077 ConditionVar);
Douglas Gregorebe10102009-08-20 07:17:43 +00006078 if (Switch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006079 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006080
Douglas Gregorebe10102009-08-20 07:17:43 +00006081 // Transform the body of the switch statement.
John McCalldadc5752010-08-24 06:29:42 +00006082 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006083 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006084 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006085
Douglas Gregorebe10102009-08-20 07:17:43 +00006086 // Complete the switch statement.
John McCallb268a282010-08-23 23:25:46 +00006087 return getDerived().RebuildSwitchStmtBody(S->getSwitchLoc(), Switch.get(),
6088 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006089}
Mike Stump11289f42009-09-09 15:08:12 +00006090
Douglas Gregorebe10102009-08-20 07:17:43 +00006091template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006092StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006093TreeTransform<Derived>::TransformWhileStmt(WhileStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006094 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006095 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006096 VarDecl *ConditionVar = nullptr;
Douglas Gregor680f8612009-11-24 21:15:44 +00006097 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006098 ConditionVar
Douglas Gregor680f8612009-11-24 21:15:44 +00006099 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006100 getDerived().TransformDefinition(
6101 S->getConditionVariable()->getLocation(),
6102 S->getConditionVariable()));
Douglas Gregor680f8612009-11-24 21:15:44 +00006103 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006104 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006105 } else {
Douglas Gregor680f8612009-11-24 21:15:44 +00006106 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006107
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006108 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006109 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006110
6111 if (S->getCond()) {
6112 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006113 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6114 S->getWhileLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006115 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006116 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006117 return StmtError();
John McCallb268a282010-08-23 23:25:46 +00006118 Cond = CondE;
Douglas Gregor6d319c62010-05-08 23:34:38 +00006119 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006120 }
Mike Stump11289f42009-09-09 15:08:12 +00006121
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006122 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006123 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006124 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006125
Douglas Gregorebe10102009-08-20 07:17:43 +00006126 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006127 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006128 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006129 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006130
Douglas Gregorebe10102009-08-20 07:17:43 +00006131 if (!getDerived().AlwaysRebuild() &&
John McCallb268a282010-08-23 23:25:46 +00006132 FullCond.get() == S->getCond() &&
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006133 ConditionVar == S->getConditionVariable() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006134 Body.get() == S->getBody())
John McCallb268a282010-08-23 23:25:46 +00006135 return Owned(S);
Mike Stump11289f42009-09-09 15:08:12 +00006136
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006137 return getDerived().RebuildWhileStmt(S->getWhileLoc(), FullCond,
John McCallb268a282010-08-23 23:25:46 +00006138 ConditionVar, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006139}
Mike Stump11289f42009-09-09 15:08:12 +00006140
Douglas Gregorebe10102009-08-20 07:17:43 +00006141template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006142StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006143TreeTransform<Derived>::TransformDoStmt(DoStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006144 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006145 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006146 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006147 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006148
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006149 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006150 ExprResult Cond = getDerived().TransformExpr(S->getCond());
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006151 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006152 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006153
Douglas Gregorebe10102009-08-20 07:17:43 +00006154 if (!getDerived().AlwaysRebuild() &&
6155 Cond.get() == S->getCond() &&
6156 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006157 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006158
John McCallb268a282010-08-23 23:25:46 +00006159 return getDerived().RebuildDoStmt(S->getDoLoc(), Body.get(), S->getWhileLoc(),
6160 /*FIXME:*/S->getWhileLoc(), Cond.get(),
Douglas Gregorebe10102009-08-20 07:17:43 +00006161 S->getRParenLoc());
6162}
Mike Stump11289f42009-09-09 15:08:12 +00006163
Douglas Gregorebe10102009-08-20 07:17:43 +00006164template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006165StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006166TreeTransform<Derived>::TransformForStmt(ForStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006167 // Transform the initialization statement
John McCalldadc5752010-08-24 06:29:42 +00006168 StmtResult Init = getDerived().TransformStmt(S->getInit());
Douglas Gregorebe10102009-08-20 07:17:43 +00006169 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006170 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006171
Douglas Gregorebe10102009-08-20 07:17:43 +00006172 // Transform the condition
John McCalldadc5752010-08-24 06:29:42 +00006173 ExprResult Cond;
Craig Topperc3ec1492014-05-26 06:22:03 +00006174 VarDecl *ConditionVar = nullptr;
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006175 if (S->getConditionVariable()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006176 ConditionVar
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006177 = cast_or_null<VarDecl>(
Douglas Gregor25289362010-03-01 17:25:41 +00006178 getDerived().TransformDefinition(
6179 S->getConditionVariable()->getLocation(),
6180 S->getConditionVariable()));
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006181 if (!ConditionVar)
John McCallfaf5fb42010-08-26 23:41:50 +00006182 return StmtError();
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006183 } else {
6184 Cond = getDerived().TransformExpr(S->getCond());
Chad Rosier1dcde962012-08-08 18:46:20 +00006185
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006186 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006187 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006188
6189 if (S->getCond()) {
6190 // Convert the condition to a boolean value.
Craig Topperc3ec1492014-05-26 06:22:03 +00006191 ExprResult CondE = getSema().ActOnBooleanCondition(nullptr,
6192 S->getForLoc(),
Douglas Gregor840bd6c2010-12-20 22:05:00 +00006193 Cond.get());
Douglas Gregor6d319c62010-05-08 23:34:38 +00006194 if (CondE.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006195 return StmtError();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006196
John McCallb268a282010-08-23 23:25:46 +00006197 Cond = CondE.get();
Douglas Gregor6d319c62010-05-08 23:34:38 +00006198 }
Douglas Gregor7bab5ff2009-11-25 00:27:52 +00006199 }
Mike Stump11289f42009-09-09 15:08:12 +00006200
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006201 Sema::FullExprArg FullCond(getSema().MakeFullExpr(Cond.get()));
John McCallb268a282010-08-23 23:25:46 +00006202 if (!S->getConditionVariable() && S->getCond() && !FullCond.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006203 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006204
Douglas Gregorebe10102009-08-20 07:17:43 +00006205 // Transform the increment
John McCalldadc5752010-08-24 06:29:42 +00006206 ExprResult Inc = getDerived().TransformExpr(S->getInc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006207 if (Inc.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006208 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006209
Richard Smith945f8d32013-01-14 22:39:08 +00006210 Sema::FullExprArg FullInc(getSema().MakeFullDiscardedValueExpr(Inc.get()));
John McCallb268a282010-08-23 23:25:46 +00006211 if (S->getInc() && !FullInc.get())
John McCallfaf5fb42010-08-26 23:41:50 +00006212 return StmtError();
Douglas Gregorff73a9e2010-05-08 22:20:28 +00006213
Douglas Gregorebe10102009-08-20 07:17:43 +00006214 // Transform the body
John McCalldadc5752010-08-24 06:29:42 +00006215 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorebe10102009-08-20 07:17:43 +00006216 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006217 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006218
Douglas Gregorebe10102009-08-20 07:17:43 +00006219 if (!getDerived().AlwaysRebuild() &&
6220 Init.get() == S->getInit() &&
John McCallb268a282010-08-23 23:25:46 +00006221 FullCond.get() == S->getCond() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006222 Inc.get() == S->getInc() &&
6223 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006224 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006225
Douglas Gregorebe10102009-08-20 07:17:43 +00006226 return getDerived().RebuildForStmt(S->getForLoc(), S->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006227 Init.get(), FullCond, ConditionVar,
6228 FullInc, S->getRParenLoc(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006229}
6230
6231template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006232StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006233TreeTransform<Derived>::TransformGotoStmt(GotoStmt *S) {
Chris Lattnercab02a62011-02-17 20:34:02 +00006234 Decl *LD = getDerived().TransformDecl(S->getLabel()->getLocation(),
6235 S->getLabel());
6236 if (!LD)
6237 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006238
Douglas Gregorebe10102009-08-20 07:17:43 +00006239 // Goto statements must always be rebuilt, to resolve the label.
Mike Stump11289f42009-09-09 15:08:12 +00006240 return getDerived().RebuildGotoStmt(S->getGotoLoc(), S->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00006241 cast<LabelDecl>(LD));
Douglas Gregorebe10102009-08-20 07:17:43 +00006242}
6243
6244template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006245StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006246TreeTransform<Derived>::TransformIndirectGotoStmt(IndirectGotoStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006247 ExprResult Target = getDerived().TransformExpr(S->getTarget());
Douglas Gregorebe10102009-08-20 07:17:43 +00006248 if (Target.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006249 return StmtError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006250 Target = SemaRef.MaybeCreateExprWithCleanups(Target.get());
Mike Stump11289f42009-09-09 15:08:12 +00006251
Douglas Gregorebe10102009-08-20 07:17:43 +00006252 if (!getDerived().AlwaysRebuild() &&
6253 Target.get() == S->getTarget())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006254 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006255
6256 return getDerived().RebuildIndirectGotoStmt(S->getGotoLoc(), S->getStarLoc(),
John McCallb268a282010-08-23 23:25:46 +00006257 Target.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006258}
6259
6260template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006261StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006262TreeTransform<Derived>::TransformContinueStmt(ContinueStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006263 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006264}
Mike Stump11289f42009-09-09 15:08:12 +00006265
Douglas Gregorebe10102009-08-20 07:17:43 +00006266template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006267StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006268TreeTransform<Derived>::TransformBreakStmt(BreakStmt *S) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006269 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006270}
Mike Stump11289f42009-09-09 15:08:12 +00006271
Douglas Gregorebe10102009-08-20 07:17:43 +00006272template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006273StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006274TreeTransform<Derived>::TransformReturnStmt(ReturnStmt *S) {
Richard Smith3b717522014-08-21 20:51:13 +00006275 ExprResult Result = getDerived().TransformInitializer(S->getRetValue(),
6276 /*NotCopyInit*/false);
Douglas Gregorebe10102009-08-20 07:17:43 +00006277 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006278 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006279
Mike Stump11289f42009-09-09 15:08:12 +00006280 // FIXME: We always rebuild the return statement because there is no way
Douglas Gregorebe10102009-08-20 07:17:43 +00006281 // to tell whether the return type of the function has changed.
John McCallb268a282010-08-23 23:25:46 +00006282 return getDerived().RebuildReturnStmt(S->getReturnLoc(), Result.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006283}
Mike Stump11289f42009-09-09 15:08:12 +00006284
Douglas Gregorebe10102009-08-20 07:17:43 +00006285template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006286StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006287TreeTransform<Derived>::TransformDeclStmt(DeclStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006288 bool DeclChanged = false;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006289 SmallVector<Decl *, 4> Decls;
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006290 for (auto *D : S->decls()) {
6291 Decl *Transformed = getDerived().TransformDefinition(D->getLocation(), D);
Douglas Gregorebe10102009-08-20 07:17:43 +00006292 if (!Transformed)
John McCallfaf5fb42010-08-26 23:41:50 +00006293 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006294
Aaron Ballman535bbcc2014-03-14 17:01:24 +00006295 if (Transformed != D)
Douglas Gregorebe10102009-08-20 07:17:43 +00006296 DeclChanged = true;
Mike Stump11289f42009-09-09 15:08:12 +00006297
Douglas Gregorebe10102009-08-20 07:17:43 +00006298 Decls.push_back(Transformed);
6299 }
Mike Stump11289f42009-09-09 15:08:12 +00006300
Douglas Gregorebe10102009-08-20 07:17:43 +00006301 if (!getDerived().AlwaysRebuild() && !DeclChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006302 return S;
Mike Stump11289f42009-09-09 15:08:12 +00006303
Rafael Espindolaab417692013-07-09 12:05:01 +00006304 return getDerived().RebuildDeclStmt(Decls, S->getStartLoc(), S->getEndLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006305}
Mike Stump11289f42009-09-09 15:08:12 +00006306
Douglas Gregorebe10102009-08-20 07:17:43 +00006307template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006308StmtResult
Chad Rosierde70e0e2012-08-25 00:11:56 +00006309TreeTransform<Derived>::TransformGCCAsmStmt(GCCAsmStmt *S) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006310
Benjamin Kramerf0623432012-08-23 22:51:59 +00006311 SmallVector<Expr*, 8> Constraints;
6312 SmallVector<Expr*, 8> Exprs;
Chris Lattner01cf8db2011-07-20 06:58:45 +00006313 SmallVector<IdentifierInfo *, 4> Names;
Anders Carlsson087bc132010-01-30 20:05:21 +00006314
John McCalldadc5752010-08-24 06:29:42 +00006315 ExprResult AsmString;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006316 SmallVector<Expr*, 8> Clobbers;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006317
6318 bool ExprsChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00006319
Anders Carlssonaaeef072010-01-24 05:50:09 +00006320 // Go through the outputs.
6321 for (unsigned I = 0, E = S->getNumOutputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006322 Names.push_back(S->getOutputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006323
Anders Carlssonaaeef072010-01-24 05:50:09 +00006324 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006325 Constraints.push_back(S->getOutputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006326
Anders Carlssonaaeef072010-01-24 05:50:09 +00006327 // Transform the output expr.
6328 Expr *OutputExpr = S->getOutputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006329 ExprResult Result = getDerived().TransformExpr(OutputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006330 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006331 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006332
Anders Carlssonaaeef072010-01-24 05:50:09 +00006333 ExprsChanged |= Result.get() != OutputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006334
John McCallb268a282010-08-23 23:25:46 +00006335 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006336 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006337
Anders Carlssonaaeef072010-01-24 05:50:09 +00006338 // Go through the inputs.
6339 for (unsigned I = 0, E = S->getNumInputs(); I != E; ++I) {
Anders Carlsson9a020f92010-01-30 22:25:16 +00006340 Names.push_back(S->getInputIdentifier(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006341
Anders Carlssonaaeef072010-01-24 05:50:09 +00006342 // No need to transform the constraint literal.
John McCallc3007a22010-10-26 07:05:15 +00006343 Constraints.push_back(S->getInputConstraintLiteral(I));
Chad Rosier1dcde962012-08-08 18:46:20 +00006344
Anders Carlssonaaeef072010-01-24 05:50:09 +00006345 // Transform the input expr.
6346 Expr *InputExpr = S->getInputExpr(I);
John McCalldadc5752010-08-24 06:29:42 +00006347 ExprResult Result = getDerived().TransformExpr(InputExpr);
Anders Carlssonaaeef072010-01-24 05:50:09 +00006348 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006349 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006350
Anders Carlssonaaeef072010-01-24 05:50:09 +00006351 ExprsChanged |= Result.get() != InputExpr;
Chad Rosier1dcde962012-08-08 18:46:20 +00006352
John McCallb268a282010-08-23 23:25:46 +00006353 Exprs.push_back(Result.get());
Anders Carlssonaaeef072010-01-24 05:50:09 +00006354 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006355
Anders Carlssonaaeef072010-01-24 05:50:09 +00006356 if (!getDerived().AlwaysRebuild() && !ExprsChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006357 return S;
Anders Carlssonaaeef072010-01-24 05:50:09 +00006358
6359 // Go through the clobbers.
6360 for (unsigned I = 0, E = S->getNumClobbers(); I != E; ++I)
Chad Rosierd9fb09a2012-08-27 23:28:41 +00006361 Clobbers.push_back(S->getClobberStringLiteral(I));
Anders Carlssonaaeef072010-01-24 05:50:09 +00006362
6363 // No need to transform the asm string literal.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006364 AsmString = S->getAsmString();
Chad Rosierde70e0e2012-08-25 00:11:56 +00006365 return getDerived().RebuildGCCAsmStmt(S->getAsmLoc(), S->isSimple(),
6366 S->isVolatile(), S->getNumOutputs(),
6367 S->getNumInputs(), Names.data(),
6368 Constraints, Exprs, AsmString.get(),
6369 Clobbers, S->getRParenLoc());
Douglas Gregorebe10102009-08-20 07:17:43 +00006370}
6371
Chad Rosier32503022012-06-11 20:47:18 +00006372template<typename Derived>
6373StmtResult
6374TreeTransform<Derived>::TransformMSAsmStmt(MSAsmStmt *S) {
Chad Rosier99fc3812012-08-07 00:29:06 +00006375 ArrayRef<Token> AsmToks =
6376 llvm::makeArrayRef(S->getAsmToks(), S->getNumAsmToks());
Chad Rosier3ed0bd92012-08-08 19:48:07 +00006377
John McCallf413f5e2013-05-03 00:10:13 +00006378 bool HadError = false, HadChange = false;
6379
6380 ArrayRef<Expr*> SrcExprs = S->getAllExprs();
6381 SmallVector<Expr*, 8> TransformedExprs;
6382 TransformedExprs.reserve(SrcExprs.size());
6383 for (unsigned i = 0, e = SrcExprs.size(); i != e; ++i) {
6384 ExprResult Result = getDerived().TransformExpr(SrcExprs[i]);
6385 if (!Result.isUsable()) {
6386 HadError = true;
6387 } else {
6388 HadChange |= (Result.get() != SrcExprs[i]);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006389 TransformedExprs.push_back(Result.get());
John McCallf413f5e2013-05-03 00:10:13 +00006390 }
6391 }
6392
6393 if (HadError) return StmtError();
6394 if (!HadChange && !getDerived().AlwaysRebuild())
6395 return Owned(S);
6396
Chad Rosierb6f46c12012-08-15 16:53:30 +00006397 return getDerived().RebuildMSAsmStmt(S->getAsmLoc(), S->getLBraceLoc(),
John McCallf413f5e2013-05-03 00:10:13 +00006398 AsmToks, S->getAsmString(),
6399 S->getNumOutputs(), S->getNumInputs(),
6400 S->getAllConstraints(), S->getClobbers(),
6401 TransformedExprs, S->getEndLoc());
Chad Rosier32503022012-06-11 20:47:18 +00006402}
Douglas Gregorebe10102009-08-20 07:17:43 +00006403
6404template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006405StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006406TreeTransform<Derived>::TransformObjCAtTryStmt(ObjCAtTryStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006407 // Transform the body of the @try.
John McCalldadc5752010-08-24 06:29:42 +00006408 StmtResult TryBody = getDerived().TransformStmt(S->getTryBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006409 if (TryBody.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006410 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006411
Douglas Gregor96c79492010-04-23 22:50:49 +00006412 // Transform the @catch statements (if present).
6413 bool AnyCatchChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00006414 SmallVector<Stmt*, 8> CatchStmts;
Douglas Gregor96c79492010-04-23 22:50:49 +00006415 for (unsigned I = 0, N = S->getNumCatchStmts(); I != N; ++I) {
John McCalldadc5752010-08-24 06:29:42 +00006416 StmtResult Catch = getDerived().TransformStmt(S->getCatchStmt(I));
Douglas Gregor306de2f2010-04-22 23:59:56 +00006417 if (Catch.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006418 return StmtError();
Douglas Gregor96c79492010-04-23 22:50:49 +00006419 if (Catch.get() != S->getCatchStmt(I))
6420 AnyCatchChanged = true;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006421 CatchStmts.push_back(Catch.get());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006422 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006423
Douglas Gregor306de2f2010-04-22 23:59:56 +00006424 // Transform the @finally statement (if present).
John McCalldadc5752010-08-24 06:29:42 +00006425 StmtResult Finally;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006426 if (S->getFinallyStmt()) {
6427 Finally = getDerived().TransformStmt(S->getFinallyStmt());
6428 if (Finally.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006429 return StmtError();
Douglas Gregor306de2f2010-04-22 23:59:56 +00006430 }
6431
6432 // If nothing changed, just retain this statement.
6433 if (!getDerived().AlwaysRebuild() &&
6434 TryBody.get() == S->getTryBody() &&
Douglas Gregor96c79492010-04-23 22:50:49 +00006435 !AnyCatchChanged &&
Douglas Gregor306de2f2010-04-22 23:59:56 +00006436 Finally.get() == S->getFinallyStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006437 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006438
Douglas Gregor306de2f2010-04-22 23:59:56 +00006439 // Build a new statement.
John McCallb268a282010-08-23 23:25:46 +00006440 return getDerived().RebuildObjCAtTryStmt(S->getAtTryLoc(), TryBody.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006441 CatchStmts, Finally.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006442}
Mike Stump11289f42009-09-09 15:08:12 +00006443
Douglas Gregorebe10102009-08-20 07:17:43 +00006444template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006445StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006446TreeTransform<Derived>::TransformObjCAtCatchStmt(ObjCAtCatchStmt *S) {
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006447 // Transform the @catch parameter, if there is one.
Craig Topperc3ec1492014-05-26 06:22:03 +00006448 VarDecl *Var = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006449 if (VarDecl *FromVar = S->getCatchParamDecl()) {
Craig Topperc3ec1492014-05-26 06:22:03 +00006450 TypeSourceInfo *TSInfo = nullptr;
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006451 if (FromVar->getTypeSourceInfo()) {
6452 TSInfo = getDerived().TransformType(FromVar->getTypeSourceInfo());
6453 if (!TSInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00006454 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006455 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006456
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006457 QualType T;
6458 if (TSInfo)
6459 T = TSInfo->getType();
6460 else {
6461 T = getDerived().TransformType(FromVar->getType());
6462 if (T.isNull())
Chad Rosier1dcde962012-08-08 18:46:20 +00006463 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006464 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006465
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006466 Var = getDerived().RebuildObjCExceptionDecl(FromVar, TSInfo, T);
6467 if (!Var)
John McCallfaf5fb42010-08-26 23:41:50 +00006468 return StmtError();
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006469 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006470
John McCalldadc5752010-08-24 06:29:42 +00006471 StmtResult Body = getDerived().TransformStmt(S->getCatchBody());
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006472 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006473 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006474
6475 return getDerived().RebuildObjCAtCatchStmt(S->getAtCatchLoc(),
Douglas Gregorf4e837f2010-04-26 17:57:08 +00006476 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006477 Var, Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006478}
Mike Stump11289f42009-09-09 15:08:12 +00006479
Douglas Gregorebe10102009-08-20 07:17:43 +00006480template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006481StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006482TreeTransform<Derived>::TransformObjCAtFinallyStmt(ObjCAtFinallyStmt *S) {
Douglas Gregor306de2f2010-04-22 23:59:56 +00006483 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006484 StmtResult Body = getDerived().TransformStmt(S->getFinallyBody());
Douglas Gregor306de2f2010-04-22 23:59:56 +00006485 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006486 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006487
Douglas Gregor306de2f2010-04-22 23:59:56 +00006488 // If nothing changed, just retain this statement.
6489 if (!getDerived().AlwaysRebuild() &&
6490 Body.get() == S->getFinallyBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006491 return S;
Douglas Gregor306de2f2010-04-22 23:59:56 +00006492
6493 // Build a new statement.
6494 return getDerived().RebuildObjCAtFinallyStmt(S->getAtFinallyLoc(),
John McCallb268a282010-08-23 23:25:46 +00006495 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006496}
Mike Stump11289f42009-09-09 15:08:12 +00006497
Douglas Gregorebe10102009-08-20 07:17:43 +00006498template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006499StmtResult
Mike Stump11289f42009-09-09 15:08:12 +00006500TreeTransform<Derived>::TransformObjCAtThrowStmt(ObjCAtThrowStmt *S) {
John McCalldadc5752010-08-24 06:29:42 +00006501 ExprResult Operand;
Douglas Gregor2900c162010-04-22 21:44:01 +00006502 if (S->getThrowExpr()) {
6503 Operand = getDerived().TransformExpr(S->getThrowExpr());
6504 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006505 return StmtError();
Douglas Gregor2900c162010-04-22 21:44:01 +00006506 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006507
Douglas Gregor2900c162010-04-22 21:44:01 +00006508 if (!getDerived().AlwaysRebuild() &&
6509 Operand.get() == S->getThrowExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006510 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006511
John McCallb268a282010-08-23 23:25:46 +00006512 return getDerived().RebuildObjCAtThrowStmt(S->getThrowLoc(), Operand.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006513}
Mike Stump11289f42009-09-09 15:08:12 +00006514
Douglas Gregorebe10102009-08-20 07:17:43 +00006515template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006516StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006517TreeTransform<Derived>::TransformObjCAtSynchronizedStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006518 ObjCAtSynchronizedStmt *S) {
Douglas Gregor6148de72010-04-22 22:01:21 +00006519 // Transform the object we are locking.
John McCalldadc5752010-08-24 06:29:42 +00006520 ExprResult Object = getDerived().TransformExpr(S->getSynchExpr());
Douglas Gregor6148de72010-04-22 22:01:21 +00006521 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006522 return StmtError();
John McCalld9bb7432011-07-27 21:50:02 +00006523 Object =
6524 getDerived().RebuildObjCAtSynchronizedOperand(S->getAtSynchronizedLoc(),
6525 Object.get());
6526 if (Object.isInvalid())
6527 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006528
Douglas Gregor6148de72010-04-22 22:01:21 +00006529 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006530 StmtResult Body = getDerived().TransformStmt(S->getSynchBody());
Douglas Gregor6148de72010-04-22 22:01:21 +00006531 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006532 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006533
Douglas Gregor6148de72010-04-22 22:01:21 +00006534 // If nothing change, just retain the current statement.
6535 if (!getDerived().AlwaysRebuild() &&
6536 Object.get() == S->getSynchExpr() &&
6537 Body.get() == S->getSynchBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006538 return S;
Douglas Gregor6148de72010-04-22 22:01:21 +00006539
6540 // Build a new statement.
6541 return getDerived().RebuildObjCAtSynchronizedStmt(S->getAtSynchronizedLoc(),
John McCallb268a282010-08-23 23:25:46 +00006542 Object.get(), Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006543}
6544
6545template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00006546StmtResult
John McCall31168b02011-06-15 23:02:42 +00006547TreeTransform<Derived>::TransformObjCAutoreleasePoolStmt(
6548 ObjCAutoreleasePoolStmt *S) {
6549 // Transform the body.
6550 StmtResult Body = getDerived().TransformStmt(S->getSubStmt());
6551 if (Body.isInvalid())
6552 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006553
John McCall31168b02011-06-15 23:02:42 +00006554 // If nothing changed, just retain this statement.
6555 if (!getDerived().AlwaysRebuild() &&
6556 Body.get() == S->getSubStmt())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006557 return S;
John McCall31168b02011-06-15 23:02:42 +00006558
6559 // Build a new statement.
6560 return getDerived().RebuildObjCAutoreleasePoolStmt(
6561 S->getAtLoc(), Body.get());
6562}
6563
6564template<typename Derived>
6565StmtResult
Douglas Gregorebe10102009-08-20 07:17:43 +00006566TreeTransform<Derived>::TransformObjCForCollectionStmt(
Mike Stump11289f42009-09-09 15:08:12 +00006567 ObjCForCollectionStmt *S) {
Douglas Gregorf68a5082010-04-22 23:10:45 +00006568 // Transform the element statement.
John McCalldadc5752010-08-24 06:29:42 +00006569 StmtResult Element = getDerived().TransformStmt(S->getElement());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006570 if (Element.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006571 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006572
Douglas Gregorf68a5082010-04-22 23:10:45 +00006573 // Transform the collection expression.
John McCalldadc5752010-08-24 06:29:42 +00006574 ExprResult Collection = getDerived().TransformExpr(S->getCollection());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006575 if (Collection.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006576 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006577
Douglas Gregorf68a5082010-04-22 23:10:45 +00006578 // Transform the body.
John McCalldadc5752010-08-24 06:29:42 +00006579 StmtResult Body = getDerived().TransformStmt(S->getBody());
Douglas Gregorf68a5082010-04-22 23:10:45 +00006580 if (Body.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006581 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006582
Douglas Gregorf68a5082010-04-22 23:10:45 +00006583 // If nothing changed, just retain this statement.
6584 if (!getDerived().AlwaysRebuild() &&
6585 Element.get() == S->getElement() &&
6586 Collection.get() == S->getCollection() &&
6587 Body.get() == S->getBody())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006588 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006589
Douglas Gregorf68a5082010-04-22 23:10:45 +00006590 // Build a new statement.
6591 return getDerived().RebuildObjCForCollectionStmt(S->getForLoc(),
John McCallb268a282010-08-23 23:25:46 +00006592 Element.get(),
6593 Collection.get(),
Douglas Gregorf68a5082010-04-22 23:10:45 +00006594 S->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00006595 Body.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006596}
6597
David Majnemer5f7efef2013-10-15 09:50:08 +00006598template <typename Derived>
6599StmtResult TreeTransform<Derived>::TransformCXXCatchStmt(CXXCatchStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006600 // Transform the exception declaration, if any.
Craig Topperc3ec1492014-05-26 06:22:03 +00006601 VarDecl *Var = nullptr;
David Majnemer5f7efef2013-10-15 09:50:08 +00006602 if (VarDecl *ExceptionDecl = S->getExceptionDecl()) {
6603 TypeSourceInfo *T =
6604 getDerived().TransformType(ExceptionDecl->getTypeSourceInfo());
Douglas Gregor9f0e1aa2010-09-09 17:09:21 +00006605 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00006606 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006607
David Majnemer5f7efef2013-10-15 09:50:08 +00006608 Var = getDerived().RebuildExceptionDecl(
6609 ExceptionDecl, T, ExceptionDecl->getInnerLocStart(),
6610 ExceptionDecl->getLocation(), ExceptionDecl->getIdentifier());
Douglas Gregorb412e172010-07-25 18:17:45 +00006611 if (!Var || Var->isInvalidDecl())
John McCallfaf5fb42010-08-26 23:41:50 +00006612 return StmtError();
Douglas Gregorebe10102009-08-20 07:17:43 +00006613 }
Mike Stump11289f42009-09-09 15:08:12 +00006614
Douglas Gregorebe10102009-08-20 07:17:43 +00006615 // Transform the actual exception handler.
John McCalldadc5752010-08-24 06:29:42 +00006616 StmtResult Handler = getDerived().TransformStmt(S->getHandlerBlock());
Douglas Gregorb412e172010-07-25 18:17:45 +00006617 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006618 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006619
David Majnemer5f7efef2013-10-15 09:50:08 +00006620 if (!getDerived().AlwaysRebuild() && !Var &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006621 Handler.get() == S->getHandlerBlock())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006622 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006623
David Majnemer5f7efef2013-10-15 09:50:08 +00006624 return getDerived().RebuildCXXCatchStmt(S->getCatchLoc(), Var, Handler.get());
Douglas Gregorebe10102009-08-20 07:17:43 +00006625}
Mike Stump11289f42009-09-09 15:08:12 +00006626
David Majnemer5f7efef2013-10-15 09:50:08 +00006627template <typename Derived>
6628StmtResult TreeTransform<Derived>::TransformCXXTryStmt(CXXTryStmt *S) {
Douglas Gregorebe10102009-08-20 07:17:43 +00006629 // Transform the try block itself.
David Majnemer5f7efef2013-10-15 09:50:08 +00006630 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
Douglas Gregorebe10102009-08-20 07:17:43 +00006631 if (TryBlock.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006632 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006633
Douglas Gregorebe10102009-08-20 07:17:43 +00006634 // Transform the handlers.
6635 bool HandlerChanged = false;
David Majnemer5f7efef2013-10-15 09:50:08 +00006636 SmallVector<Stmt *, 8> Handlers;
Douglas Gregorebe10102009-08-20 07:17:43 +00006637 for (unsigned I = 0, N = S->getNumHandlers(); I != N; ++I) {
David Majnemer5f7efef2013-10-15 09:50:08 +00006638 StmtResult Handler = getDerived().TransformCXXCatchStmt(S->getHandler(I));
Douglas Gregorebe10102009-08-20 07:17:43 +00006639 if (Handler.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00006640 return StmtError();
Mike Stump11289f42009-09-09 15:08:12 +00006641
Douglas Gregorebe10102009-08-20 07:17:43 +00006642 HandlerChanged = HandlerChanged || Handler.get() != S->getHandler(I);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006643 Handlers.push_back(Handler.getAs<Stmt>());
Douglas Gregorebe10102009-08-20 07:17:43 +00006644 }
Mike Stump11289f42009-09-09 15:08:12 +00006645
David Majnemer5f7efef2013-10-15 09:50:08 +00006646 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
Douglas Gregorebe10102009-08-20 07:17:43 +00006647 !HandlerChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006648 return S;
Douglas Gregorebe10102009-08-20 07:17:43 +00006649
John McCallb268a282010-08-23 23:25:46 +00006650 return getDerived().RebuildCXXTryStmt(S->getTryLoc(), TryBlock.get(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00006651 Handlers);
Douglas Gregorebe10102009-08-20 07:17:43 +00006652}
Mike Stump11289f42009-09-09 15:08:12 +00006653
Richard Smith02e85f32011-04-14 22:09:26 +00006654template<typename Derived>
6655StmtResult
6656TreeTransform<Derived>::TransformCXXForRangeStmt(CXXForRangeStmt *S) {
6657 StmtResult Range = getDerived().TransformStmt(S->getRangeStmt());
6658 if (Range.isInvalid())
6659 return StmtError();
6660
6661 StmtResult BeginEnd = getDerived().TransformStmt(S->getBeginEndStmt());
6662 if (BeginEnd.isInvalid())
6663 return StmtError();
6664
6665 ExprResult Cond = getDerived().TransformExpr(S->getCond());
6666 if (Cond.isInvalid())
6667 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006668 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006669 Cond = SemaRef.CheckBooleanCondition(Cond.get(), S->getColonLoc());
Eli Friedman87d32802012-01-31 22:45:40 +00006670 if (Cond.isInvalid())
6671 return StmtError();
6672 if (Cond.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006673 Cond = SemaRef.MaybeCreateExprWithCleanups(Cond.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006674
6675 ExprResult Inc = getDerived().TransformExpr(S->getInc());
6676 if (Inc.isInvalid())
6677 return StmtError();
Eli Friedman87d32802012-01-31 22:45:40 +00006678 if (Inc.get())
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006679 Inc = SemaRef.MaybeCreateExprWithCleanups(Inc.get());
Richard Smith02e85f32011-04-14 22:09:26 +00006680
6681 StmtResult LoopVar = getDerived().TransformStmt(S->getLoopVarStmt());
6682 if (LoopVar.isInvalid())
6683 return StmtError();
6684
6685 StmtResult NewStmt = S;
6686 if (getDerived().AlwaysRebuild() ||
6687 Range.get() != S->getRangeStmt() ||
6688 BeginEnd.get() != S->getBeginEndStmt() ||
6689 Cond.get() != S->getCond() ||
6690 Inc.get() != S->getInc() ||
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006691 LoopVar.get() != S->getLoopVarStmt()) {
Richard Smith02e85f32011-04-14 22:09:26 +00006692 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6693 S->getColonLoc(), Range.get(),
6694 BeginEnd.get(), Cond.get(),
6695 Inc.get(), LoopVar.get(),
6696 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006697 if (NewStmt.isInvalid())
6698 return StmtError();
6699 }
Richard Smith02e85f32011-04-14 22:09:26 +00006700
6701 StmtResult Body = getDerived().TransformStmt(S->getBody());
6702 if (Body.isInvalid())
6703 return StmtError();
6704
6705 // Body has changed but we didn't rebuild the for-range statement. Rebuild
6706 // it now so we have a new statement to attach the body to.
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006707 if (Body.get() != S->getBody() && NewStmt.get() == S) {
Richard Smith02e85f32011-04-14 22:09:26 +00006708 NewStmt = getDerived().RebuildCXXForRangeStmt(S->getForLoc(),
6709 S->getColonLoc(), Range.get(),
6710 BeginEnd.get(), Cond.get(),
6711 Inc.get(), LoopVar.get(),
6712 S->getRParenLoc());
Douglas Gregor39aaeef2013-05-02 18:35:56 +00006713 if (NewStmt.isInvalid())
6714 return StmtError();
6715 }
Richard Smith02e85f32011-04-14 22:09:26 +00006716
6717 if (NewStmt.get() == S)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006718 return S;
Richard Smith02e85f32011-04-14 22:09:26 +00006719
6720 return FinishCXXForRangeStmt(NewStmt.get(), Body.get());
6721}
6722
John Wiegley1c0675e2011-04-28 01:08:34 +00006723template<typename Derived>
6724StmtResult
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006725TreeTransform<Derived>::TransformMSDependentExistsStmt(
6726 MSDependentExistsStmt *S) {
6727 // Transform the nested-name-specifier, if any.
6728 NestedNameSpecifierLoc QualifierLoc;
6729 if (S->getQualifierLoc()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00006730 QualifierLoc
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006731 = getDerived().TransformNestedNameSpecifierLoc(S->getQualifierLoc());
6732 if (!QualifierLoc)
6733 return StmtError();
6734 }
6735
6736 // Transform the declaration name.
6737 DeclarationNameInfo NameInfo = S->getNameInfo();
6738 if (NameInfo.getName()) {
6739 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
6740 if (!NameInfo.getName())
6741 return StmtError();
6742 }
6743
6744 // Check whether anything changed.
6745 if (!getDerived().AlwaysRebuild() &&
6746 QualifierLoc == S->getQualifierLoc() &&
6747 NameInfo.getName() == S->getNameInfo().getName())
6748 return S;
Chad Rosier1dcde962012-08-08 18:46:20 +00006749
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006750 // Determine whether this name exists, if we can.
6751 CXXScopeSpec SS;
6752 SS.Adopt(QualifierLoc);
6753 bool Dependent = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00006754 switch (getSema().CheckMicrosoftIfExistsSymbol(/*S=*/nullptr, SS, NameInfo)) {
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006755 case Sema::IER_Exists:
6756 if (S->isIfExists())
6757 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006758
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006759 return new (getSema().Context) NullStmt(S->getKeywordLoc());
6760
6761 case Sema::IER_DoesNotExist:
6762 if (S->isIfNotExists())
6763 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006764
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006765 return new (getSema().Context) NullStmt(S->getKeywordLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00006766
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006767 case Sema::IER_Dependent:
6768 Dependent = true;
6769 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00006770
Douglas Gregor4a2a8f72011-10-25 03:44:56 +00006771 case Sema::IER_Error:
6772 return StmtError();
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006773 }
Chad Rosier1dcde962012-08-08 18:46:20 +00006774
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006775 // We need to continue with the instantiation, so do so now.
6776 StmtResult SubStmt = getDerived().TransformCompoundStmt(S->getSubStmt());
6777 if (SubStmt.isInvalid())
6778 return StmtError();
Chad Rosier1dcde962012-08-08 18:46:20 +00006779
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006780 // If we have resolved the name, just transform to the substatement.
6781 if (!Dependent)
6782 return SubStmt;
Chad Rosier1dcde962012-08-08 18:46:20 +00006783
Douglas Gregordeb4a2be2011-10-25 01:33:02 +00006784 // The name is still dependent, so build a dependent expression again.
6785 return getDerived().RebuildMSDependentExistsStmt(S->getKeywordLoc(),
6786 S->isIfExists(),
6787 QualifierLoc,
6788 NameInfo,
6789 SubStmt.get());
6790}
6791
6792template<typename Derived>
John McCall5e77d762013-04-16 07:28:30 +00006793ExprResult
6794TreeTransform<Derived>::TransformMSPropertyRefExpr(MSPropertyRefExpr *E) {
6795 NestedNameSpecifierLoc QualifierLoc;
6796 if (E->getQualifierLoc()) {
6797 QualifierLoc
6798 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
6799 if (!QualifierLoc)
6800 return ExprError();
6801 }
6802
6803 MSPropertyDecl *PD = cast_or_null<MSPropertyDecl>(
6804 getDerived().TransformDecl(E->getMemberLoc(), E->getPropertyDecl()));
6805 if (!PD)
6806 return ExprError();
6807
6808 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
6809 if (Base.isInvalid())
6810 return ExprError();
6811
6812 return new (SemaRef.getASTContext())
6813 MSPropertyRefExpr(Base.get(), PD, E->isArrow(),
6814 SemaRef.getASTContext().PseudoObjectTy, VK_LValue,
6815 QualifierLoc, E->getMemberLoc());
6816}
6817
David Majnemerfad8f482013-10-15 09:33:02 +00006818template <typename Derived>
6819StmtResult TreeTransform<Derived>::TransformSEHTryStmt(SEHTryStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006820 StmtResult TryBlock = getDerived().TransformCompoundStmt(S->getTryBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006821 if (TryBlock.isInvalid())
6822 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006823
6824 StmtResult Handler = getDerived().TransformSEHHandler(S->getHandler());
David Majnemer7e755502013-10-15 09:30:14 +00006825 if (Handler.isInvalid())
6826 return StmtError();
6827
David Majnemerfad8f482013-10-15 09:33:02 +00006828 if (!getDerived().AlwaysRebuild() && TryBlock.get() == S->getTryBlock() &&
6829 Handler.get() == S->getHandler())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00006830 return S;
John Wiegley1c0675e2011-04-28 01:08:34 +00006831
Warren Huntf6be4cb2014-07-25 20:52:51 +00006832 return getDerived().RebuildSEHTryStmt(S->getIsCXXTry(), S->getTryLoc(),
6833 TryBlock.get(), Handler.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006834}
6835
David Majnemerfad8f482013-10-15 09:33:02 +00006836template <typename Derived>
6837StmtResult TreeTransform<Derived>::TransformSEHFinallyStmt(SEHFinallyStmt *S) {
David Majnemer7e755502013-10-15 09:30:14 +00006838 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006839 if (Block.isInvalid())
6840 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006841
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006842 return getDerived().RebuildSEHFinallyStmt(S->getFinallyLoc(), Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006843}
6844
David Majnemerfad8f482013-10-15 09:33:02 +00006845template <typename Derived>
6846StmtResult TreeTransform<Derived>::TransformSEHExceptStmt(SEHExceptStmt *S) {
John Wiegley1c0675e2011-04-28 01:08:34 +00006847 ExprResult FilterExpr = getDerived().TransformExpr(S->getFilterExpr());
David Majnemerfad8f482013-10-15 09:33:02 +00006848 if (FilterExpr.isInvalid())
6849 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006850
David Majnemer7e755502013-10-15 09:30:14 +00006851 StmtResult Block = getDerived().TransformCompoundStmt(S->getBlock());
David Majnemerfad8f482013-10-15 09:33:02 +00006852 if (Block.isInvalid())
6853 return StmtError();
John Wiegley1c0675e2011-04-28 01:08:34 +00006854
Nikola Smiljanic01a75982014-05-29 10:55:11 +00006855 return getDerived().RebuildSEHExceptStmt(S->getExceptLoc(), FilterExpr.get(),
6856 Block.get());
John Wiegley1c0675e2011-04-28 01:08:34 +00006857}
6858
David Majnemerfad8f482013-10-15 09:33:02 +00006859template <typename Derived>
6860StmtResult TreeTransform<Derived>::TransformSEHHandler(Stmt *Handler) {
6861 if (isa<SEHFinallyStmt>(Handler))
John Wiegley1c0675e2011-04-28 01:08:34 +00006862 return getDerived().TransformSEHFinallyStmt(cast<SEHFinallyStmt>(Handler));
6863 else
6864 return getDerived().TransformSEHExceptStmt(cast<SEHExceptStmt>(Handler));
6865}
6866
Nico Weber9b982072014-07-07 00:12:30 +00006867template<typename Derived>
6868StmtResult
6869TreeTransform<Derived>::TransformSEHLeaveStmt(SEHLeaveStmt *S) {
6870 return S;
6871}
6872
Alexander Musman64d33f12014-06-04 07:53:32 +00006873//===----------------------------------------------------------------------===//
6874// OpenMP directive transformation
6875//===----------------------------------------------------------------------===//
6876template <typename Derived>
6877StmtResult TreeTransform<Derived>::TransformOMPExecutableDirective(
6878 OMPExecutableDirective *D) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00006879
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006880 // Transform the clauses
Alexey Bataev758e55e2013-09-06 18:03:48 +00006881 llvm::SmallVector<OMPClause *, 16> TClauses;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006882 ArrayRef<OMPClause *> Clauses = D->clauses();
6883 TClauses.reserve(Clauses.size());
6884 for (ArrayRef<OMPClause *>::iterator I = Clauses.begin(), E = Clauses.end();
6885 I != E; ++I) {
6886 if (*I) {
Alexey Bataevaac108a2015-06-23 04:51:00 +00006887 getDerived().getSema().StartOpenMPClause((*I)->getClauseKind());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006888 OMPClause *Clause = getDerived().TransformOMPClause(*I);
Alexey Bataevaac108a2015-06-23 04:51:00 +00006889 getDerived().getSema().EndOpenMPClause();
Alexey Bataevc5e02582014-06-16 07:08:35 +00006890 if (Clause)
6891 TClauses.push_back(Clause);
Alexander Musman64d33f12014-06-04 07:53:32 +00006892 } else {
Alexey Bataev9959db52014-05-06 10:08:46 +00006893 TClauses.push_back(nullptr);
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006894 }
6895 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006896 StmtResult AssociatedStmt;
6897 if (D->hasAssociatedStmt()) {
6898 if (!D->getAssociatedStmt()) {
6899 return StmtError();
6900 }
Alexey Bataev8bf6b3e2015-04-02 13:07:08 +00006901 getDerived().getSema().ActOnOpenMPRegionStart(D->getDirectiveKind(),
6902 /*CurScope=*/nullptr);
6903 StmtResult Body;
6904 {
6905 Sema::CompoundScopeRAII CompoundScope(getSema());
6906 Body = getDerived().TransformStmt(
6907 cast<CapturedStmt>(D->getAssociatedStmt())->getCapturedStmt());
6908 }
6909 AssociatedStmt =
6910 getDerived().getSema().ActOnOpenMPRegionEnd(Body, TClauses);
Alexey Bataev68446b72014-07-18 07:47:19 +00006911 if (AssociatedStmt.isInvalid()) {
6912 return StmtError();
6913 }
Alexey Bataev758e55e2013-09-06 18:03:48 +00006914 }
Alexey Bataev68446b72014-07-18 07:47:19 +00006915 if (TClauses.size() != Clauses.size()) {
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006916 return StmtError();
Alexey Bataev758e55e2013-09-06 18:03:48 +00006917 }
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006918
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006919 // Transform directive name for 'omp critical' directive.
6920 DeclarationNameInfo DirName;
6921 if (D->getDirectiveKind() == OMPD_critical) {
6922 DirName = cast<OMPCriticalDirective>(D)->getDirectiveName();
6923 DirName = getDerived().TransformDeclarationNameInfo(DirName);
6924 }
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006925 OpenMPDirectiveKind CancelRegion = OMPD_unknown;
6926 if (D->getDirectiveKind() == OMPD_cancellation_point) {
6927 CancelRegion = cast<OMPCancellationPointDirective>(D)->getCancelRegion();
Alexey Bataev80909872015-07-02 11:25:17 +00006928 } else if (D->getDirectiveKind() == OMPD_cancel) {
6929 CancelRegion = cast<OMPCancelDirective>(D)->getCancelRegion();
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006930 }
Alexander Musmand9ed09f2014-07-21 09:42:05 +00006931
Alexander Musman64d33f12014-06-04 07:53:32 +00006932 return getDerived().RebuildOMPExecutableDirective(
Alexey Bataev6d4ed052015-07-01 06:57:41 +00006933 D->getDirectiveKind(), DirName, CancelRegion, TClauses,
6934 AssociatedStmt.get(), D->getLocStart(), D->getLocEnd());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006935}
6936
Alexander Musman64d33f12014-06-04 07:53:32 +00006937template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006938StmtResult
6939TreeTransform<Derived>::TransformOMPParallelDirective(OMPParallelDirective *D) {
6940 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006941 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel, DirName, nullptr,
6942 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006943 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6944 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6945 return Res;
6946}
6947
Alexander Musman64d33f12014-06-04 07:53:32 +00006948template <typename Derived>
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006949StmtResult
6950TreeTransform<Derived>::TransformOMPSimdDirective(OMPSimdDirective *D) {
6951 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006952 getDerived().getSema().StartOpenMPDSABlock(OMPD_simd, DirName, nullptr,
6953 D->getLocStart());
Alexey Bataev1b59ab52014-02-27 08:29:12 +00006954 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6955 getDerived().getSema().EndOpenMPDSABlock(Res.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00006956 return Res;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00006957}
6958
Alexey Bataevf29276e2014-06-18 04:14:57 +00006959template <typename Derived>
6960StmtResult
6961TreeTransform<Derived>::TransformOMPForDirective(OMPForDirective *D) {
6962 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006963 getDerived().getSema().StartOpenMPDSABlock(OMPD_for, DirName, nullptr,
6964 D->getLocStart());
Alexey Bataevf29276e2014-06-18 04:14:57 +00006965 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6966 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6967 return Res;
6968}
6969
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006970template <typename Derived>
6971StmtResult
Alexander Musmanf82886e2014-09-18 05:12:34 +00006972TreeTransform<Derived>::TransformOMPForSimdDirective(OMPForSimdDirective *D) {
6973 DeclarationNameInfo DirName;
6974 getDerived().getSema().StartOpenMPDSABlock(OMPD_for_simd, DirName, nullptr,
6975 D->getLocStart());
6976 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6977 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6978 return Res;
6979}
6980
6981template <typename Derived>
6982StmtResult
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006983TreeTransform<Derived>::TransformOMPSectionsDirective(OMPSectionsDirective *D) {
6984 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006985 getDerived().getSema().StartOpenMPDSABlock(OMPD_sections, DirName, nullptr,
6986 D->getLocStart());
Alexey Bataevd3f8dd22014-06-25 11:44:49 +00006987 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6988 getDerived().getSema().EndOpenMPDSABlock(Res.get());
6989 return Res;
6990}
6991
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006992template <typename Derived>
6993StmtResult
6994TreeTransform<Derived>::TransformOMPSectionDirective(OMPSectionDirective *D) {
6995 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00006996 getDerived().getSema().StartOpenMPDSABlock(OMPD_section, DirName, nullptr,
6997 D->getLocStart());
Alexey Bataev1e0498a2014-06-26 08:21:58 +00006998 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
6999 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7000 return Res;
7001}
7002
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007003template <typename Derived>
7004StmtResult
7005TreeTransform<Derived>::TransformOMPSingleDirective(OMPSingleDirective *D) {
7006 DeclarationNameInfo DirName;
Alexey Bataevbae9a792014-06-27 10:37:06 +00007007 getDerived().getSema().StartOpenMPDSABlock(OMPD_single, DirName, nullptr,
7008 D->getLocStart());
Alexey Bataevd1e40fb2014-06-26 12:05:45 +00007009 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7010 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7011 return Res;
7012}
7013
Alexey Bataev4acb8592014-07-07 13:01:15 +00007014template <typename Derived>
Alexander Musman80c22892014-07-17 08:54:58 +00007015StmtResult
7016TreeTransform<Derived>::TransformOMPMasterDirective(OMPMasterDirective *D) {
7017 DeclarationNameInfo DirName;
7018 getDerived().getSema().StartOpenMPDSABlock(OMPD_master, DirName, nullptr,
7019 D->getLocStart());
7020 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7021 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7022 return Res;
7023}
7024
7025template <typename Derived>
Alexander Musmand9ed09f2014-07-21 09:42:05 +00007026StmtResult
7027TreeTransform<Derived>::TransformOMPCriticalDirective(OMPCriticalDirective *D) {
7028 getDerived().getSema().StartOpenMPDSABlock(
7029 OMPD_critical, D->getDirectiveName(), nullptr, D->getLocStart());
7030 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7031 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7032 return Res;
7033}
7034
7035template <typename Derived>
Alexey Bataev4acb8592014-07-07 13:01:15 +00007036StmtResult TreeTransform<Derived>::TransformOMPParallelForDirective(
7037 OMPParallelForDirective *D) {
7038 DeclarationNameInfo DirName;
7039 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for, DirName,
7040 nullptr, D->getLocStart());
7041 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7042 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7043 return Res;
7044}
7045
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007046template <typename Derived>
Alexander Musmane4e893b2014-09-23 09:33:00 +00007047StmtResult TreeTransform<Derived>::TransformOMPParallelForSimdDirective(
7048 OMPParallelForSimdDirective *D) {
7049 DeclarationNameInfo DirName;
7050 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_for_simd, DirName,
7051 nullptr, D->getLocStart());
7052 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7053 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7054 return Res;
7055}
7056
7057template <typename Derived>
Alexey Bataev84d0b3e2014-07-08 08:12:03 +00007058StmtResult TreeTransform<Derived>::TransformOMPParallelSectionsDirective(
7059 OMPParallelSectionsDirective *D) {
7060 DeclarationNameInfo DirName;
7061 getDerived().getSema().StartOpenMPDSABlock(OMPD_parallel_sections, DirName,
7062 nullptr, D->getLocStart());
7063 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7064 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7065 return Res;
7066}
7067
Alexey Bataev9c2e8ee2014-07-11 11:25:16 +00007068template <typename Derived>
7069StmtResult
7070TreeTransform<Derived>::TransformOMPTaskDirective(OMPTaskDirective *D) {
7071 DeclarationNameInfo DirName;
7072 getDerived().getSema().StartOpenMPDSABlock(OMPD_task, DirName, nullptr,
7073 D->getLocStart());
7074 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7075 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7076 return Res;
7077}
7078
Alexey Bataev68446b72014-07-18 07:47:19 +00007079template <typename Derived>
7080StmtResult TreeTransform<Derived>::TransformOMPTaskyieldDirective(
7081 OMPTaskyieldDirective *D) {
7082 DeclarationNameInfo DirName;
7083 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskyield, DirName, nullptr,
7084 D->getLocStart());
7085 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7086 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7087 return Res;
7088}
7089
Alexey Bataev4d1dfea2014-07-18 09:11:51 +00007090template <typename Derived>
7091StmtResult
7092TreeTransform<Derived>::TransformOMPBarrierDirective(OMPBarrierDirective *D) {
7093 DeclarationNameInfo DirName;
7094 getDerived().getSema().StartOpenMPDSABlock(OMPD_barrier, DirName, nullptr,
7095 D->getLocStart());
7096 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7097 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7098 return Res;
7099}
7100
Alexey Bataev2df347a2014-07-18 10:17:07 +00007101template <typename Derived>
7102StmtResult
7103TreeTransform<Derived>::TransformOMPTaskwaitDirective(OMPTaskwaitDirective *D) {
7104 DeclarationNameInfo DirName;
7105 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskwait, DirName, nullptr,
7106 D->getLocStart());
7107 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7108 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7109 return Res;
7110}
7111
Alexey Bataev6125da92014-07-21 11:26:11 +00007112template <typename Derived>
Alexey Bataevc30dd2d2015-06-18 12:14:09 +00007113StmtResult TreeTransform<Derived>::TransformOMPTaskgroupDirective(
7114 OMPTaskgroupDirective *D) {
7115 DeclarationNameInfo DirName;
7116 getDerived().getSema().StartOpenMPDSABlock(OMPD_taskgroup, DirName, nullptr,
7117 D->getLocStart());
7118 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7119 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7120 return Res;
7121}
7122
7123template <typename Derived>
Alexey Bataev6125da92014-07-21 11:26:11 +00007124StmtResult
7125TreeTransform<Derived>::TransformOMPFlushDirective(OMPFlushDirective *D) {
7126 DeclarationNameInfo DirName;
7127 getDerived().getSema().StartOpenMPDSABlock(OMPD_flush, DirName, nullptr,
7128 D->getLocStart());
7129 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7130 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7131 return Res;
7132}
7133
Alexey Bataev9fb6e642014-07-22 06:45:04 +00007134template <typename Derived>
7135StmtResult
7136TreeTransform<Derived>::TransformOMPOrderedDirective(OMPOrderedDirective *D) {
7137 DeclarationNameInfo DirName;
7138 getDerived().getSema().StartOpenMPDSABlock(OMPD_ordered, DirName, nullptr,
7139 D->getLocStart());
7140 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7141 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7142 return Res;
7143}
7144
Alexey Bataev0162e452014-07-22 10:10:35 +00007145template <typename Derived>
7146StmtResult
7147TreeTransform<Derived>::TransformOMPAtomicDirective(OMPAtomicDirective *D) {
7148 DeclarationNameInfo DirName;
7149 getDerived().getSema().StartOpenMPDSABlock(OMPD_atomic, DirName, nullptr,
7150 D->getLocStart());
7151 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7152 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7153 return Res;
7154}
7155
Alexey Bataev0bd520b2014-09-19 08:19:49 +00007156template <typename Derived>
7157StmtResult
7158TreeTransform<Derived>::TransformOMPTargetDirective(OMPTargetDirective *D) {
7159 DeclarationNameInfo DirName;
7160 getDerived().getSema().StartOpenMPDSABlock(OMPD_target, DirName, nullptr,
7161 D->getLocStart());
7162 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7163 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7164 return Res;
7165}
7166
Alexey Bataev13314bf2014-10-09 04:18:56 +00007167template <typename Derived>
Michael Wong65f367f2015-07-21 13:44:28 +00007168StmtResult TreeTransform<Derived>::TransformOMPTargetDataDirective(
7169 OMPTargetDataDirective *D) {
7170 DeclarationNameInfo DirName;
7171 getDerived().getSema().StartOpenMPDSABlock(OMPD_target_data, DirName, nullptr,
7172 D->getLocStart());
7173 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7174 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7175 return Res;
7176}
7177
7178template <typename Derived>
Alexey Bataev13314bf2014-10-09 04:18:56 +00007179StmtResult
7180TreeTransform<Derived>::TransformOMPTeamsDirective(OMPTeamsDirective *D) {
7181 DeclarationNameInfo DirName;
7182 getDerived().getSema().StartOpenMPDSABlock(OMPD_teams, DirName, nullptr,
7183 D->getLocStart());
7184 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7185 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7186 return Res;
7187}
7188
Alexey Bataev6d4ed052015-07-01 06:57:41 +00007189template <typename Derived>
7190StmtResult TreeTransform<Derived>::TransformOMPCancellationPointDirective(
7191 OMPCancellationPointDirective *D) {
7192 DeclarationNameInfo DirName;
7193 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancellation_point, DirName,
7194 nullptr, D->getLocStart());
7195 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7196 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7197 return Res;
7198}
7199
Alexey Bataev80909872015-07-02 11:25:17 +00007200template <typename Derived>
7201StmtResult
7202TreeTransform<Derived>::TransformOMPCancelDirective(OMPCancelDirective *D) {
7203 DeclarationNameInfo DirName;
7204 getDerived().getSema().StartOpenMPDSABlock(OMPD_cancel, DirName, nullptr,
7205 D->getLocStart());
7206 StmtResult Res = getDerived().TransformOMPExecutableDirective(D);
7207 getDerived().getSema().EndOpenMPDSABlock(Res.get());
7208 return Res;
7209}
7210
Alexander Musman64d33f12014-06-04 07:53:32 +00007211//===----------------------------------------------------------------------===//
7212// OpenMP clause transformation
7213//===----------------------------------------------------------------------===//
7214template <typename Derived>
7215OMPClause *TreeTransform<Derived>::TransformOMPIfClause(OMPIfClause *C) {
Alexey Bataevaf7849e2014-03-05 06:45:14 +00007216 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7217 if (Cond.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007218 return nullptr;
Alexey Bataev6b8046a2015-09-03 07:23:48 +00007219 return getDerived().RebuildOMPIfClause(
7220 C->getNameModifier(), Cond.get(), C->getLocStart(), C->getLParenLoc(),
7221 C->getNameModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007222}
7223
Alexander Musman64d33f12014-06-04 07:53:32 +00007224template <typename Derived>
Alexey Bataev3778b602014-07-17 07:32:53 +00007225OMPClause *TreeTransform<Derived>::TransformOMPFinalClause(OMPFinalClause *C) {
7226 ExprResult Cond = getDerived().TransformExpr(C->getCondition());
7227 if (Cond.isInvalid())
7228 return nullptr;
7229 return getDerived().RebuildOMPFinalClause(Cond.get(), C->getLocStart(),
7230 C->getLParenLoc(), C->getLocEnd());
7231}
7232
7233template <typename Derived>
Alexey Bataevaadd52e2014-02-13 05:29:23 +00007234OMPClause *
Alexey Bataev568a8332014-03-06 06:15:19 +00007235TreeTransform<Derived>::TransformOMPNumThreadsClause(OMPNumThreadsClause *C) {
7236 ExprResult NumThreads = getDerived().TransformExpr(C->getNumThreads());
7237 if (NumThreads.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007238 return nullptr;
Alexander Musman64d33f12014-06-04 07:53:32 +00007239 return getDerived().RebuildOMPNumThreadsClause(
7240 NumThreads.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev568a8332014-03-06 06:15:19 +00007241}
7242
Alexey Bataev62c87d22014-03-21 04:51:18 +00007243template <typename Derived>
7244OMPClause *
7245TreeTransform<Derived>::TransformOMPSafelenClause(OMPSafelenClause *C) {
7246 ExprResult E = getDerived().TransformExpr(C->getSafelen());
7247 if (E.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007248 return nullptr;
Alexey Bataev62c87d22014-03-21 04:51:18 +00007249 return getDerived().RebuildOMPSafelenClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007250 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev62c87d22014-03-21 04:51:18 +00007251}
7252
Alexander Musman8bd31e62014-05-27 15:12:19 +00007253template <typename Derived>
7254OMPClause *
Alexey Bataev66b15b52015-08-21 11:14:16 +00007255TreeTransform<Derived>::TransformOMPSimdlenClause(OMPSimdlenClause *C) {
7256 ExprResult E = getDerived().TransformExpr(C->getSimdlen());
7257 if (E.isInvalid())
7258 return nullptr;
7259 return getDerived().RebuildOMPSimdlenClause(
7260 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7261}
7262
7263template <typename Derived>
7264OMPClause *
Alexander Musman8bd31e62014-05-27 15:12:19 +00007265TreeTransform<Derived>::TransformOMPCollapseClause(OMPCollapseClause *C) {
7266 ExprResult E = getDerived().TransformExpr(C->getNumForLoops());
7267 if (E.isInvalid())
Hans Wennborg59dbe862015-09-29 20:56:43 +00007268 return nullptr;
Alexander Musman8bd31e62014-05-27 15:12:19 +00007269 return getDerived().RebuildOMPCollapseClause(
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007270 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexander Musman8bd31e62014-05-27 15:12:19 +00007271}
7272
Alexander Musman64d33f12014-06-04 07:53:32 +00007273template <typename Derived>
Alexey Bataev568a8332014-03-06 06:15:19 +00007274OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007275TreeTransform<Derived>::TransformOMPDefaultClause(OMPDefaultClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007276 return getDerived().RebuildOMPDefaultClause(
7277 C->getDefaultKind(), C->getDefaultKindKwLoc(), C->getLocStart(),
7278 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007279}
7280
Alexander Musman64d33f12014-06-04 07:53:32 +00007281template <typename Derived>
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007282OMPClause *
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007283TreeTransform<Derived>::TransformOMPProcBindClause(OMPProcBindClause *C) {
Alexander Musman64d33f12014-06-04 07:53:32 +00007284 return getDerived().RebuildOMPProcBindClause(
7285 C->getProcBindKind(), C->getProcBindKindKwLoc(), C->getLocStart(),
7286 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007287}
7288
Alexander Musman64d33f12014-06-04 07:53:32 +00007289template <typename Derived>
Alexey Bataevbcbadb62014-05-06 06:04:14 +00007290OMPClause *
Alexey Bataev56dafe82014-06-20 07:16:17 +00007291TreeTransform<Derived>::TransformOMPScheduleClause(OMPScheduleClause *C) {
7292 ExprResult E = getDerived().TransformExpr(C->getChunkSize());
7293 if (E.isInvalid())
7294 return nullptr;
7295 return getDerived().RebuildOMPScheduleClause(
7296 C->getScheduleKind(), E.get(), C->getLocStart(), C->getLParenLoc(),
7297 C->getScheduleKindLoc(), C->getCommaLoc(), C->getLocEnd());
7298}
7299
7300template <typename Derived>
7301OMPClause *
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007302TreeTransform<Derived>::TransformOMPOrderedClause(OMPOrderedClause *C) {
Alexey Bataev10e775f2015-07-30 11:36:16 +00007303 ExprResult E;
7304 if (auto *Num = C->getNumForLoops()) {
7305 E = getDerived().TransformExpr(Num);
7306 if (E.isInvalid())
7307 return nullptr;
7308 }
7309 return getDerived().RebuildOMPOrderedClause(C->getLocStart(), C->getLocEnd(),
7310 C->getLParenLoc(), E.get());
Alexey Bataev142e1fc2014-06-20 09:44:06 +00007311}
7312
7313template <typename Derived>
7314OMPClause *
Alexey Bataev236070f2014-06-20 11:19:47 +00007315TreeTransform<Derived>::TransformOMPNowaitClause(OMPNowaitClause *C) {
7316 // No need to rebuild this clause, no template-dependent parameters.
7317 return C;
7318}
7319
7320template <typename Derived>
7321OMPClause *
Alexey Bataev7aea99a2014-07-17 12:19:31 +00007322TreeTransform<Derived>::TransformOMPUntiedClause(OMPUntiedClause *C) {
7323 // No need to rebuild this clause, no template-dependent parameters.
7324 return C;
7325}
7326
7327template <typename Derived>
7328OMPClause *
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007329TreeTransform<Derived>::TransformOMPMergeableClause(OMPMergeableClause *C) {
7330 // No need to rebuild this clause, no template-dependent parameters.
7331 return C;
7332}
7333
7334template <typename Derived>
Alexey Bataevf98b00c2014-07-23 02:27:21 +00007335OMPClause *TreeTransform<Derived>::TransformOMPReadClause(OMPReadClause *C) {
7336 // No need to rebuild this clause, no template-dependent parameters.
7337 return C;
7338}
7339
7340template <typename Derived>
Alexey Bataevdea47612014-07-23 07:46:59 +00007341OMPClause *TreeTransform<Derived>::TransformOMPWriteClause(OMPWriteClause *C) {
7342 // No need to rebuild this clause, no template-dependent parameters.
7343 return C;
7344}
7345
7346template <typename Derived>
Alexey Bataev74ba3a52014-07-17 12:47:03 +00007347OMPClause *
Alexey Bataev67a4f222014-07-23 10:25:33 +00007348TreeTransform<Derived>::TransformOMPUpdateClause(OMPUpdateClause *C) {
7349 // No need to rebuild this clause, no template-dependent parameters.
7350 return C;
7351}
7352
7353template <typename Derived>
7354OMPClause *
Alexey Bataev459dec02014-07-24 06:46:57 +00007355TreeTransform<Derived>::TransformOMPCaptureClause(OMPCaptureClause *C) {
7356 // No need to rebuild this clause, no template-dependent parameters.
7357 return C;
7358}
7359
7360template <typename Derived>
7361OMPClause *
Alexey Bataev82bad8b2014-07-24 08:55:34 +00007362TreeTransform<Derived>::TransformOMPSeqCstClause(OMPSeqCstClause *C) {
7363 // No need to rebuild this clause, no template-dependent parameters.
7364 return C;
7365}
7366
7367template <typename Derived>
7368OMPClause *
Alexey Bataev346265e2015-09-25 10:37:12 +00007369TreeTransform<Derived>::TransformOMPThreadsClause(OMPThreadsClause *C) {
7370 // No need to rebuild this clause, no template-dependent parameters.
7371 return C;
7372}
7373
7374template <typename Derived>
Alexey Bataevd14d1e62015-09-28 06:39:35 +00007375OMPClause *TreeTransform<Derived>::TransformOMPSIMDClause(OMPSIMDClause *C) {
7376 // No need to rebuild this clause, no template-dependent parameters.
7377 return C;
7378}
7379
7380template <typename Derived>
Alexey Bataev346265e2015-09-25 10:37:12 +00007381OMPClause *
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007382TreeTransform<Derived>::TransformOMPPrivateClause(OMPPrivateClause *C) {
Alexey Bataev758e55e2013-09-06 18:03:48 +00007383 llvm::SmallVector<Expr *, 16> Vars;
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007384 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007385 for (auto *VE : C->varlists()) {
7386 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007387 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007388 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007389 Vars.push_back(EVar.get());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007390 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007391 return getDerived().RebuildOMPPrivateClause(
7392 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataev5ec3eb12013-07-19 03:13:43 +00007393}
7394
Alexander Musman64d33f12014-06-04 07:53:32 +00007395template <typename Derived>
7396OMPClause *TreeTransform<Derived>::TransformOMPFirstprivateClause(
7397 OMPFirstprivateClause *C) {
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007398 llvm::SmallVector<Expr *, 16> Vars;
7399 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007400 for (auto *VE : C->varlists()) {
7401 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007402 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007403 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007404 Vars.push_back(EVar.get());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007405 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007406 return getDerived().RebuildOMPFirstprivateClause(
7407 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007408}
7409
Alexander Musman64d33f12014-06-04 07:53:32 +00007410template <typename Derived>
Alexey Bataevd5af8e42013-10-01 05:32:34 +00007411OMPClause *
Alexander Musman1bb328c2014-06-04 13:06:39 +00007412TreeTransform<Derived>::TransformOMPLastprivateClause(OMPLastprivateClause *C) {
7413 llvm::SmallVector<Expr *, 16> Vars;
7414 Vars.reserve(C->varlist_size());
7415 for (auto *VE : C->varlists()) {
7416 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7417 if (EVar.isInvalid())
7418 return nullptr;
7419 Vars.push_back(EVar.get());
7420 }
7421 return getDerived().RebuildOMPLastprivateClause(
7422 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7423}
7424
7425template <typename Derived>
7426OMPClause *
Alexey Bataev758e55e2013-09-06 18:03:48 +00007427TreeTransform<Derived>::TransformOMPSharedClause(OMPSharedClause *C) {
7428 llvm::SmallVector<Expr *, 16> Vars;
7429 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007430 for (auto *VE : C->varlists()) {
7431 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataev758e55e2013-09-06 18:03:48 +00007432 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007433 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007434 Vars.push_back(EVar.get());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007435 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007436 return getDerived().RebuildOMPSharedClause(Vars, C->getLocStart(),
7437 C->getLParenLoc(), C->getLocEnd());
Alexey Bataev758e55e2013-09-06 18:03:48 +00007438}
7439
Alexander Musman64d33f12014-06-04 07:53:32 +00007440template <typename Derived>
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007441OMPClause *
Alexey Bataevc5e02582014-06-16 07:08:35 +00007442TreeTransform<Derived>::TransformOMPReductionClause(OMPReductionClause *C) {
7443 llvm::SmallVector<Expr *, 16> Vars;
7444 Vars.reserve(C->varlist_size());
7445 for (auto *VE : C->varlists()) {
7446 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7447 if (EVar.isInvalid())
7448 return nullptr;
7449 Vars.push_back(EVar.get());
7450 }
7451 CXXScopeSpec ReductionIdScopeSpec;
7452 ReductionIdScopeSpec.Adopt(C->getQualifierLoc());
7453
7454 DeclarationNameInfo NameInfo = C->getNameInfo();
7455 if (NameInfo.getName()) {
7456 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7457 if (!NameInfo.getName())
7458 return nullptr;
7459 }
7460 return getDerived().RebuildOMPReductionClause(
7461 Vars, C->getLocStart(), C->getLParenLoc(), C->getColonLoc(),
7462 C->getLocEnd(), ReductionIdScopeSpec, NameInfo);
7463}
7464
7465template <typename Derived>
7466OMPClause *
Alexander Musman8dba6642014-04-22 13:09:42 +00007467TreeTransform<Derived>::TransformOMPLinearClause(OMPLinearClause *C) {
7468 llvm::SmallVector<Expr *, 16> Vars;
7469 Vars.reserve(C->varlist_size());
7470 for (auto *VE : C->varlists()) {
7471 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7472 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007473 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007474 Vars.push_back(EVar.get());
Alexander Musman8dba6642014-04-22 13:09:42 +00007475 }
7476 ExprResult Step = getDerived().TransformExpr(C->getStep());
7477 if (Step.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007478 return nullptr;
Alexey Bataev182227b2015-08-20 10:54:39 +00007479 return getDerived().RebuildOMPLinearClause(
7480 Vars, Step.get(), C->getLocStart(), C->getLParenLoc(), C->getModifier(),
7481 C->getModifierLoc(), C->getColonLoc(), C->getLocEnd());
Alexander Musman8dba6642014-04-22 13:09:42 +00007482}
7483
Alexander Musman64d33f12014-06-04 07:53:32 +00007484template <typename Derived>
Alexander Musman8dba6642014-04-22 13:09:42 +00007485OMPClause *
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007486TreeTransform<Derived>::TransformOMPAlignedClause(OMPAlignedClause *C) {
7487 llvm::SmallVector<Expr *, 16> Vars;
7488 Vars.reserve(C->varlist_size());
7489 for (auto *VE : C->varlists()) {
7490 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7491 if (EVar.isInvalid())
7492 return nullptr;
7493 Vars.push_back(EVar.get());
7494 }
7495 ExprResult Alignment = getDerived().TransformExpr(C->getAlignment());
7496 if (Alignment.isInvalid())
7497 return nullptr;
7498 return getDerived().RebuildOMPAlignedClause(
7499 Vars, Alignment.get(), C->getLocStart(), C->getLParenLoc(),
7500 C->getColonLoc(), C->getLocEnd());
7501}
7502
Alexander Musman64d33f12014-06-04 07:53:32 +00007503template <typename Derived>
Alexander Musmanf0d76e72014-05-29 14:36:25 +00007504OMPClause *
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007505TreeTransform<Derived>::TransformOMPCopyinClause(OMPCopyinClause *C) {
7506 llvm::SmallVector<Expr *, 16> Vars;
7507 Vars.reserve(C->varlist_size());
Alexey Bataev444120d2014-04-04 10:02:14 +00007508 for (auto *VE : C->varlists()) {
7509 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007510 if (EVar.isInvalid())
Craig Topperc3ec1492014-05-26 06:22:03 +00007511 return nullptr;
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007512 Vars.push_back(EVar.get());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007513 }
Alexander Musman64d33f12014-06-04 07:53:32 +00007514 return getDerived().RebuildOMPCopyinClause(Vars, C->getLocStart(),
7515 C->getLParenLoc(), C->getLocEnd());
Alexey Bataevd48bcd82014-03-31 03:36:38 +00007516}
7517
Alexey Bataevbae9a792014-06-27 10:37:06 +00007518template <typename Derived>
7519OMPClause *
7520TreeTransform<Derived>::TransformOMPCopyprivateClause(OMPCopyprivateClause *C) {
7521 llvm::SmallVector<Expr *, 16> Vars;
7522 Vars.reserve(C->varlist_size());
7523 for (auto *VE : C->varlists()) {
7524 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7525 if (EVar.isInvalid())
7526 return nullptr;
7527 Vars.push_back(EVar.get());
7528 }
7529 return getDerived().RebuildOMPCopyprivateClause(
7530 Vars, C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7531}
7532
Alexey Bataev6125da92014-07-21 11:26:11 +00007533template <typename Derived>
7534OMPClause *TreeTransform<Derived>::TransformOMPFlushClause(OMPFlushClause *C) {
7535 llvm::SmallVector<Expr *, 16> Vars;
7536 Vars.reserve(C->varlist_size());
7537 for (auto *VE : C->varlists()) {
7538 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7539 if (EVar.isInvalid())
7540 return nullptr;
7541 Vars.push_back(EVar.get());
7542 }
7543 return getDerived().RebuildOMPFlushClause(Vars, C->getLocStart(),
7544 C->getLParenLoc(), C->getLocEnd());
7545}
7546
Alexey Bataev1c2cfbc2015-06-23 14:25:19 +00007547template <typename Derived>
7548OMPClause *
7549TreeTransform<Derived>::TransformOMPDependClause(OMPDependClause *C) {
7550 llvm::SmallVector<Expr *, 16> Vars;
7551 Vars.reserve(C->varlist_size());
7552 for (auto *VE : C->varlists()) {
7553 ExprResult EVar = getDerived().TransformExpr(cast<Expr>(VE));
7554 if (EVar.isInvalid())
7555 return nullptr;
7556 Vars.push_back(EVar.get());
7557 }
7558 return getDerived().RebuildOMPDependClause(
7559 C->getDependencyKind(), C->getDependencyLoc(), C->getColonLoc(), Vars,
7560 C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7561}
7562
Michael Wonge710d542015-08-07 16:16:36 +00007563template <typename Derived>
7564OMPClause *
7565TreeTransform<Derived>::TransformOMPDeviceClause(OMPDeviceClause *C) {
7566 ExprResult E = getDerived().TransformExpr(C->getDevice());
7567 if (E.isInvalid())
7568 return nullptr;
7569 return getDerived().RebuildOMPDeviceClause(
7570 E.get(), C->getLocStart(), C->getLParenLoc(), C->getLocEnd());
7571}
7572
Douglas Gregorebe10102009-08-20 07:17:43 +00007573//===----------------------------------------------------------------------===//
Douglas Gregora16548e2009-08-11 05:31:07 +00007574// Expression transformation
7575//===----------------------------------------------------------------------===//
Mike Stump11289f42009-09-09 15:08:12 +00007576template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007577ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007578TreeTransform<Derived>::TransformPredefinedExpr(PredefinedExpr *E) {
Alexey Bataevec474782014-10-09 08:45:04 +00007579 if (!E->isTypeDependent())
7580 return E;
7581
7582 return getDerived().RebuildPredefinedExpr(E->getLocation(),
7583 E->getIdentType());
Douglas Gregora16548e2009-08-11 05:31:07 +00007584}
Mike Stump11289f42009-09-09 15:08:12 +00007585
7586template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007587ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007588TreeTransform<Derived>::TransformDeclRefExpr(DeclRefExpr *E) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007589 NestedNameSpecifierLoc QualifierLoc;
7590 if (E->getQualifierLoc()) {
7591 QualifierLoc
7592 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
7593 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00007594 return ExprError();
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007595 }
John McCallce546572009-12-08 09:08:17 +00007596
7597 ValueDecl *ND
Douglas Gregora04f2ca2010-03-01 15:56:25 +00007598 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getLocation(),
7599 E->getDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00007600 if (!ND)
John McCallfaf5fb42010-08-26 23:41:50 +00007601 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007602
John McCall815039a2010-08-17 21:27:17 +00007603 DeclarationNameInfo NameInfo = E->getNameInfo();
7604 if (NameInfo.getName()) {
7605 NameInfo = getDerived().TransformDeclarationNameInfo(NameInfo);
7606 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00007607 return ExprError();
John McCall815039a2010-08-17 21:27:17 +00007608 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007609
7610 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00007611 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007612 ND == E->getDecl() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00007613 NameInfo.getName() == E->getDecl()->getDeclName() &&
John McCallb3774b52010-08-19 23:49:38 +00007614 !E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007615
7616 // Mark it referenced in the new context regardless.
7617 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00007618 SemaRef.MarkDeclRefReferenced(E);
John McCallce546572009-12-08 09:08:17 +00007619
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007620 return E;
Douglas Gregor4bd90e52009-10-23 18:54:35 +00007621 }
John McCallce546572009-12-08 09:08:17 +00007622
Craig Topperc3ec1492014-05-26 06:22:03 +00007623 TemplateArgumentListInfo TransArgs, *TemplateArgs = nullptr;
John McCallb3774b52010-08-19 23:49:38 +00007624 if (E->hasExplicitTemplateArgs()) {
John McCallce546572009-12-08 09:08:17 +00007625 TemplateArgs = &TransArgs;
7626 TransArgs.setLAngleLoc(E->getLAngleLoc());
7627 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00007628 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
7629 E->getNumTemplateArgs(),
7630 TransArgs))
7631 return ExprError();
John McCallce546572009-12-08 09:08:17 +00007632 }
7633
Chad Rosier1dcde962012-08-08 18:46:20 +00007634 return getDerived().RebuildDeclRefExpr(QualifierLoc, ND, NameInfo,
Douglas Gregorea972d32011-02-28 21:54:11 +00007635 TemplateArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00007636}
Mike Stump11289f42009-09-09 15:08:12 +00007637
Douglas Gregora16548e2009-08-11 05:31:07 +00007638template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007639ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007640TreeTransform<Derived>::TransformIntegerLiteral(IntegerLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007641 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007642}
Mike Stump11289f42009-09-09 15:08:12 +00007643
Douglas Gregora16548e2009-08-11 05:31:07 +00007644template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007645ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007646TreeTransform<Derived>::TransformFloatingLiteral(FloatingLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007647 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007648}
Mike Stump11289f42009-09-09 15:08:12 +00007649
Douglas Gregora16548e2009-08-11 05:31:07 +00007650template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007651ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007652TreeTransform<Derived>::TransformImaginaryLiteral(ImaginaryLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007653 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007654}
Mike Stump11289f42009-09-09 15:08:12 +00007655
Douglas Gregora16548e2009-08-11 05:31:07 +00007656template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007657ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007658TreeTransform<Derived>::TransformStringLiteral(StringLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007659 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00007660}
Mike Stump11289f42009-09-09 15:08:12 +00007661
Douglas Gregora16548e2009-08-11 05:31:07 +00007662template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007663ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007664TreeTransform<Derived>::TransformCharacterLiteral(CharacterLiteral *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007665 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007666}
7667
7668template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007669ExprResult
Richard Smithc67fdd42012-03-07 08:35:16 +00007670TreeTransform<Derived>::TransformUserDefinedLiteral(UserDefinedLiteral *E) {
Argyrios Kyrtzidis25049092013-04-09 01:17:02 +00007671 if (FunctionDecl *FD = E->getDirectCallee())
7672 SemaRef.MarkFunctionReferenced(E->getLocStart(), FD);
Richard Smithc67fdd42012-03-07 08:35:16 +00007673 return SemaRef.MaybeBindToTemporary(E);
7674}
7675
7676template<typename Derived>
7677ExprResult
Peter Collingbourne91147592011-04-15 00:35:48 +00007678TreeTransform<Derived>::TransformGenericSelectionExpr(GenericSelectionExpr *E) {
7679 ExprResult ControllingExpr =
7680 getDerived().TransformExpr(E->getControllingExpr());
7681 if (ControllingExpr.isInvalid())
7682 return ExprError();
7683
Chris Lattner01cf8db2011-07-20 06:58:45 +00007684 SmallVector<Expr *, 4> AssocExprs;
7685 SmallVector<TypeSourceInfo *, 4> AssocTypes;
Peter Collingbourne91147592011-04-15 00:35:48 +00007686 for (unsigned i = 0; i != E->getNumAssocs(); ++i) {
7687 TypeSourceInfo *TS = E->getAssocTypeSourceInfo(i);
7688 if (TS) {
7689 TypeSourceInfo *AssocType = getDerived().TransformType(TS);
7690 if (!AssocType)
7691 return ExprError();
7692 AssocTypes.push_back(AssocType);
7693 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00007694 AssocTypes.push_back(nullptr);
Peter Collingbourne91147592011-04-15 00:35:48 +00007695 }
7696
7697 ExprResult AssocExpr = getDerived().TransformExpr(E->getAssocExpr(i));
7698 if (AssocExpr.isInvalid())
7699 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007700 AssocExprs.push_back(AssocExpr.get());
Peter Collingbourne91147592011-04-15 00:35:48 +00007701 }
7702
7703 return getDerived().RebuildGenericSelectionExpr(E->getGenericLoc(),
7704 E->getDefaultLoc(),
7705 E->getRParenLoc(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007706 ControllingExpr.get(),
Dmitri Gribenko82360372013-05-10 13:06:58 +00007707 AssocTypes,
7708 AssocExprs);
Peter Collingbourne91147592011-04-15 00:35:48 +00007709}
7710
7711template<typename Derived>
7712ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007713TreeTransform<Derived>::TransformParenExpr(ParenExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007714 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007715 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007716 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007717
Douglas Gregora16548e2009-08-11 05:31:07 +00007718 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007719 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007720
John McCallb268a282010-08-23 23:25:46 +00007721 return getDerived().RebuildParenExpr(SubExpr.get(), E->getLParen(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007722 E->getRParen());
7723}
7724
Richard Smithdb2630f2012-10-21 03:28:35 +00007725/// \brief The operand of a unary address-of operator has special rules: it's
7726/// allowed to refer to a non-static member of a class even if there's no 'this'
7727/// object available.
7728template<typename Derived>
7729ExprResult
7730TreeTransform<Derived>::TransformAddressOfOperand(Expr *E) {
7731 if (DependentScopeDeclRefExpr *DRE = dyn_cast<DependentScopeDeclRefExpr>(E))
Reid Kleckner32506ed2014-06-12 23:03:48 +00007732 return getDerived().TransformDependentScopeDeclRefExpr(DRE, true, nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00007733 else
7734 return getDerived().TransformExpr(E);
7735}
7736
Mike Stump11289f42009-09-09 15:08:12 +00007737template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007738ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007739TreeTransform<Derived>::TransformUnaryOperator(UnaryOperator *E) {
Richard Smitheebe125f2013-05-21 23:29:46 +00007740 ExprResult SubExpr;
7741 if (E->getOpcode() == UO_AddrOf)
7742 SubExpr = TransformAddressOfOperand(E->getSubExpr());
7743 else
7744 SubExpr = TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00007745 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007746 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007747
Douglas Gregora16548e2009-08-11 05:31:07 +00007748 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007749 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007750
Douglas Gregora16548e2009-08-11 05:31:07 +00007751 return getDerived().RebuildUnaryOperator(E->getOperatorLoc(),
7752 E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00007753 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00007754}
Mike Stump11289f42009-09-09 15:08:12 +00007755
Douglas Gregora16548e2009-08-11 05:31:07 +00007756template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007757ExprResult
Douglas Gregor882211c2010-04-28 22:16:22 +00007758TreeTransform<Derived>::TransformOffsetOfExpr(OffsetOfExpr *E) {
7759 // Transform the type.
7760 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
7761 if (!Type)
John McCallfaf5fb42010-08-26 23:41:50 +00007762 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007763
Douglas Gregor882211c2010-04-28 22:16:22 +00007764 // Transform all of the components into components similar to what the
7765 // parser uses.
Chad Rosier1dcde962012-08-08 18:46:20 +00007766 // FIXME: It would be slightly more efficient in the non-dependent case to
7767 // just map FieldDecls, rather than requiring the rebuilder to look for
7768 // the fields again. However, __builtin_offsetof is rare enough in
Douglas Gregor882211c2010-04-28 22:16:22 +00007769 // template code that we don't care.
7770 bool ExprChanged = false;
John McCallfaf5fb42010-08-26 23:41:50 +00007771 typedef Sema::OffsetOfComponent Component;
Douglas Gregor882211c2010-04-28 22:16:22 +00007772 typedef OffsetOfExpr::OffsetOfNode Node;
Chris Lattner01cf8db2011-07-20 06:58:45 +00007773 SmallVector<Component, 4> Components;
Douglas Gregor882211c2010-04-28 22:16:22 +00007774 for (unsigned I = 0, N = E->getNumComponents(); I != N; ++I) {
7775 const Node &ON = E->getComponent(I);
7776 Component Comp;
Douglas Gregor0be628f2010-04-30 20:35:01 +00007777 Comp.isBrackets = true;
Abramo Bagnara6b6f0512011-03-12 09:45:03 +00007778 Comp.LocStart = ON.getSourceRange().getBegin();
7779 Comp.LocEnd = ON.getSourceRange().getEnd();
Douglas Gregor882211c2010-04-28 22:16:22 +00007780 switch (ON.getKind()) {
7781 case Node::Array: {
7782 Expr *FromIndex = E->getIndexExpr(ON.getArrayExprIndex());
John McCalldadc5752010-08-24 06:29:42 +00007783 ExprResult Index = getDerived().TransformExpr(FromIndex);
Douglas Gregor882211c2010-04-28 22:16:22 +00007784 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007785 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007786
Douglas Gregor882211c2010-04-28 22:16:22 +00007787 ExprChanged = ExprChanged || Index.get() != FromIndex;
7788 Comp.isBrackets = true;
John McCallb268a282010-08-23 23:25:46 +00007789 Comp.U.E = Index.get();
Douglas Gregor882211c2010-04-28 22:16:22 +00007790 break;
7791 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007792
Douglas Gregor882211c2010-04-28 22:16:22 +00007793 case Node::Field:
7794 case Node::Identifier:
7795 Comp.isBrackets = false;
7796 Comp.U.IdentInfo = ON.getFieldName();
Douglas Gregorea679ec2010-04-28 22:43:14 +00007797 if (!Comp.U.IdentInfo)
7798 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00007799
Douglas Gregor882211c2010-04-28 22:16:22 +00007800 break;
Chad Rosier1dcde962012-08-08 18:46:20 +00007801
Douglas Gregord1702062010-04-29 00:18:15 +00007802 case Node::Base:
7803 // Will be recomputed during the rebuild.
7804 continue;
Douglas Gregor882211c2010-04-28 22:16:22 +00007805 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007806
Douglas Gregor882211c2010-04-28 22:16:22 +00007807 Components.push_back(Comp);
7808 }
Chad Rosier1dcde962012-08-08 18:46:20 +00007809
Douglas Gregor882211c2010-04-28 22:16:22 +00007810 // If nothing changed, retain the existing expression.
7811 if (!getDerived().AlwaysRebuild() &&
7812 Type == E->getTypeSourceInfo() &&
7813 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007814 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +00007815
Douglas Gregor882211c2010-04-28 22:16:22 +00007816 // Build a new offsetof expression.
7817 return getDerived().RebuildOffsetOfExpr(E->getOperatorLoc(), Type,
Craig Topperb5518242015-10-22 04:59:59 +00007818 Components, E->getRParenLoc());
Douglas Gregor882211c2010-04-28 22:16:22 +00007819}
7820
7821template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007822ExprResult
John McCall8d69a212010-11-15 23:31:06 +00007823TreeTransform<Derived>::TransformOpaqueValueExpr(OpaqueValueExpr *E) {
Hubert Tong2cded442015-09-01 22:50:31 +00007824 assert((!E->getSourceExpr() || getDerived().AlreadyTransformed(E->getType())) &&
John McCall8d69a212010-11-15 23:31:06 +00007825 "opaque value expression requires transformation");
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007826 return E;
John McCall8d69a212010-11-15 23:31:06 +00007827}
7828
7829template<typename Derived>
7830ExprResult
Kaelyn Takatae1f49d52014-10-27 18:07:20 +00007831TreeTransform<Derived>::TransformTypoExpr(TypoExpr *E) {
7832 return E;
7833}
7834
7835template<typename Derived>
7836ExprResult
John McCallfe96e0b2011-11-06 09:01:30 +00007837TreeTransform<Derived>::TransformPseudoObjectExpr(PseudoObjectExpr *E) {
John McCalle9290822011-11-30 04:42:31 +00007838 // Rebuild the syntactic form. The original syntactic form has
7839 // opaque-value expressions in it, so strip those away and rebuild
7840 // the result. This is a really awful way of doing this, but the
7841 // better solution (rebuilding the semantic expressions and
7842 // rebinding OVEs as necessary) doesn't work; we'd need
7843 // TreeTransform to not strip away implicit conversions.
7844 Expr *newSyntacticForm = SemaRef.recreateSyntacticForm(E);
7845 ExprResult result = getDerived().TransformExpr(newSyntacticForm);
John McCallfe96e0b2011-11-06 09:01:30 +00007846 if (result.isInvalid()) return ExprError();
7847
7848 // If that gives us a pseudo-object result back, the pseudo-object
7849 // expression must have been an lvalue-to-rvalue conversion which we
7850 // should reapply.
7851 if (result.get()->hasPlaceholderType(BuiltinType::PseudoObject))
Nikola Smiljanic01a75982014-05-29 10:55:11 +00007852 result = SemaRef.checkPseudoObjectRValue(result.get());
John McCallfe96e0b2011-11-06 09:01:30 +00007853
7854 return result;
7855}
7856
7857template<typename Derived>
7858ExprResult
Peter Collingbournee190dee2011-03-11 19:24:49 +00007859TreeTransform<Derived>::TransformUnaryExprOrTypeTraitExpr(
7860 UnaryExprOrTypeTraitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007861 if (E->isArgumentType()) {
John McCallbcd03502009-12-07 02:54:59 +00007862 TypeSourceInfo *OldT = E->getArgumentTypeInfo();
Douglas Gregor3da3c062009-10-28 00:29:27 +00007863
John McCallbcd03502009-12-07 02:54:59 +00007864 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
John McCall4c98fd82009-11-04 07:28:41 +00007865 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00007866 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007867
John McCall4c98fd82009-11-04 07:28:41 +00007868 if (!getDerived().AlwaysRebuild() && OldT == NewT)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007869 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007870
Peter Collingbournee190dee2011-03-11 19:24:49 +00007871 return getDerived().RebuildUnaryExprOrTypeTrait(NewT, E->getOperatorLoc(),
7872 E->getKind(),
7873 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007874 }
Mike Stump11289f42009-09-09 15:08:12 +00007875
Eli Friedmane4f22df2012-02-29 04:03:55 +00007876 // C++0x [expr.sizeof]p1:
7877 // The operand is either an expression, which is an unevaluated operand
7878 // [...]
Eli Friedman15681d62012-09-26 04:34:21 +00007879 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
7880 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00007881
Reid Kleckner32506ed2014-06-12 23:03:48 +00007882 // Try to recover if we have something like sizeof(T::X) where X is a type.
7883 // Notably, there must be *exactly* one set of parens if X is a type.
7884 TypeSourceInfo *RecoveryTSI = nullptr;
7885 ExprResult SubExpr;
7886 auto *PE = dyn_cast<ParenExpr>(E->getArgumentExpr());
7887 if (auto *DRE =
7888 PE ? dyn_cast<DependentScopeDeclRefExpr>(PE->getSubExpr()) : nullptr)
7889 SubExpr = getDerived().TransformParenDependentScopeDeclRefExpr(
7890 PE, DRE, false, &RecoveryTSI);
7891 else
7892 SubExpr = getDerived().TransformExpr(E->getArgumentExpr());
7893
7894 if (RecoveryTSI) {
7895 return getDerived().RebuildUnaryExprOrTypeTrait(
7896 RecoveryTSI, E->getOperatorLoc(), E->getKind(), E->getSourceRange());
7897 } else if (SubExpr.isInvalid())
Eli Friedmane4f22df2012-02-29 04:03:55 +00007898 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007899
Eli Friedmane4f22df2012-02-29 04:03:55 +00007900 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getArgumentExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007901 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007902
Peter Collingbournee190dee2011-03-11 19:24:49 +00007903 return getDerived().RebuildUnaryExprOrTypeTrait(SubExpr.get(),
7904 E->getOperatorLoc(),
7905 E->getKind(),
7906 E->getSourceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00007907}
Mike Stump11289f42009-09-09 15:08:12 +00007908
Douglas Gregora16548e2009-08-11 05:31:07 +00007909template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007910ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007911TreeTransform<Derived>::TransformArraySubscriptExpr(ArraySubscriptExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007912 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007913 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007914 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007915
John McCalldadc5752010-08-24 06:29:42 +00007916 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00007917 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007918 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007919
7920
Douglas Gregora16548e2009-08-11 05:31:07 +00007921 if (!getDerived().AlwaysRebuild() &&
7922 LHS.get() == E->getLHS() &&
7923 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00007924 return E;
Mike Stump11289f42009-09-09 15:08:12 +00007925
John McCallb268a282010-08-23 23:25:46 +00007926 return getDerived().RebuildArraySubscriptExpr(LHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007927 /*FIXME:*/E->getLHS()->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00007928 RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00007929 E->getRBracketLoc());
7930}
Mike Stump11289f42009-09-09 15:08:12 +00007931
Alexey Bataev1a3320e2015-08-25 14:24:04 +00007932template <typename Derived>
7933ExprResult
7934TreeTransform<Derived>::TransformOMPArraySectionExpr(OMPArraySectionExpr *E) {
7935 ExprResult Base = getDerived().TransformExpr(E->getBase());
7936 if (Base.isInvalid())
7937 return ExprError();
7938
7939 ExprResult LowerBound;
7940 if (E->getLowerBound()) {
7941 LowerBound = getDerived().TransformExpr(E->getLowerBound());
7942 if (LowerBound.isInvalid())
7943 return ExprError();
7944 }
7945
7946 ExprResult Length;
7947 if (E->getLength()) {
7948 Length = getDerived().TransformExpr(E->getLength());
7949 if (Length.isInvalid())
7950 return ExprError();
7951 }
7952
7953 if (!getDerived().AlwaysRebuild() && Base.get() == E->getBase() &&
7954 LowerBound.get() == E->getLowerBound() && Length.get() == E->getLength())
7955 return E;
7956
7957 return getDerived().RebuildOMPArraySectionExpr(
7958 Base.get(), E->getBase()->getLocEnd(), LowerBound.get(), E->getColonLoc(),
7959 Length.get(), E->getRBracketLoc());
7960}
7961
Mike Stump11289f42009-09-09 15:08:12 +00007962template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007963ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007964TreeTransform<Derived>::TransformCallExpr(CallExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00007965 // Transform the callee.
John McCalldadc5752010-08-24 06:29:42 +00007966 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00007967 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007968 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00007969
7970 // Transform arguments.
7971 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00007972 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00007973 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00007974 &ArgChanged))
7975 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00007976
Douglas Gregora16548e2009-08-11 05:31:07 +00007977 if (!getDerived().AlwaysRebuild() &&
7978 Callee.get() == E->getCallee() &&
7979 !ArgChanged)
Dmitri Gribenko76bb5cabfa2012-09-10 21:20:09 +00007980 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00007981
Douglas Gregora16548e2009-08-11 05:31:07 +00007982 // FIXME: Wrong source location information for the '('.
Mike Stump11289f42009-09-09 15:08:12 +00007983 SourceLocation FakeLParenLoc
Douglas Gregora16548e2009-08-11 05:31:07 +00007984 = ((Expr *)Callee.get())->getSourceRange().getBegin();
John McCallb268a282010-08-23 23:25:46 +00007985 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00007986 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00007987 E->getRParenLoc());
7988}
Mike Stump11289f42009-09-09 15:08:12 +00007989
7990template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00007991ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00007992TreeTransform<Derived>::TransformMemberExpr(MemberExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00007993 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00007994 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00007995 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00007996
Douglas Gregorea972d32011-02-28 21:54:11 +00007997 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorf405d7e2009-08-31 23:41:50 +00007998 if (E->hasQualifier()) {
Douglas Gregorea972d32011-02-28 21:54:11 +00007999 QualifierLoc
8000 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
Chad Rosier1dcde962012-08-08 18:46:20 +00008001
Douglas Gregorea972d32011-02-28 21:54:11 +00008002 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00008003 return ExprError();
Douglas Gregorf405d7e2009-08-31 23:41:50 +00008004 }
Abramo Bagnara7945c982012-01-27 09:46:47 +00008005 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00008006
Eli Friedman2cfcef62009-12-04 06:40:45 +00008007 ValueDecl *Member
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008008 = cast_or_null<ValueDecl>(getDerived().TransformDecl(E->getMemberLoc(),
8009 E->getMemberDecl()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008010 if (!Member)
John McCallfaf5fb42010-08-26 23:41:50 +00008011 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008012
John McCall16df1e52010-03-30 21:47:33 +00008013 NamedDecl *FoundDecl = E->getFoundDecl();
8014 if (FoundDecl == E->getMemberDecl()) {
8015 FoundDecl = Member;
8016 } else {
8017 FoundDecl = cast_or_null<NamedDecl>(
8018 getDerived().TransformDecl(E->getMemberLoc(), FoundDecl));
8019 if (!FoundDecl)
John McCallfaf5fb42010-08-26 23:41:50 +00008020 return ExprError();
John McCall16df1e52010-03-30 21:47:33 +00008021 }
8022
Douglas Gregora16548e2009-08-11 05:31:07 +00008023 if (!getDerived().AlwaysRebuild() &&
8024 Base.get() == E->getBase() &&
Douglas Gregorea972d32011-02-28 21:54:11 +00008025 QualifierLoc == E->getQualifierLoc() &&
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008026 Member == E->getMemberDecl() &&
John McCall16df1e52010-03-30 21:47:33 +00008027 FoundDecl == E->getFoundDecl() &&
John McCallb3774b52010-08-19 23:49:38 +00008028 !E->hasExplicitTemplateArgs()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00008029
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008030 // Mark it referenced in the new context regardless.
8031 // FIXME: this is a bit instantiation-specific.
Eli Friedmanfa0df832012-02-02 03:46:19 +00008032 SemaRef.MarkMemberReferenced(E);
8033
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008034 return E;
Anders Carlsson9c45ad72009-12-22 05:24:09 +00008035 }
Douglas Gregora16548e2009-08-11 05:31:07 +00008036
John McCall6b51f282009-11-23 01:53:49 +00008037 TemplateArgumentListInfo TransArgs;
John McCallb3774b52010-08-19 23:49:38 +00008038 if (E->hasExplicitTemplateArgs()) {
John McCall6b51f282009-11-23 01:53:49 +00008039 TransArgs.setLAngleLoc(E->getLAngleLoc());
8040 TransArgs.setRAngleLoc(E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00008041 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
8042 E->getNumTemplateArgs(),
8043 TransArgs))
8044 return ExprError();
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008045 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008046
Douglas Gregora16548e2009-08-11 05:31:07 +00008047 // FIXME: Bogus source location for the operator
Alp Tokerb6cc5922014-05-03 03:45:55 +00008048 SourceLocation FakeOperatorLoc =
8049 SemaRef.getLocForEndOfToken(E->getBase()->getSourceRange().getEnd());
Douglas Gregora16548e2009-08-11 05:31:07 +00008050
John McCall38836f02010-01-15 08:34:02 +00008051 // FIXME: to do this check properly, we will need to preserve the
8052 // first-qualifier-in-scope here, just in case we had a dependent
8053 // base (and therefore couldn't do the check) and a
8054 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00008055 NamedDecl *FirstQualifierInScope = nullptr;
John McCall38836f02010-01-15 08:34:02 +00008056
John McCallb268a282010-08-23 23:25:46 +00008057 return getDerived().RebuildMemberExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008058 E->isArrow(),
Douglas Gregorea972d32011-02-28 21:54:11 +00008059 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00008060 TemplateKWLoc,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00008061 E->getMemberNameInfo(),
Douglas Gregorb184f0d2009-11-04 23:20:05 +00008062 Member,
John McCall16df1e52010-03-30 21:47:33 +00008063 FoundDecl,
John McCallb3774b52010-08-19 23:49:38 +00008064 (E->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00008065 ? &TransArgs : nullptr),
John McCall38836f02010-01-15 08:34:02 +00008066 FirstQualifierInScope);
Douglas Gregora16548e2009-08-11 05:31:07 +00008067}
Mike Stump11289f42009-09-09 15:08:12 +00008068
Douglas Gregora16548e2009-08-11 05:31:07 +00008069template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008070ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008071TreeTransform<Derived>::TransformBinaryOperator(BinaryOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008072 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008073 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008074 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008075
John McCalldadc5752010-08-24 06:29:42 +00008076 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008077 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008078 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008079
Douglas Gregora16548e2009-08-11 05:31:07 +00008080 if (!getDerived().AlwaysRebuild() &&
8081 LHS.get() == E->getLHS() &&
8082 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008083 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008084
Lang Hames5de91cc2012-10-02 04:45:10 +00008085 Sema::FPContractStateRAII FPContractState(getSema());
8086 getSema().FPFeatures.fp_contract = E->isFPContractable();
8087
Douglas Gregora16548e2009-08-11 05:31:07 +00008088 return getDerived().RebuildBinaryOperator(E->getOperatorLoc(), E->getOpcode(),
John McCallb268a282010-08-23 23:25:46 +00008089 LHS.get(), RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008090}
8091
Mike Stump11289f42009-09-09 15:08:12 +00008092template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008093ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008094TreeTransform<Derived>::TransformCompoundAssignOperator(
John McCall47f29ea2009-12-08 09:21:05 +00008095 CompoundAssignOperator *E) {
8096 return getDerived().TransformBinaryOperator(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008097}
Mike Stump11289f42009-09-09 15:08:12 +00008098
Douglas Gregora16548e2009-08-11 05:31:07 +00008099template<typename Derived>
John McCallc07a0c72011-02-17 10:25:35 +00008100ExprResult TreeTransform<Derived>::
8101TransformBinaryConditionalOperator(BinaryConditionalOperator *e) {
8102 // Just rebuild the common and RHS expressions and see whether we
8103 // get any changes.
8104
8105 ExprResult commonExpr = getDerived().TransformExpr(e->getCommon());
8106 if (commonExpr.isInvalid())
8107 return ExprError();
8108
8109 ExprResult rhs = getDerived().TransformExpr(e->getFalseExpr());
8110 if (rhs.isInvalid())
8111 return ExprError();
8112
8113 if (!getDerived().AlwaysRebuild() &&
8114 commonExpr.get() == e->getCommon() &&
8115 rhs.get() == e->getFalseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008116 return e;
John McCallc07a0c72011-02-17 10:25:35 +00008117
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008118 return getDerived().RebuildConditionalOperator(commonExpr.get(),
John McCallc07a0c72011-02-17 10:25:35 +00008119 e->getQuestionLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00008120 nullptr,
John McCallc07a0c72011-02-17 10:25:35 +00008121 e->getColonLoc(),
8122 rhs.get());
8123}
8124
8125template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008126ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008127TreeTransform<Derived>::TransformConditionalOperator(ConditionalOperator *E) {
John McCalldadc5752010-08-24 06:29:42 +00008128 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008129 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008130 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008131
John McCalldadc5752010-08-24 06:29:42 +00008132 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008133 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008134 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008135
John McCalldadc5752010-08-24 06:29:42 +00008136 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008137 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008138 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008139
Douglas Gregora16548e2009-08-11 05:31:07 +00008140 if (!getDerived().AlwaysRebuild() &&
8141 Cond.get() == E->getCond() &&
8142 LHS.get() == E->getLHS() &&
8143 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008144 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008145
John McCallb268a282010-08-23 23:25:46 +00008146 return getDerived().RebuildConditionalOperator(Cond.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008147 E->getQuestionLoc(),
John McCallb268a282010-08-23 23:25:46 +00008148 LHS.get(),
Douglas Gregor7e112b02009-08-26 14:37:04 +00008149 E->getColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008150 RHS.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008151}
Mike Stump11289f42009-09-09 15:08:12 +00008152
8153template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008154ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008155TreeTransform<Derived>::TransformImplicitCastExpr(ImplicitCastExpr *E) {
Douglas Gregor6131b442009-12-12 18:16:41 +00008156 // Implicit casts are eliminated during transformation, since they
8157 // will be recomputed by semantic analysis after transformation.
Douglas Gregord196a582009-12-14 19:27:10 +00008158 return getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008159}
Mike Stump11289f42009-09-09 15:08:12 +00008160
Douglas Gregora16548e2009-08-11 05:31:07 +00008161template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008162ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008163TreeTransform<Derived>::TransformCStyleCastExpr(CStyleCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008164 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8165 if (!Type)
8166 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008167
John McCalldadc5752010-08-24 06:29:42 +00008168 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008169 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008170 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008171 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008172
Douglas Gregora16548e2009-08-11 05:31:07 +00008173 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008174 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008175 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008176 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008177
John McCall97513962010-01-15 18:39:57 +00008178 return getDerived().RebuildCStyleCastExpr(E->getLParenLoc(),
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008179 Type,
Douglas Gregora16548e2009-08-11 05:31:07 +00008180 E->getRParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008181 SubExpr.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008182}
Mike Stump11289f42009-09-09 15:08:12 +00008183
Douglas Gregora16548e2009-08-11 05:31:07 +00008184template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008185ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008186TreeTransform<Derived>::TransformCompoundLiteralExpr(CompoundLiteralExpr *E) {
John McCalle15bbff2010-01-18 19:35:47 +00008187 TypeSourceInfo *OldT = E->getTypeSourceInfo();
8188 TypeSourceInfo *NewT = getDerived().TransformType(OldT);
8189 if (!NewT)
John McCallfaf5fb42010-08-26 23:41:50 +00008190 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008191
John McCalldadc5752010-08-24 06:29:42 +00008192 ExprResult Init = getDerived().TransformExpr(E->getInitializer());
Douglas Gregora16548e2009-08-11 05:31:07 +00008193 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008194 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008195
Douglas Gregora16548e2009-08-11 05:31:07 +00008196 if (!getDerived().AlwaysRebuild() &&
John McCalle15bbff2010-01-18 19:35:47 +00008197 OldT == NewT &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008198 Init.get() == E->getInitializer())
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008199 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008200
John McCall5d7aa7f2010-01-19 22:33:45 +00008201 // Note: the expression type doesn't necessarily match the
8202 // type-as-written, but that's okay, because it should always be
8203 // derivable from the initializer.
8204
John McCalle15bbff2010-01-18 19:35:47 +00008205 return getDerived().RebuildCompoundLiteralExpr(E->getLParenLoc(), NewT,
Douglas Gregora16548e2009-08-11 05:31:07 +00008206 /*FIXME:*/E->getInitializer()->getLocEnd(),
John McCallb268a282010-08-23 23:25:46 +00008207 Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008208}
Mike Stump11289f42009-09-09 15:08:12 +00008209
Douglas Gregora16548e2009-08-11 05:31:07 +00008210template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008211ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008212TreeTransform<Derived>::TransformExtVectorElementExpr(ExtVectorElementExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008213 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregora16548e2009-08-11 05:31:07 +00008214 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008215 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008216
Douglas Gregora16548e2009-08-11 05:31:07 +00008217 if (!getDerived().AlwaysRebuild() &&
8218 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008219 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008220
Douglas Gregora16548e2009-08-11 05:31:07 +00008221 // FIXME: Bad source location
Alp Tokerb6cc5922014-05-03 03:45:55 +00008222 SourceLocation FakeOperatorLoc =
8223 SemaRef.getLocForEndOfToken(E->getBase()->getLocEnd());
John McCallb268a282010-08-23 23:25:46 +00008224 return getDerived().RebuildExtVectorElementExpr(Base.get(), FakeOperatorLoc,
Douglas Gregora16548e2009-08-11 05:31:07 +00008225 E->getAccessorLoc(),
8226 E->getAccessor());
8227}
Mike Stump11289f42009-09-09 15:08:12 +00008228
Douglas Gregora16548e2009-08-11 05:31:07 +00008229template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008230ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008231TreeTransform<Derived>::TransformInitListExpr(InitListExpr *E) {
Richard Smith520449d2015-02-05 06:15:50 +00008232 if (InitListExpr *Syntactic = E->getSyntacticForm())
8233 E = Syntactic;
8234
Douglas Gregora16548e2009-08-11 05:31:07 +00008235 bool InitChanged = false;
Mike Stump11289f42009-09-09 15:08:12 +00008236
Benjamin Kramerf0623432012-08-23 22:51:59 +00008237 SmallVector<Expr*, 4> Inits;
Chad Rosier1dcde962012-08-08 18:46:20 +00008238 if (getDerived().TransformExprs(E->getInits(), E->getNumInits(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +00008239 Inits, &InitChanged))
8240 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008241
Richard Smith520449d2015-02-05 06:15:50 +00008242 if (!getDerived().AlwaysRebuild() && !InitChanged) {
8243 // FIXME: Attempt to reuse the existing syntactic form of the InitListExpr
8244 // in some cases. We can't reuse it in general, because the syntactic and
8245 // semantic forms are linked, and we can't know that semantic form will
8246 // match even if the syntactic form does.
8247 }
Mike Stump11289f42009-09-09 15:08:12 +00008248
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008249 return getDerived().RebuildInitList(E->getLBraceLoc(), Inits,
Douglas Gregord3d93062009-11-09 17:16:50 +00008250 E->getRBraceLoc(), E->getType());
Douglas Gregora16548e2009-08-11 05:31:07 +00008251}
Mike Stump11289f42009-09-09 15:08:12 +00008252
Douglas Gregora16548e2009-08-11 05:31:07 +00008253template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008254ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008255TreeTransform<Derived>::TransformDesignatedInitExpr(DesignatedInitExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008256 Designation Desig;
Mike Stump11289f42009-09-09 15:08:12 +00008257
Douglas Gregorebe10102009-08-20 07:17:43 +00008258 // transform the initializer value
John McCalldadc5752010-08-24 06:29:42 +00008259 ExprResult Init = getDerived().TransformExpr(E->getInit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008260 if (Init.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008261 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008262
Douglas Gregorebe10102009-08-20 07:17:43 +00008263 // transform the designators.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008264 SmallVector<Expr*, 4> ArrayExprs;
Douglas Gregora16548e2009-08-11 05:31:07 +00008265 bool ExprChanged = false;
8266 for (DesignatedInitExpr::designators_iterator D = E->designators_begin(),
8267 DEnd = E->designators_end();
8268 D != DEnd; ++D) {
8269 if (D->isFieldDesignator()) {
8270 Desig.AddDesignator(Designator::getField(D->getFieldName(),
8271 D->getDotLoc(),
8272 D->getFieldLoc()));
8273 continue;
8274 }
Mike Stump11289f42009-09-09 15:08:12 +00008275
Douglas Gregora16548e2009-08-11 05:31:07 +00008276 if (D->isArrayDesignator()) {
John McCalldadc5752010-08-24 06:29:42 +00008277 ExprResult Index = getDerived().TransformExpr(E->getArrayIndex(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008278 if (Index.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008279 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008280
8281 Desig.AddDesignator(Designator::getArray(Index.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008282 D->getLBracketLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008283
Douglas Gregora16548e2009-08-11 05:31:07 +00008284 ExprChanged = ExprChanged || Init.get() != E->getArrayIndex(*D);
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008285 ArrayExprs.push_back(Index.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008286 continue;
8287 }
Mike Stump11289f42009-09-09 15:08:12 +00008288
Douglas Gregora16548e2009-08-11 05:31:07 +00008289 assert(D->isArrayRangeDesignator() && "New kind of designator?");
John McCalldadc5752010-08-24 06:29:42 +00008290 ExprResult Start
Douglas Gregora16548e2009-08-11 05:31:07 +00008291 = getDerived().TransformExpr(E->getArrayRangeStart(*D));
8292 if (Start.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008293 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008294
John McCalldadc5752010-08-24 06:29:42 +00008295 ExprResult End = getDerived().TransformExpr(E->getArrayRangeEnd(*D));
Douglas Gregora16548e2009-08-11 05:31:07 +00008296 if (End.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008297 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008298
8299 Desig.AddDesignator(Designator::getArrayRange(Start.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008300 End.get(),
8301 D->getLBracketLoc(),
8302 D->getEllipsisLoc()));
Mike Stump11289f42009-09-09 15:08:12 +00008303
Douglas Gregora16548e2009-08-11 05:31:07 +00008304 ExprChanged = ExprChanged || Start.get() != E->getArrayRangeStart(*D) ||
8305 End.get() != E->getArrayRangeEnd(*D);
Mike Stump11289f42009-09-09 15:08:12 +00008306
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008307 ArrayExprs.push_back(Start.get());
8308 ArrayExprs.push_back(End.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008309 }
Mike Stump11289f42009-09-09 15:08:12 +00008310
Douglas Gregora16548e2009-08-11 05:31:07 +00008311 if (!getDerived().AlwaysRebuild() &&
8312 Init.get() == E->getInit() &&
8313 !ExprChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008314 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008315
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008316 return getDerived().RebuildDesignatedInitExpr(Desig, ArrayExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008317 E->getEqualOrColonLoc(),
John McCallb268a282010-08-23 23:25:46 +00008318 E->usesGNUSyntax(), Init.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008319}
Mike Stump11289f42009-09-09 15:08:12 +00008320
Yunzhong Gaocb779302015-06-10 00:27:52 +00008321// Seems that if TransformInitListExpr() only works on the syntactic form of an
8322// InitListExpr, then a DesignatedInitUpdateExpr is not encountered.
8323template<typename Derived>
8324ExprResult
8325TreeTransform<Derived>::TransformDesignatedInitUpdateExpr(
8326 DesignatedInitUpdateExpr *E) {
8327 llvm_unreachable("Unexpected DesignatedInitUpdateExpr in syntactic form of "
8328 "initializer");
8329 return ExprError();
8330}
8331
8332template<typename Derived>
8333ExprResult
8334TreeTransform<Derived>::TransformNoInitExpr(
8335 NoInitExpr *E) {
8336 llvm_unreachable("Unexpected NoInitExpr in syntactic form of initializer");
8337 return ExprError();
8338}
8339
Douglas Gregora16548e2009-08-11 05:31:07 +00008340template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008341ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008342TreeTransform<Derived>::TransformImplicitValueInitExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008343 ImplicitValueInitExpr *E) {
Douglas Gregor3da3c062009-10-28 00:29:27 +00008344 TemporaryBase Rebase(*this, E->getLocStart(), DeclarationName());
Chad Rosier1dcde962012-08-08 18:46:20 +00008345
Douglas Gregor3da3c062009-10-28 00:29:27 +00008346 // FIXME: Will we ever have proper type location here? Will we actually
8347 // need to transform the type?
Douglas Gregora16548e2009-08-11 05:31:07 +00008348 QualType T = getDerived().TransformType(E->getType());
8349 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00008350 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008351
Douglas Gregora16548e2009-08-11 05:31:07 +00008352 if (!getDerived().AlwaysRebuild() &&
8353 T == E->getType())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008354 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008355
Douglas Gregora16548e2009-08-11 05:31:07 +00008356 return getDerived().RebuildImplicitValueInitExpr(T);
8357}
Mike Stump11289f42009-09-09 15:08:12 +00008358
Douglas Gregora16548e2009-08-11 05:31:07 +00008359template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008360ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008361TreeTransform<Derived>::TransformVAArgExpr(VAArgExpr *E) {
Douglas Gregor7058c262010-08-10 14:27:00 +00008362 TypeSourceInfo *TInfo = getDerived().TransformType(E->getWrittenTypeInfo());
8363 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008364 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008365
John McCalldadc5752010-08-24 06:29:42 +00008366 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008367 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008368 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008369
Douglas Gregora16548e2009-08-11 05:31:07 +00008370 if (!getDerived().AlwaysRebuild() &&
Abramo Bagnara27db2392010-08-10 10:06:15 +00008371 TInfo == E->getWrittenTypeInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008372 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008373 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008374
John McCallb268a282010-08-23 23:25:46 +00008375 return getDerived().RebuildVAArgExpr(E->getBuiltinLoc(), SubExpr.get(),
Abramo Bagnara27db2392010-08-10 10:06:15 +00008376 TInfo, E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008377}
8378
8379template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008380ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008381TreeTransform<Derived>::TransformParenListExpr(ParenListExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008382 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008383 SmallVector<Expr*, 4> Inits;
Douglas Gregora3efea12011-01-03 19:04:46 +00008384 if (TransformExprs(E->getExprs(), E->getNumExprs(), true, Inits,
8385 &ArgumentChanged))
8386 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008387
Douglas Gregora16548e2009-08-11 05:31:07 +00008388 return getDerived().RebuildParenListExpr(E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008389 Inits,
Douglas Gregora16548e2009-08-11 05:31:07 +00008390 E->getRParenLoc());
8391}
Mike Stump11289f42009-09-09 15:08:12 +00008392
Douglas Gregora16548e2009-08-11 05:31:07 +00008393/// \brief Transform an address-of-label expression.
8394///
8395/// By default, the transformation of an address-of-label expression always
8396/// rebuilds the expression, so that the label identifier can be resolved to
8397/// the corresponding label statement by semantic analysis.
8398template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008399ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008400TreeTransform<Derived>::TransformAddrLabelExpr(AddrLabelExpr *E) {
Chris Lattnercab02a62011-02-17 20:34:02 +00008401 Decl *LD = getDerived().TransformDecl(E->getLabel()->getLocation(),
8402 E->getLabel());
8403 if (!LD)
8404 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008405
Douglas Gregora16548e2009-08-11 05:31:07 +00008406 return getDerived().RebuildAddrLabelExpr(E->getAmpAmpLoc(), E->getLabelLoc(),
Chris Lattnercab02a62011-02-17 20:34:02 +00008407 cast<LabelDecl>(LD));
Douglas Gregora16548e2009-08-11 05:31:07 +00008408}
Mike Stump11289f42009-09-09 15:08:12 +00008409
8410template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +00008411ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008412TreeTransform<Derived>::TransformStmtExpr(StmtExpr *E) {
John McCalled7b2782012-04-06 18:20:53 +00008413 SemaRef.ActOnStartStmtExpr();
John McCalldadc5752010-08-24 06:29:42 +00008414 StmtResult SubStmt
Douglas Gregora16548e2009-08-11 05:31:07 +00008415 = getDerived().TransformCompoundStmt(E->getSubStmt(), true);
John McCalled7b2782012-04-06 18:20:53 +00008416 if (SubStmt.isInvalid()) {
8417 SemaRef.ActOnStmtExprError();
John McCallfaf5fb42010-08-26 23:41:50 +00008418 return ExprError();
John McCalled7b2782012-04-06 18:20:53 +00008419 }
Mike Stump11289f42009-09-09 15:08:12 +00008420
Douglas Gregora16548e2009-08-11 05:31:07 +00008421 if (!getDerived().AlwaysRebuild() &&
John McCalled7b2782012-04-06 18:20:53 +00008422 SubStmt.get() == E->getSubStmt()) {
8423 // Calling this an 'error' is unintuitive, but it does the right thing.
8424 SemaRef.ActOnStmtExprError();
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008425 return SemaRef.MaybeBindToTemporary(E);
John McCalled7b2782012-04-06 18:20:53 +00008426 }
Mike Stump11289f42009-09-09 15:08:12 +00008427
8428 return getDerived().RebuildStmtExpr(E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008429 SubStmt.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008430 E->getRParenLoc());
8431}
Mike Stump11289f42009-09-09 15:08:12 +00008432
Douglas Gregora16548e2009-08-11 05:31:07 +00008433template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008434ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008435TreeTransform<Derived>::TransformChooseExpr(ChooseExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008436 ExprResult Cond = getDerived().TransformExpr(E->getCond());
Douglas Gregora16548e2009-08-11 05:31:07 +00008437 if (Cond.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008438 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008439
John McCalldadc5752010-08-24 06:29:42 +00008440 ExprResult LHS = getDerived().TransformExpr(E->getLHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008441 if (LHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008442 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008443
John McCalldadc5752010-08-24 06:29:42 +00008444 ExprResult RHS = getDerived().TransformExpr(E->getRHS());
Douglas Gregora16548e2009-08-11 05:31:07 +00008445 if (RHS.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008446 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008447
Douglas Gregora16548e2009-08-11 05:31:07 +00008448 if (!getDerived().AlwaysRebuild() &&
8449 Cond.get() == E->getCond() &&
8450 LHS.get() == E->getLHS() &&
8451 RHS.get() == E->getRHS())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008452 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008453
Douglas Gregora16548e2009-08-11 05:31:07 +00008454 return getDerived().RebuildChooseExpr(E->getBuiltinLoc(),
John McCallb268a282010-08-23 23:25:46 +00008455 Cond.get(), LHS.get(), RHS.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008456 E->getRParenLoc());
8457}
Mike Stump11289f42009-09-09 15:08:12 +00008458
Douglas Gregora16548e2009-08-11 05:31:07 +00008459template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008460ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008461TreeTransform<Derived>::TransformGNUNullExpr(GNUNullExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008462 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008463}
8464
8465template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008466ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008467TreeTransform<Derived>::TransformCXXOperatorCallExpr(CXXOperatorCallExpr *E) {
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008468 switch (E->getOperator()) {
8469 case OO_New:
8470 case OO_Delete:
8471 case OO_Array_New:
8472 case OO_Array_Delete:
8473 llvm_unreachable("new and delete operators cannot use CXXOperatorCallExpr");
Chad Rosier1dcde962012-08-08 18:46:20 +00008474
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008475 case OO_Call: {
8476 // This is a call to an object's operator().
8477 assert(E->getNumArgs() >= 1 && "Object call is missing arguments");
8478
8479 // Transform the object itself.
John McCalldadc5752010-08-24 06:29:42 +00008480 ExprResult Object = getDerived().TransformExpr(E->getArg(0));
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008481 if (Object.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008482 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008483
8484 // FIXME: Poor location information
Alp Tokerb6cc5922014-05-03 03:45:55 +00008485 SourceLocation FakeLParenLoc = SemaRef.getLocForEndOfToken(
8486 static_cast<Expr *>(Object.get())->getLocEnd());
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008487
8488 // Transform the call arguments.
Benjamin Kramerf0623432012-08-23 22:51:59 +00008489 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008490 if (getDerived().TransformExprs(E->getArgs() + 1, E->getNumArgs() - 1, true,
Douglas Gregora3efea12011-01-03 19:04:46 +00008491 Args))
8492 return ExprError();
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008493
John McCallb268a282010-08-23 23:25:46 +00008494 return getDerived().RebuildCallExpr(Object.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008495 Args,
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008496 E->getLocEnd());
8497 }
8498
8499#define OVERLOADED_OPERATOR(Name,Spelling,Token,Unary,Binary,MemberOnly) \
8500 case OO_##Name:
8501#define OVERLOADED_OPERATOR_MULTI(Name,Spelling,Unary,Binary,MemberOnly)
8502#include "clang/Basic/OperatorKinds.def"
8503 case OO_Subscript:
8504 // Handled below.
8505 break;
8506
8507 case OO_Conditional:
8508 llvm_unreachable("conditional operator is not actually overloadable");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008509
8510 case OO_None:
8511 case NUM_OVERLOADED_OPERATORS:
8512 llvm_unreachable("not an overloaded operator?");
Douglas Gregorb08f1a72009-12-13 20:44:55 +00008513 }
8514
John McCalldadc5752010-08-24 06:29:42 +00008515 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
Douglas Gregora16548e2009-08-11 05:31:07 +00008516 if (Callee.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008517 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008518
Richard Smithdb2630f2012-10-21 03:28:35 +00008519 ExprResult First;
8520 if (E->getOperator() == OO_Amp)
8521 First = getDerived().TransformAddressOfOperand(E->getArg(0));
8522 else
8523 First = getDerived().TransformExpr(E->getArg(0));
Douglas Gregora16548e2009-08-11 05:31:07 +00008524 if (First.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008525 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008526
John McCalldadc5752010-08-24 06:29:42 +00008527 ExprResult Second;
Douglas Gregora16548e2009-08-11 05:31:07 +00008528 if (E->getNumArgs() == 2) {
8529 Second = getDerived().TransformExpr(E->getArg(1));
8530 if (Second.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008531 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00008532 }
Mike Stump11289f42009-09-09 15:08:12 +00008533
Douglas Gregora16548e2009-08-11 05:31:07 +00008534 if (!getDerived().AlwaysRebuild() &&
8535 Callee.get() == E->getCallee() &&
8536 First.get() == E->getArg(0) &&
Mike Stump11289f42009-09-09 15:08:12 +00008537 (E->getNumArgs() != 2 || Second.get() == E->getArg(1)))
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008538 return SemaRef.MaybeBindToTemporary(E);
Mike Stump11289f42009-09-09 15:08:12 +00008539
Lang Hames5de91cc2012-10-02 04:45:10 +00008540 Sema::FPContractStateRAII FPContractState(getSema());
8541 getSema().FPFeatures.fp_contract = E->isFPContractable();
8542
Douglas Gregora16548e2009-08-11 05:31:07 +00008543 return getDerived().RebuildCXXOperatorCallExpr(E->getOperator(),
8544 E->getOperatorLoc(),
John McCallb268a282010-08-23 23:25:46 +00008545 Callee.get(),
8546 First.get(),
8547 Second.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008548}
Mike Stump11289f42009-09-09 15:08:12 +00008549
Douglas Gregora16548e2009-08-11 05:31:07 +00008550template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008551ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008552TreeTransform<Derived>::TransformCXXMemberCallExpr(CXXMemberCallExpr *E) {
8553 return getDerived().TransformCallExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008554}
Mike Stump11289f42009-09-09 15:08:12 +00008555
Douglas Gregora16548e2009-08-11 05:31:07 +00008556template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008557ExprResult
Peter Collingbourne41f85462011-02-09 21:07:24 +00008558TreeTransform<Derived>::TransformCUDAKernelCallExpr(CUDAKernelCallExpr *E) {
8559 // Transform the callee.
8560 ExprResult Callee = getDerived().TransformExpr(E->getCallee());
8561 if (Callee.isInvalid())
8562 return ExprError();
8563
8564 // Transform exec config.
8565 ExprResult EC = getDerived().TransformCallExpr(E->getConfig());
8566 if (EC.isInvalid())
8567 return ExprError();
8568
8569 // Transform arguments.
8570 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008571 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00008572 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008573 &ArgChanged))
8574 return ExprError();
8575
8576 if (!getDerived().AlwaysRebuild() &&
8577 Callee.get() == E->getCallee() &&
8578 !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +00008579 return SemaRef.MaybeBindToTemporary(E);
Peter Collingbourne41f85462011-02-09 21:07:24 +00008580
8581 // FIXME: Wrong source location information for the '('.
8582 SourceLocation FakeLParenLoc
8583 = ((Expr *)Callee.get())->getSourceRange().getBegin();
8584 return getDerived().RebuildCallExpr(Callee.get(), FakeLParenLoc,
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008585 Args,
Peter Collingbourne41f85462011-02-09 21:07:24 +00008586 E->getRParenLoc(), EC.get());
8587}
8588
8589template<typename Derived>
8590ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008591TreeTransform<Derived>::TransformCXXNamedCastExpr(CXXNamedCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008592 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8593 if (!Type)
8594 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008595
John McCalldadc5752010-08-24 06:29:42 +00008596 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008597 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008598 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008599 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008600
Douglas Gregora16548e2009-08-11 05:31:07 +00008601 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008602 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008603 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008604 return E;
Nico Weberc153d242014-07-28 00:02:09 +00008605 return getDerived().RebuildCXXNamedCastExpr(
8606 E->getOperatorLoc(), E->getStmtClass(), E->getAngleBrackets().getBegin(),
8607 Type, E->getAngleBrackets().getEnd(),
8608 // FIXME. this should be '(' location
8609 E->getAngleBrackets().getEnd(), SubExpr.get(), E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008610}
Mike Stump11289f42009-09-09 15:08:12 +00008611
Douglas Gregora16548e2009-08-11 05:31:07 +00008612template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008613ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008614TreeTransform<Derived>::TransformCXXStaticCastExpr(CXXStaticCastExpr *E) {
8615 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008616}
Mike Stump11289f42009-09-09 15:08:12 +00008617
8618template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008619ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008620TreeTransform<Derived>::TransformCXXDynamicCastExpr(CXXDynamicCastExpr *E) {
8621 return getDerived().TransformCXXNamedCastExpr(E);
Mike Stump11289f42009-09-09 15:08:12 +00008622}
8623
Douglas Gregora16548e2009-08-11 05:31:07 +00008624template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008625ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008626TreeTransform<Derived>::TransformCXXReinterpretCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008627 CXXReinterpretCastExpr *E) {
8628 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008629}
Mike Stump11289f42009-09-09 15:08:12 +00008630
Douglas Gregora16548e2009-08-11 05:31:07 +00008631template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008632ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008633TreeTransform<Derived>::TransformCXXConstCastExpr(CXXConstCastExpr *E) {
8634 return getDerived().TransformCXXNamedCastExpr(E);
Douglas Gregora16548e2009-08-11 05:31:07 +00008635}
Mike Stump11289f42009-09-09 15:08:12 +00008636
Douglas Gregora16548e2009-08-11 05:31:07 +00008637template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008638ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008639TreeTransform<Derived>::TransformCXXFunctionalCastExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008640 CXXFunctionalCastExpr *E) {
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008641 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeInfoAsWritten());
8642 if (!Type)
8643 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008644
John McCalldadc5752010-08-24 06:29:42 +00008645 ExprResult SubExpr
Douglas Gregord196a582009-12-14 19:27:10 +00008646 = getDerived().TransformExpr(E->getSubExprAsWritten());
Douglas Gregora16548e2009-08-11 05:31:07 +00008647 if (SubExpr.isInvalid())
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 Gregor3b29b2c2010-09-09 16:55:46 +00008651 Type == E->getTypeInfoAsWritten() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008652 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008653 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008654
Douglas Gregor3b29b2c2010-09-09 16:55:46 +00008655 return getDerived().RebuildCXXFunctionalCastExpr(Type,
Eli Friedman89fe0d52013-08-15 22:02:56 +00008656 E->getLParenLoc(),
John McCallb268a282010-08-23 23:25:46 +00008657 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008658 E->getRParenLoc());
8659}
Mike Stump11289f42009-09-09 15:08:12 +00008660
Douglas Gregora16548e2009-08-11 05:31:07 +00008661template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008662ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008663TreeTransform<Derived>::TransformCXXTypeidExpr(CXXTypeidExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008664 if (E->isTypeOperand()) {
Douglas Gregor9da64192010-04-26 22:37:10 +00008665 TypeSourceInfo *TInfo
8666 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8667 if (!TInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008668 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008669
Douglas Gregora16548e2009-08-11 05:31:07 +00008670 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor9da64192010-04-26 22:37:10 +00008671 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008672 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008673
Douglas Gregor9da64192010-04-26 22:37:10 +00008674 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8675 E->getLocStart(),
8676 TInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +00008677 E->getLocEnd());
8678 }
Mike Stump11289f42009-09-09 15:08:12 +00008679
Eli Friedman456f0182012-01-20 01:26:23 +00008680 // We don't know whether the subexpression is potentially evaluated until
8681 // after we perform semantic analysis. We speculatively assume it is
8682 // unevaluated; it will get fixed later if the subexpression is in fact
Douglas Gregora16548e2009-08-11 05:31:07 +00008683 // potentially evaluated.
Eli Friedman15681d62012-09-26 04:34:21 +00008684 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated,
8685 Sema::ReuseLambdaContextDecl);
Mike Stump11289f42009-09-09 15:08:12 +00008686
John McCalldadc5752010-08-24 06:29:42 +00008687 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
Douglas Gregora16548e2009-08-11 05:31:07 +00008688 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008689 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008690
Douglas Gregora16548e2009-08-11 05:31:07 +00008691 if (!getDerived().AlwaysRebuild() &&
8692 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008693 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008694
Douglas Gregor9da64192010-04-26 22:37:10 +00008695 return getDerived().RebuildCXXTypeidExpr(E->getType(),
8696 E->getLocStart(),
John McCallb268a282010-08-23 23:25:46 +00008697 SubExpr.get(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008698 E->getLocEnd());
8699}
8700
8701template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008702ExprResult
Francois Pichet9f4f2072010-09-08 12:20:18 +00008703TreeTransform<Derived>::TransformCXXUuidofExpr(CXXUuidofExpr *E) {
8704 if (E->isTypeOperand()) {
8705 TypeSourceInfo *TInfo
8706 = getDerived().TransformType(E->getTypeOperandSourceInfo());
8707 if (!TInfo)
8708 return ExprError();
8709
8710 if (!getDerived().AlwaysRebuild() &&
8711 TInfo == E->getTypeOperandSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008712 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008713
Douglas Gregor69735112011-03-06 17:40:41 +00008714 return getDerived().RebuildCXXUuidofExpr(E->getType(),
Francois Pichet9f4f2072010-09-08 12:20:18 +00008715 E->getLocStart(),
8716 TInfo,
8717 E->getLocEnd());
8718 }
8719
Francois Pichet9f4f2072010-09-08 12:20:18 +00008720 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
8721
8722 ExprResult SubExpr = getDerived().TransformExpr(E->getExprOperand());
8723 if (SubExpr.isInvalid())
8724 return ExprError();
8725
8726 if (!getDerived().AlwaysRebuild() &&
8727 SubExpr.get() == E->getExprOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008728 return E;
Francois Pichet9f4f2072010-09-08 12:20:18 +00008729
8730 return getDerived().RebuildCXXUuidofExpr(E->getType(),
8731 E->getLocStart(),
8732 SubExpr.get(),
8733 E->getLocEnd());
8734}
8735
8736template<typename Derived>
8737ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008738TreeTransform<Derived>::TransformCXXBoolLiteralExpr(CXXBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008739 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008740}
Mike Stump11289f42009-09-09 15:08:12 +00008741
Douglas Gregora16548e2009-08-11 05:31:07 +00008742template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008743ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00008744TreeTransform<Derived>::TransformCXXNullPtrLiteralExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008745 CXXNullPtrLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008746 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008747}
Mike Stump11289f42009-09-09 15:08:12 +00008748
Douglas Gregora16548e2009-08-11 05:31:07 +00008749template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008750ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008751TreeTransform<Derived>::TransformCXXThisExpr(CXXThisExpr *E) {
Richard Smithc3d2ebb2013-06-07 02:33:37 +00008752 QualType T = getSema().getCurrentThisType();
Mike Stump11289f42009-09-09 15:08:12 +00008753
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008754 if (!getDerived().AlwaysRebuild() && T == E->getType()) {
8755 // Make sure that we capture 'this'.
8756 getSema().CheckCXXThisCapture(E->getLocStart());
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008757 return E;
Douglas Gregor3a08c1c2012-02-24 17:41:38 +00008758 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008759
Douglas Gregorb15af892010-01-07 23:12:05 +00008760 return getDerived().RebuildCXXThisExpr(E->getLocStart(), T, E->isImplicit());
Douglas Gregora16548e2009-08-11 05:31:07 +00008761}
Mike Stump11289f42009-09-09 15:08:12 +00008762
Douglas Gregora16548e2009-08-11 05:31:07 +00008763template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008764ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008765TreeTransform<Derived>::TransformCXXThrowExpr(CXXThrowExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008766 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00008767 if (SubExpr.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008768 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008769
Douglas Gregora16548e2009-08-11 05:31:07 +00008770 if (!getDerived().AlwaysRebuild() &&
8771 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008772 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +00008773
Douglas Gregor53e191ed2011-07-06 22:04:06 +00008774 return getDerived().RebuildCXXThrowExpr(E->getThrowLoc(), SubExpr.get(),
8775 E->isThrownVariableInScope());
Douglas Gregora16548e2009-08-11 05:31:07 +00008776}
Mike Stump11289f42009-09-09 15:08:12 +00008777
Douglas Gregora16548e2009-08-11 05:31:07 +00008778template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008779ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008780TreeTransform<Derived>::TransformCXXDefaultArgExpr(CXXDefaultArgExpr *E) {
Mike Stump11289f42009-09-09 15:08:12 +00008781 ParmVarDecl *Param
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008782 = cast_or_null<ParmVarDecl>(getDerived().TransformDecl(E->getLocStart(),
8783 E->getParam()));
Douglas Gregora16548e2009-08-11 05:31:07 +00008784 if (!Param)
John McCallfaf5fb42010-08-26 23:41:50 +00008785 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008786
Chandler Carruth794da4c2010-02-08 06:42:49 +00008787 if (!getDerived().AlwaysRebuild() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008788 Param == E->getParam())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008789 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008790
Douglas Gregor033f6752009-12-23 23:03:06 +00008791 return getDerived().RebuildCXXDefaultArgExpr(E->getUsedLocation(), Param);
Douglas Gregora16548e2009-08-11 05:31:07 +00008792}
Mike Stump11289f42009-09-09 15:08:12 +00008793
Douglas Gregora16548e2009-08-11 05:31:07 +00008794template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008795ExprResult
Richard Smith852c9db2013-04-20 22:23:05 +00008796TreeTransform<Derived>::TransformCXXDefaultInitExpr(CXXDefaultInitExpr *E) {
8797 FieldDecl *Field
8798 = cast_or_null<FieldDecl>(getDerived().TransformDecl(E->getLocStart(),
8799 E->getField()));
8800 if (!Field)
8801 return ExprError();
8802
8803 if (!getDerived().AlwaysRebuild() && Field == E->getField())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008804 return E;
Richard Smith852c9db2013-04-20 22:23:05 +00008805
8806 return getDerived().RebuildCXXDefaultInitExpr(E->getExprLoc(), Field);
8807}
8808
8809template<typename Derived>
8810ExprResult
Douglas Gregor2b88c112010-09-08 00:15:04 +00008811TreeTransform<Derived>::TransformCXXScalarValueInitExpr(
8812 CXXScalarValueInitExpr *E) {
8813 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
8814 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00008815 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00008816
Douglas Gregora16548e2009-08-11 05:31:07 +00008817 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00008818 T == E->getTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008819 return E;
Mike Stump11289f42009-09-09 15:08:12 +00008820
Chad Rosier1dcde962012-08-08 18:46:20 +00008821 return getDerived().RebuildCXXScalarValueInitExpr(T,
Douglas Gregor2b88c112010-09-08 00:15:04 +00008822 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Douglas Gregor747eb782010-07-08 06:14:04 +00008823 E->getRParenLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +00008824}
Mike Stump11289f42009-09-09 15:08:12 +00008825
Douglas Gregora16548e2009-08-11 05:31:07 +00008826template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008827ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008828TreeTransform<Derived>::TransformCXXNewExpr(CXXNewExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00008829 // Transform the type that we're allocating
Douglas Gregor0744ef62010-09-07 21:49:58 +00008830 TypeSourceInfo *AllocTypeInfo
8831 = getDerived().TransformType(E->getAllocatedTypeSourceInfo());
8832 if (!AllocTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00008833 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008834
Douglas Gregora16548e2009-08-11 05:31:07 +00008835 // Transform the size of the array we're allocating (if any).
John McCalldadc5752010-08-24 06:29:42 +00008836 ExprResult ArraySize = getDerived().TransformExpr(E->getArraySize());
Douglas Gregora16548e2009-08-11 05:31:07 +00008837 if (ArraySize.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008838 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008839
Douglas Gregora16548e2009-08-11 05:31:07 +00008840 // Transform the placement arguments (if any).
8841 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00008842 SmallVector<Expr*, 8> PlacementArgs;
Chad Rosier1dcde962012-08-08 18:46:20 +00008843 if (getDerived().TransformExprs(E->getPlacementArgs(),
Douglas Gregora3efea12011-01-03 19:04:46 +00008844 E->getNumPlacementArgs(), true,
8845 PlacementArgs, &ArgumentChanged))
Sebastian Redl6047f072012-02-16 12:22:20 +00008846 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008847
Sebastian Redl6047f072012-02-16 12:22:20 +00008848 // Transform the initializer (if any).
8849 Expr *OldInit = E->getInitializer();
8850 ExprResult NewInit;
8851 if (OldInit)
Richard Smithc6abd962014-07-25 01:12:44 +00008852 NewInit = getDerived().TransformInitializer(OldInit, true);
Sebastian Redl6047f072012-02-16 12:22:20 +00008853 if (NewInit.isInvalid())
8854 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008855
Sebastian Redl6047f072012-02-16 12:22:20 +00008856 // Transform new operator and delete operator.
Craig Topperc3ec1492014-05-26 06:22:03 +00008857 FunctionDecl *OperatorNew = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008858 if (E->getOperatorNew()) {
8859 OperatorNew = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008860 getDerived().TransformDecl(E->getLocStart(),
8861 E->getOperatorNew()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008862 if (!OperatorNew)
John McCallfaf5fb42010-08-26 23:41:50 +00008863 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008864 }
8865
Craig Topperc3ec1492014-05-26 06:22:03 +00008866 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008867 if (E->getOperatorDelete()) {
8868 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008869 getDerived().TransformDecl(E->getLocStart(),
8870 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008871 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008872 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008873 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008874
Douglas Gregora16548e2009-08-11 05:31:07 +00008875 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor0744ef62010-09-07 21:49:58 +00008876 AllocTypeInfo == E->getAllocatedTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00008877 ArraySize.get() == E->getArraySize() &&
Sebastian Redl6047f072012-02-16 12:22:20 +00008878 NewInit.get() == OldInit &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008879 OperatorNew == E->getOperatorNew() &&
8880 OperatorDelete == E->getOperatorDelete() &&
8881 !ArgumentChanged) {
8882 // Mark any declarations we need as referenced.
8883 // FIXME: instantiation-specific.
Douglas Gregord2d9da02010-02-26 00:38:10 +00008884 if (OperatorNew)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008885 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorNew);
Douglas Gregord2d9da02010-02-26 00:38:10 +00008886 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008887 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008888
Sebastian Redl6047f072012-02-16 12:22:20 +00008889 if (E->isArray() && !E->getAllocatedType()->isDependentType()) {
Douglas Gregor72912fb2011-07-26 15:11:03 +00008890 QualType ElementType
8891 = SemaRef.Context.getBaseElementType(E->getAllocatedType());
8892 if (const RecordType *RecordT = ElementType->getAs<RecordType>()) {
8893 CXXRecordDecl *Record = cast<CXXRecordDecl>(RecordT->getDecl());
8894 if (CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(Record)) {
Eli Friedmanfa0df832012-02-02 03:46:19 +00008895 SemaRef.MarkFunctionReferenced(E->getLocStart(), Destructor);
Douglas Gregor72912fb2011-07-26 15:11:03 +00008896 }
8897 }
8898 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008899
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008900 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008901 }
Mike Stump11289f42009-09-09 15:08:12 +00008902
Douglas Gregor0744ef62010-09-07 21:49:58 +00008903 QualType AllocType = AllocTypeInfo->getType();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008904 if (!ArraySize.get()) {
8905 // If no array size was specified, but the new expression was
8906 // instantiated with an array type (e.g., "new T" where T is
8907 // instantiated with "int[4]"), extract the outer bound from the
8908 // array type as our array size. We do this with constant and
8909 // dependently-sized array types.
8910 const ArrayType *ArrayT = SemaRef.Context.getAsArrayType(AllocType);
8911 if (!ArrayT) {
8912 // Do nothing
8913 } else if (const ConstantArrayType *ConsArrayT
8914 = dyn_cast<ConstantArrayType>(ArrayT)) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008915 ArraySize = IntegerLiteral::Create(SemaRef.Context, ConsArrayT->getSize(),
8916 SemaRef.Context.getSizeType(),
8917 /*FIXME:*/ E->getLocStart());
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008918 AllocType = ConsArrayT->getElementType();
8919 } else if (const DependentSizedArrayType *DepArrayT
8920 = dyn_cast<DependentSizedArrayType>(ArrayT)) {
8921 if (DepArrayT->getSizeExpr()) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008922 ArraySize = DepArrayT->getSizeExpr();
Douglas Gregor2e9c7952009-12-22 17:13:37 +00008923 AllocType = DepArrayT->getElementType();
8924 }
8925 }
8926 }
Sebastian Redl6047f072012-02-16 12:22:20 +00008927
Douglas Gregora16548e2009-08-11 05:31:07 +00008928 return getDerived().RebuildCXXNewExpr(E->getLocStart(),
8929 E->isGlobalNew(),
8930 /*FIXME:*/E->getLocStart(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00008931 PlacementArgs,
Douglas Gregora16548e2009-08-11 05:31:07 +00008932 /*FIXME:*/E->getLocStart(),
Douglas Gregorf2753b32010-07-13 15:54:32 +00008933 E->getTypeIdParens(),
Douglas Gregora16548e2009-08-11 05:31:07 +00008934 AllocType,
Douglas Gregor0744ef62010-09-07 21:49:58 +00008935 AllocTypeInfo,
John McCallb268a282010-08-23 23:25:46 +00008936 ArraySize.get(),
Sebastian Redl6047f072012-02-16 12:22:20 +00008937 E->getDirectInitRange(),
Nikola Smiljanic01a75982014-05-29 10:55:11 +00008938 NewInit.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008939}
Mike Stump11289f42009-09-09 15:08:12 +00008940
Douglas Gregora16548e2009-08-11 05:31:07 +00008941template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008942ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00008943TreeTransform<Derived>::TransformCXXDeleteExpr(CXXDeleteExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008944 ExprResult Operand = getDerived().TransformExpr(E->getArgument());
Douglas Gregora16548e2009-08-11 05:31:07 +00008945 if (Operand.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008946 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008947
Douglas Gregord2d9da02010-02-26 00:38:10 +00008948 // Transform the delete operator, if known.
Craig Topperc3ec1492014-05-26 06:22:03 +00008949 FunctionDecl *OperatorDelete = nullptr;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008950 if (E->getOperatorDelete()) {
8951 OperatorDelete = cast_or_null<FunctionDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00008952 getDerived().TransformDecl(E->getLocStart(),
8953 E->getOperatorDelete()));
Douglas Gregord2d9da02010-02-26 00:38:10 +00008954 if (!OperatorDelete)
John McCallfaf5fb42010-08-26 23:41:50 +00008955 return ExprError();
Douglas Gregord2d9da02010-02-26 00:38:10 +00008956 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008957
Douglas Gregora16548e2009-08-11 05:31:07 +00008958 if (!getDerived().AlwaysRebuild() &&
Douglas Gregord2d9da02010-02-26 00:38:10 +00008959 Operand.get() == E->getArgument() &&
8960 OperatorDelete == E->getOperatorDelete()) {
8961 // Mark any declarations we need as referenced.
8962 // FIXME: instantiation-specific.
8963 if (OperatorDelete)
Eli Friedmanfa0df832012-02-02 03:46:19 +00008964 SemaRef.MarkFunctionReferenced(E->getLocStart(), OperatorDelete);
Chad Rosier1dcde962012-08-08 18:46:20 +00008965
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008966 if (!E->getArgument()->isTypeDependent()) {
8967 QualType Destroyed = SemaRef.Context.getBaseElementType(
8968 E->getDestroyedType());
8969 if (const RecordType *DestroyedRec = Destroyed->getAs<RecordType>()) {
8970 CXXRecordDecl *Record = cast<CXXRecordDecl>(DestroyedRec->getDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +00008971 SemaRef.MarkFunctionReferenced(E->getLocStart(),
Eli Friedmanfa0df832012-02-02 03:46:19 +00008972 SemaRef.LookupDestructor(Record));
Douglas Gregor6ed2fee2010-09-14 22:55:20 +00008973 }
8974 }
Chad Rosier1dcde962012-08-08 18:46:20 +00008975
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00008976 return E;
Douglas Gregord2d9da02010-02-26 00:38:10 +00008977 }
Mike Stump11289f42009-09-09 15:08:12 +00008978
Douglas Gregora16548e2009-08-11 05:31:07 +00008979 return getDerived().RebuildCXXDeleteExpr(E->getLocStart(),
8980 E->isGlobalDelete(),
8981 E->isArrayForm(),
John McCallb268a282010-08-23 23:25:46 +00008982 Operand.get());
Douglas Gregora16548e2009-08-11 05:31:07 +00008983}
Mike Stump11289f42009-09-09 15:08:12 +00008984
Douglas Gregora16548e2009-08-11 05:31:07 +00008985template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00008986ExprResult
Douglas Gregorad8a3362009-09-04 17:36:40 +00008987TreeTransform<Derived>::TransformCXXPseudoDestructorExpr(
John McCall47f29ea2009-12-08 09:21:05 +00008988 CXXPseudoDestructorExpr *E) {
John McCalldadc5752010-08-24 06:29:42 +00008989 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregorad8a3362009-09-04 17:36:40 +00008990 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00008991 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00008992
John McCallba7bf592010-08-24 05:47:05 +00008993 ParsedType ObjectTypePtr;
Douglas Gregor678f90d2010-02-25 01:56:36 +00008994 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00008995 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00008996 E->getOperatorLoc(),
8997 E->isArrow()? tok::arrow : tok::period,
8998 ObjectTypePtr,
8999 MayBePseudoDestructor);
9000 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009001 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009002
John McCallba7bf592010-08-24 05:47:05 +00009003 QualType ObjectType = ObjectTypePtr.get();
Douglas Gregora6ce6082011-02-25 18:19:59 +00009004 NestedNameSpecifierLoc QualifierLoc = E->getQualifierLoc();
9005 if (QualifierLoc) {
9006 QualifierLoc
9007 = getDerived().TransformNestedNameSpecifierLoc(QualifierLoc, ObjectType);
9008 if (!QualifierLoc)
John McCall31f82722010-11-12 08:19:04 +00009009 return ExprError();
9010 }
Douglas Gregora6ce6082011-02-25 18:19:59 +00009011 CXXScopeSpec SS;
9012 SS.Adopt(QualifierLoc);
Mike Stump11289f42009-09-09 15:08:12 +00009013
Douglas Gregor678f90d2010-02-25 01:56:36 +00009014 PseudoDestructorTypeStorage Destroyed;
9015 if (E->getDestroyedTypeInfo()) {
9016 TypeSourceInfo *DestroyedTypeInfo
John McCall31f82722010-11-12 08:19:04 +00009017 = getDerived().TransformTypeInObjectScope(E->getDestroyedTypeInfo(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009018 ObjectType, nullptr, SS);
Douglas Gregor678f90d2010-02-25 01:56:36 +00009019 if (!DestroyedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009020 return ExprError();
Douglas Gregor678f90d2010-02-25 01:56:36 +00009021 Destroyed = DestroyedTypeInfo;
Douglas Gregorf39a8dd2011-11-09 02:19:47 +00009022 } else if (!ObjectType.isNull() && ObjectType->isDependentType()) {
Douglas Gregor678f90d2010-02-25 01:56:36 +00009023 // We aren't likely to be able to resolve the identifier down to a type
9024 // now anyway, so just retain the identifier.
9025 Destroyed = PseudoDestructorTypeStorage(E->getDestroyedTypeIdentifier(),
9026 E->getDestroyedTypeLoc());
9027 } else {
9028 // Look for a destructor known with the given name.
John McCallba7bf592010-08-24 05:47:05 +00009029 ParsedType T = SemaRef.getDestructorName(E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009030 *E->getDestroyedTypeIdentifier(),
9031 E->getDestroyedTypeLoc(),
Craig Topperc3ec1492014-05-26 06:22:03 +00009032 /*Scope=*/nullptr,
Douglas Gregor678f90d2010-02-25 01:56:36 +00009033 SS, ObjectTypePtr,
9034 false);
9035 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009036 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009037
Douglas Gregor678f90d2010-02-25 01:56:36 +00009038 Destroyed
9039 = SemaRef.Context.getTrivialTypeSourceInfo(SemaRef.GetTypeFromParser(T),
9040 E->getDestroyedTypeLoc());
9041 }
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009042
Craig Topperc3ec1492014-05-26 06:22:03 +00009043 TypeSourceInfo *ScopeTypeInfo = nullptr;
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009044 if (E->getScopeTypeInfo()) {
Douglas Gregora88c55b2013-03-08 21:25:01 +00009045 CXXScopeSpec EmptySS;
9046 ScopeTypeInfo = getDerived().TransformTypeInObjectScope(
Craig Topperc3ec1492014-05-26 06:22:03 +00009047 E->getScopeTypeInfo(), ObjectType, nullptr, EmptySS);
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009048 if (!ScopeTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +00009049 return ExprError();
Douglas Gregorad8a3362009-09-04 17:36:40 +00009050 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009051
John McCallb268a282010-08-23 23:25:46 +00009052 return getDerived().RebuildCXXPseudoDestructorExpr(Base.get(),
Douglas Gregorad8a3362009-09-04 17:36:40 +00009053 E->getOperatorLoc(),
9054 E->isArrow(),
Douglas Gregora6ce6082011-02-25 18:19:59 +00009055 SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +00009056 ScopeTypeInfo,
9057 E->getColonColonLoc(),
Douglas Gregorcdbd5152010-02-24 23:50:37 +00009058 E->getTildeLoc(),
Douglas Gregor678f90d2010-02-25 01:56:36 +00009059 Destroyed);
Douglas Gregorad8a3362009-09-04 17:36:40 +00009060}
Mike Stump11289f42009-09-09 15:08:12 +00009061
Douglas Gregorad8a3362009-09-04 17:36:40 +00009062template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009063ExprResult
John McCalld14a8642009-11-21 08:51:07 +00009064TreeTransform<Derived>::TransformUnresolvedLookupExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009065 UnresolvedLookupExpr *Old) {
John McCalle66edc12009-11-24 19:00:30 +00009066 LookupResult R(SemaRef, Old->getName(), Old->getNameLoc(),
9067 Sema::LookupOrdinaryName);
9068
9069 // Transform all the decls.
9070 for (UnresolvedLookupExpr::decls_iterator I = Old->decls_begin(),
9071 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009072 NamedDecl *InstD = static_cast<NamedDecl*>(
9073 getDerived().TransformDecl(Old->getNameLoc(),
9074 *I));
John McCall84d87672009-12-10 09:41:52 +00009075 if (!InstD) {
9076 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9077 // This can happen because of dependent hiding.
9078 if (isa<UsingShadowDecl>(*I))
9079 continue;
Serge Pavlov82605302013-09-04 04:50:29 +00009080 else {
9081 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009082 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009083 }
John McCall84d87672009-12-10 09:41:52 +00009084 }
John McCalle66edc12009-11-24 19:00:30 +00009085
9086 // Expand using declarations.
9087 if (isa<UsingDecl>(InstD)) {
9088 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009089 for (auto *I : UD->shadows())
9090 R.addDecl(I);
John McCalle66edc12009-11-24 19:00:30 +00009091 continue;
9092 }
9093
9094 R.addDecl(InstD);
9095 }
9096
9097 // Resolve a kind, but don't do any further analysis. If it's
9098 // ambiguous, the callee needs to deal with it.
9099 R.resolveKind();
9100
9101 // Rebuild the nested-name qualifier, if present.
9102 CXXScopeSpec SS;
Douglas Gregor0da1d432011-02-28 20:01:57 +00009103 if (Old->getQualifierLoc()) {
9104 NestedNameSpecifierLoc QualifierLoc
9105 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9106 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009107 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009108
Douglas Gregor0da1d432011-02-28 20:01:57 +00009109 SS.Adopt(QualifierLoc);
Chad Rosier1dcde962012-08-08 18:46:20 +00009110 }
9111
Douglas Gregor9262f472010-04-27 18:19:34 +00009112 if (Old->getNamingClass()) {
Douglas Gregorda7be082010-04-27 16:10:10 +00009113 CXXRecordDecl *NamingClass
9114 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
9115 Old->getNameLoc(),
9116 Old->getNamingClass()));
Serge Pavlov82605302013-09-04 04:50:29 +00009117 if (!NamingClass) {
9118 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009119 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009120 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009121
Douglas Gregorda7be082010-04-27 16:10:10 +00009122 R.setNamingClass(NamingClass);
John McCalle66edc12009-11-24 19:00:30 +00009123 }
9124
Abramo Bagnara7945c982012-01-27 09:46:47 +00009125 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9126
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009127 // If we have neither explicit template arguments, nor the template keyword,
Reid Kleckner744e3e72015-10-20 21:04:13 +00009128 // it's a normal declaration name or member reference.
9129 if (!Old->hasExplicitTemplateArgs() && !TemplateKWLoc.isValid()) {
9130 NamedDecl *D = R.getAsSingle<NamedDecl>();
9131 // In a C++11 unevaluated context, an UnresolvedLookupExpr might refer to an
9132 // instance member. In other contexts, BuildPossibleImplicitMemberExpr will
9133 // give a good diagnostic.
9134 if (D && D->isCXXInstanceMember()) {
9135 return SemaRef.BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R,
9136 /*TemplateArgs=*/nullptr,
9137 /*Scope=*/nullptr);
9138 }
9139
John McCalle66edc12009-11-24 19:00:30 +00009140 return getDerived().RebuildDeclarationNameExpr(SS, R, Old->requiresADL());
Reid Kleckner744e3e72015-10-20 21:04:13 +00009141 }
John McCalle66edc12009-11-24 19:00:30 +00009142
9143 // If we have template arguments, rebuild them, then rebuild the
9144 // templateid expression.
9145 TemplateArgumentListInfo TransArgs(Old->getLAngleLoc(), Old->getRAngleLoc());
Rafael Espindola3dd531d2012-08-28 04:13:54 +00009146 if (Old->hasExplicitTemplateArgs() &&
9147 getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
Douglas Gregor62e06f22010-12-20 17:31:10 +00009148 Old->getNumTemplateArgs(),
Serge Pavlov82605302013-09-04 04:50:29 +00009149 TransArgs)) {
9150 R.clear();
Douglas Gregor62e06f22010-12-20 17:31:10 +00009151 return ExprError();
Serge Pavlov82605302013-09-04 04:50:29 +00009152 }
John McCalle66edc12009-11-24 19:00:30 +00009153
Abramo Bagnara7945c982012-01-27 09:46:47 +00009154 return getDerived().RebuildTemplateIdExpr(SS, TemplateKWLoc, R,
Abramo Bagnara65f7c3d2012-02-06 14:31:00 +00009155 Old->requiresADL(), &TransArgs);
Douglas Gregora16548e2009-08-11 05:31:07 +00009156}
Mike Stump11289f42009-09-09 15:08:12 +00009157
Douglas Gregora16548e2009-08-11 05:31:07 +00009158template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009159ExprResult
Douglas Gregor29c42f22012-02-24 07:38:34 +00009160TreeTransform<Derived>::TransformTypeTraitExpr(TypeTraitExpr *E) {
9161 bool ArgChanged = false;
Dmitri Gribenkof8579502013-01-12 19:30:44 +00009162 SmallVector<TypeSourceInfo *, 4> Args;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009163 for (unsigned I = 0, N = E->getNumArgs(); I != N; ++I) {
9164 TypeSourceInfo *From = E->getArg(I);
9165 TypeLoc FromTL = From->getTypeLoc();
David Blaikie6adc78e2013-02-18 22:06:02 +00009166 if (!FromTL.getAs<PackExpansionTypeLoc>()) {
Douglas Gregor29c42f22012-02-24 07:38:34 +00009167 TypeLocBuilder TLB;
9168 TLB.reserve(FromTL.getFullDataSize());
9169 QualType To = getDerived().TransformType(TLB, FromTL);
9170 if (To.isNull())
9171 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009172
Douglas Gregor29c42f22012-02-24 07:38:34 +00009173 if (To == From->getType())
9174 Args.push_back(From);
9175 else {
9176 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9177 ArgChanged = true;
9178 }
9179 continue;
9180 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009181
Douglas Gregor29c42f22012-02-24 07:38:34 +00009182 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +00009183
Douglas Gregor29c42f22012-02-24 07:38:34 +00009184 // We have a pack expansion. Instantiate it.
David Blaikie6adc78e2013-02-18 22:06:02 +00009185 PackExpansionTypeLoc ExpansionTL = FromTL.castAs<PackExpansionTypeLoc>();
Douglas Gregor29c42f22012-02-24 07:38:34 +00009186 TypeLoc PatternTL = ExpansionTL.getPatternLoc();
9187 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
9188 SemaRef.collectUnexpandedParameterPacks(PatternTL, Unexpanded);
Chad Rosier1dcde962012-08-08 18:46:20 +00009189
Douglas Gregor29c42f22012-02-24 07:38:34 +00009190 // Determine whether the set of unexpanded parameter packs can and should
9191 // be expanded.
9192 bool Expand = true;
9193 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009194 Optional<unsigned> OrigNumExpansions =
9195 ExpansionTL.getTypePtr()->getNumExpansions();
9196 Optional<unsigned> NumExpansions = OrigNumExpansions;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009197 if (getDerived().TryExpandParameterPacks(ExpansionTL.getEllipsisLoc(),
9198 PatternTL.getSourceRange(),
9199 Unexpanded,
9200 Expand, RetainExpansion,
9201 NumExpansions))
9202 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009203
Douglas Gregor29c42f22012-02-24 07:38:34 +00009204 if (!Expand) {
9205 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +00009206 // transformation on the pack expansion, producing another pack
Douglas Gregor29c42f22012-02-24 07:38:34 +00009207 // expansion.
9208 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
Chad Rosier1dcde962012-08-08 18:46:20 +00009209
Douglas Gregor29c42f22012-02-24 07:38:34 +00009210 TypeLocBuilder TLB;
9211 TLB.reserve(From->getTypeLoc().getFullDataSize());
9212
9213 QualType To = getDerived().TransformType(TLB, PatternTL);
9214 if (To.isNull())
9215 return ExprError();
9216
Chad Rosier1dcde962012-08-08 18:46:20 +00009217 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009218 PatternTL.getSourceRange(),
9219 ExpansionTL.getEllipsisLoc(),
9220 NumExpansions);
9221 if (To.isNull())
9222 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009223
Douglas Gregor29c42f22012-02-24 07:38:34 +00009224 PackExpansionTypeLoc ToExpansionTL
9225 = TLB.push<PackExpansionTypeLoc>(To);
9226 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9227 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9228 continue;
9229 }
9230
9231 // Expand the pack expansion by substituting for each argument in the
9232 // pack(s).
9233 for (unsigned I = 0; I != *NumExpansions; ++I) {
9234 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(SemaRef, I);
9235 TypeLocBuilder TLB;
9236 TLB.reserve(PatternTL.getFullDataSize());
9237 QualType To = getDerived().TransformType(TLB, PatternTL);
9238 if (To.isNull())
9239 return ExprError();
9240
Eli Friedman5e05c4a2013-07-19 21:49:32 +00009241 if (To->containsUnexpandedParameterPack()) {
9242 To = getDerived().RebuildPackExpansionType(To,
9243 PatternTL.getSourceRange(),
9244 ExpansionTL.getEllipsisLoc(),
9245 NumExpansions);
9246 if (To.isNull())
9247 return ExprError();
9248
9249 PackExpansionTypeLoc ToExpansionTL
9250 = TLB.push<PackExpansionTypeLoc>(To);
9251 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9252 }
9253
Douglas Gregor29c42f22012-02-24 07:38:34 +00009254 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9255 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009256
Douglas Gregor29c42f22012-02-24 07:38:34 +00009257 if (!RetainExpansion)
9258 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009259
Douglas Gregor29c42f22012-02-24 07:38:34 +00009260 // If we're supposed to retain a pack expansion, do so by temporarily
9261 // forgetting the partially-substituted parameter pack.
9262 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
9263
9264 TypeLocBuilder TLB;
9265 TLB.reserve(From->getTypeLoc().getFullDataSize());
Chad Rosier1dcde962012-08-08 18:46:20 +00009266
Douglas Gregor29c42f22012-02-24 07:38:34 +00009267 QualType To = getDerived().TransformType(TLB, PatternTL);
9268 if (To.isNull())
9269 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009270
9271 To = getDerived().RebuildPackExpansionType(To,
Douglas Gregor29c42f22012-02-24 07:38:34 +00009272 PatternTL.getSourceRange(),
9273 ExpansionTL.getEllipsisLoc(),
9274 NumExpansions);
9275 if (To.isNull())
9276 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009277
Douglas Gregor29c42f22012-02-24 07:38:34 +00009278 PackExpansionTypeLoc ToExpansionTL
9279 = TLB.push<PackExpansionTypeLoc>(To);
9280 ToExpansionTL.setEllipsisLoc(ExpansionTL.getEllipsisLoc());
9281 Args.push_back(TLB.getTypeSourceInfo(SemaRef.Context, To));
9282 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009283
Douglas Gregor29c42f22012-02-24 07:38:34 +00009284 if (!getDerived().AlwaysRebuild() && !ArgChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009285 return E;
Douglas Gregor29c42f22012-02-24 07:38:34 +00009286
9287 return getDerived().RebuildTypeTrait(E->getTrait(),
9288 E->getLocStart(),
9289 Args,
9290 E->getLocEnd());
9291}
9292
9293template<typename Derived>
9294ExprResult
John Wiegley6242b6a2011-04-28 00:16:57 +00009295TreeTransform<Derived>::TransformArrayTypeTraitExpr(ArrayTypeTraitExpr *E) {
9296 TypeSourceInfo *T = getDerived().TransformType(E->getQueriedTypeSourceInfo());
9297 if (!T)
9298 return ExprError();
9299
9300 if (!getDerived().AlwaysRebuild() &&
9301 T == E->getQueriedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009302 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009303
9304 ExprResult SubExpr;
9305 {
9306 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9307 SubExpr = getDerived().TransformExpr(E->getDimensionExpression());
9308 if (SubExpr.isInvalid())
9309 return ExprError();
9310
9311 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getDimensionExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009312 return E;
John Wiegley6242b6a2011-04-28 00:16:57 +00009313 }
9314
9315 return getDerived().RebuildArrayTypeTrait(E->getTrait(),
9316 E->getLocStart(),
9317 T,
9318 SubExpr.get(),
9319 E->getLocEnd());
9320}
9321
9322template<typename Derived>
9323ExprResult
John Wiegleyf9f65842011-04-25 06:54:41 +00009324TreeTransform<Derived>::TransformExpressionTraitExpr(ExpressionTraitExpr *E) {
9325 ExprResult SubExpr;
9326 {
9327 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
9328 SubExpr = getDerived().TransformExpr(E->getQueriedExpression());
9329 if (SubExpr.isInvalid())
9330 return ExprError();
9331
9332 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getQueriedExpression())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009333 return E;
John Wiegleyf9f65842011-04-25 06:54:41 +00009334 }
9335
9336 return getDerived().RebuildExpressionTrait(
9337 E->getTrait(), E->getLocStart(), SubExpr.get(), E->getLocEnd());
9338}
9339
Reid Kleckner32506ed2014-06-12 23:03:48 +00009340template <typename Derived>
9341ExprResult TreeTransform<Derived>::TransformParenDependentScopeDeclRefExpr(
9342 ParenExpr *PE, DependentScopeDeclRefExpr *DRE, bool AddrTaken,
9343 TypeSourceInfo **RecoveryTSI) {
9344 ExprResult NewDRE = getDerived().TransformDependentScopeDeclRefExpr(
9345 DRE, AddrTaken, RecoveryTSI);
9346
9347 // Propagate both errors and recovered types, which return ExprEmpty.
9348 if (!NewDRE.isUsable())
9349 return NewDRE;
9350
9351 // We got an expr, wrap it up in parens.
9352 if (!getDerived().AlwaysRebuild() && NewDRE.get() == DRE)
9353 return PE;
9354 return getDerived().RebuildParenExpr(NewDRE.get(), PE->getLParen(),
9355 PE->getRParen());
9356}
9357
9358template <typename Derived>
9359ExprResult TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9360 DependentScopeDeclRefExpr *E) {
9361 return TransformDependentScopeDeclRefExpr(E, /*IsAddressOfOperand=*/false,
9362 nullptr);
Richard Smithdb2630f2012-10-21 03:28:35 +00009363}
9364
9365template<typename Derived>
9366ExprResult
9367TreeTransform<Derived>::TransformDependentScopeDeclRefExpr(
9368 DependentScopeDeclRefExpr *E,
Reid Kleckner32506ed2014-06-12 23:03:48 +00009369 bool IsAddressOfOperand,
9370 TypeSourceInfo **RecoveryTSI) {
Reid Kleckner916ac4d2013-10-15 18:38:02 +00009371 assert(E->getQualifierLoc());
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009372 NestedNameSpecifierLoc QualifierLoc
9373 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc());
9374 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009375 return ExprError();
Abramo Bagnara7945c982012-01-27 09:46:47 +00009376 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
Mike Stump11289f42009-09-09 15:08:12 +00009377
John McCall31f82722010-11-12 08:19:04 +00009378 // TODO: If this is a conversion-function-id, verify that the
9379 // destination type name (if present) resolves the same way after
9380 // instantiation as it did in the local scope.
9381
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009382 DeclarationNameInfo NameInfo
9383 = getDerived().TransformDeclarationNameInfo(E->getNameInfo());
9384 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009385 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009386
John McCalle66edc12009-11-24 19:00:30 +00009387 if (!E->hasExplicitTemplateArgs()) {
9388 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor3a43fd62011-02-25 20:49:16 +00009389 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009390 // Note: it is sufficient to compare the Name component of NameInfo:
9391 // if name has not changed, DNLoc has not changed either.
9392 NameInfo.getName() == E->getDeclName())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009393 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009394
Reid Kleckner32506ed2014-06-12 23:03:48 +00009395 return getDerived().RebuildDependentScopeDeclRefExpr(
9396 QualifierLoc, TemplateKWLoc, NameInfo, /*TemplateArgs=*/nullptr,
9397 IsAddressOfOperand, RecoveryTSI);
Douglas Gregord019ff62009-10-22 17:20:55 +00009398 }
John McCall6b51f282009-11-23 01:53:49 +00009399
9400 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009401 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9402 E->getNumTemplateArgs(),
9403 TransArgs))
9404 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009405
Reid Kleckner32506ed2014-06-12 23:03:48 +00009406 return getDerived().RebuildDependentScopeDeclRefExpr(
9407 QualifierLoc, TemplateKWLoc, NameInfo, &TransArgs, IsAddressOfOperand,
9408 RecoveryTSI);
Douglas Gregora16548e2009-08-11 05:31:07 +00009409}
9410
9411template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009412ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009413TreeTransform<Derived>::TransformCXXConstructExpr(CXXConstructExpr *E) {
Richard Smithd59b8322012-12-19 01:39:02 +00009414 // CXXConstructExprs other than for list-initialization and
9415 // CXXTemporaryObjectExpr are always implicit, so when we have
9416 // a 1-argument construction we just transform that argument.
Richard Smithdd2ca572012-11-26 08:32:48 +00009417 if ((E->getNumArgs() == 1 ||
9418 (E->getNumArgs() > 1 && getDerived().DropCallArgument(E->getArg(1)))) &&
Richard Smithd59b8322012-12-19 01:39:02 +00009419 (!getDerived().DropCallArgument(E->getArg(0))) &&
9420 !E->isListInitialization())
Douglas Gregordb56b912010-02-03 03:01:57 +00009421 return getDerived().TransformExpr(E->getArg(0));
9422
Douglas Gregora16548e2009-08-11 05:31:07 +00009423 TemporaryBase Rebase(*this, /*FIXME*/E->getLocStart(), DeclarationName());
9424
9425 QualType T = getDerived().TransformType(E->getType());
9426 if (T.isNull())
John McCallfaf5fb42010-08-26 23:41:50 +00009427 return ExprError();
Douglas Gregora16548e2009-08-11 05:31:07 +00009428
9429 CXXConstructorDecl *Constructor
9430 = cast_or_null<CXXConstructorDecl>(
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009431 getDerived().TransformDecl(E->getLocStart(),
9432 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009433 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009434 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009435
Douglas Gregora16548e2009-08-11 05:31:07 +00009436 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009437 SmallVector<Expr*, 8> Args;
Chad Rosier1dcde962012-08-08 18:46:20 +00009438 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009439 &ArgumentChanged))
9440 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009441
Douglas Gregora16548e2009-08-11 05:31:07 +00009442 if (!getDerived().AlwaysRebuild() &&
9443 T == E->getType() &&
9444 Constructor == E->getConstructor() &&
Douglas Gregorde550352010-02-26 00:01:57 +00009445 !ArgumentChanged) {
Douglas Gregord2d9da02010-02-26 00:38:10 +00009446 // Mark the constructor as referenced.
9447 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009448 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009449 return E;
Douglas Gregorde550352010-02-26 00:01:57 +00009450 }
Mike Stump11289f42009-09-09 15:08:12 +00009451
Douglas Gregordb121ba2009-12-14 16:27:04 +00009452 return getDerived().RebuildCXXConstructExpr(T, /*FIXME:*/E->getLocStart(),
9453 Constructor, E->isElidable(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009454 Args,
Abramo Bagnara635ed24e2011-10-05 07:56:41 +00009455 E->hadMultipleCandidates(),
Richard Smithd59b8322012-12-19 01:39:02 +00009456 E->isListInitialization(),
Richard Smithf8adcdc2014-07-17 05:12:35 +00009457 E->isStdInitListInitialization(),
Douglas Gregorb0a04ff2010-08-22 17:20:18 +00009458 E->requiresZeroInitialization(),
Chandler Carruth01718152010-10-25 08:47:36 +00009459 E->getConstructionKind(),
Enea Zaffanella76e98fe2013-09-07 05:49:53 +00009460 E->getParenOrBraceRange());
Douglas Gregora16548e2009-08-11 05:31:07 +00009461}
Mike Stump11289f42009-09-09 15:08:12 +00009462
Douglas Gregora16548e2009-08-11 05:31:07 +00009463/// \brief Transform a C++ temporary-binding expression.
9464///
Douglas Gregor363b1512009-12-24 18:51:59 +00009465/// Since CXXBindTemporaryExpr nodes are implicitly generated, we just
9466/// transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009467template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009468ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009469TreeTransform<Derived>::TransformCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009470 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009471}
Mike Stump11289f42009-09-09 15:08:12 +00009472
John McCall5d413782010-12-06 08:20:24 +00009473/// \brief Transform a C++ expression that contains cleanups that should
9474/// be run after the expression is evaluated.
Douglas Gregora16548e2009-08-11 05:31:07 +00009475///
John McCall5d413782010-12-06 08:20:24 +00009476/// Since ExprWithCleanups nodes are implicitly generated, we
Douglas Gregor363b1512009-12-24 18:51:59 +00009477/// just transform the subexpression and return that.
Douglas Gregora16548e2009-08-11 05:31:07 +00009478template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009479ExprResult
John McCall5d413782010-12-06 08:20:24 +00009480TreeTransform<Derived>::TransformExprWithCleanups(ExprWithCleanups *E) {
Douglas Gregor363b1512009-12-24 18:51:59 +00009481 return getDerived().TransformExpr(E->getSubExpr());
Douglas Gregora16548e2009-08-11 05:31:07 +00009482}
Mike Stump11289f42009-09-09 15:08:12 +00009483
Douglas Gregora16548e2009-08-11 05:31:07 +00009484template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009485ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009486TreeTransform<Derived>::TransformCXXTemporaryObjectExpr(
Douglas Gregor2b88c112010-09-08 00:15:04 +00009487 CXXTemporaryObjectExpr *E) {
9488 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9489 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009490 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009491
Douglas Gregora16548e2009-08-11 05:31:07 +00009492 CXXConstructorDecl *Constructor
9493 = cast_or_null<CXXConstructorDecl>(
Chad Rosier1dcde962012-08-08 18:46:20 +00009494 getDerived().TransformDecl(E->getLocStart(),
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009495 E->getConstructor()));
Douglas Gregora16548e2009-08-11 05:31:07 +00009496 if (!Constructor)
John McCallfaf5fb42010-08-26 23:41:50 +00009497 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009498
Douglas Gregora16548e2009-08-11 05:31:07 +00009499 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009500 SmallVector<Expr*, 8> Args;
Douglas Gregora16548e2009-08-11 05:31:07 +00009501 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +00009502 if (TransformExprs(E->getArgs(), E->getNumArgs(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009503 &ArgumentChanged))
9504 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009505
Douglas Gregora16548e2009-08-11 05:31:07 +00009506 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009507 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009508 Constructor == E->getConstructor() &&
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009509 !ArgumentChanged) {
9510 // FIXME: Instantiation-specific
Eli Friedmanfa0df832012-02-02 03:46:19 +00009511 SemaRef.MarkFunctionReferenced(E->getLocStart(), Constructor);
John McCallc3007a22010-10-26 07:05:15 +00009512 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregor9bc6b7f2010-03-02 17:18:33 +00009513 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009514
Richard Smithd59b8322012-12-19 01:39:02 +00009515 // FIXME: Pass in E->isListInitialization().
Douglas Gregor2b88c112010-09-08 00:15:04 +00009516 return getDerived().RebuildCXXTemporaryObjectExpr(T,
9517 /*FIXME:*/T->getTypeLoc().getEndLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009518 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009519 E->getLocEnd());
9520}
Mike Stump11289f42009-09-09 15:08:12 +00009521
Douglas Gregora16548e2009-08-11 05:31:07 +00009522template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009523ExprResult
Douglas Gregore31e6062012-02-07 10:09:13 +00009524TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
Richard Smith01014ce2014-11-20 23:53:14 +00009525 // Transform any init-capture expressions before entering the scope of the
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009526 // lambda body, because they are not semantically within that scope.
Richard Smithc38498f2015-04-27 21:27:54 +00009527 typedef std::pair<ExprResult, QualType> InitCaptureInfoTy;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009528 SmallVector<InitCaptureInfoTy, 8> InitCaptureExprsAndTypes;
9529 InitCaptureExprsAndTypes.resize(E->explicit_capture_end() -
Richard Smithc38498f2015-04-27 21:27:54 +00009530 E->explicit_capture_begin());
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009531 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Richard Smith01014ce2014-11-20 23:53:14 +00009532 CEnd = E->capture_end();
9533 C != CEnd; ++C) {
James Dennettdd2ffea22015-05-07 18:48:18 +00009534 if (!E->isInitCapture(C))
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009535 continue;
Richard Smith01014ce2014-11-20 23:53:14 +00009536 EnterExpressionEvaluationContext EEEC(getSema(),
9537 Sema::PotentiallyEvaluated);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009538 ExprResult NewExprInitResult = getDerived().TransformInitializer(
9539 C->getCapturedVar()->getInit(),
9540 C->getCapturedVar()->getInitStyle() == VarDecl::CallInit);
Richard Smith01014ce2014-11-20 23:53:14 +00009541
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009542 if (NewExprInitResult.isInvalid())
9543 return ExprError();
9544 Expr *NewExprInit = NewExprInitResult.get();
Richard Smith01014ce2014-11-20 23:53:14 +00009545
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009546 VarDecl *OldVD = C->getCapturedVar();
Richard Smith01014ce2014-11-20 23:53:14 +00009547 QualType NewInitCaptureType =
9548 getSema().performLambdaInitCaptureInitialization(C->getLocation(),
9549 OldVD->getType()->isReferenceType(), OldVD->getIdentifier(),
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009550 NewExprInit);
9551 NewExprInitResult = NewExprInit;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009552 InitCaptureExprsAndTypes[C - E->capture_begin()] =
9553 std::make_pair(NewExprInitResult, NewInitCaptureType);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009554 }
9555
Faisal Vali2cba1332013-10-23 06:44:28 +00009556 // Transform the template parameters, and add them to the current
9557 // instantiation scope. The null case is handled correctly.
Richard Smithc38498f2015-04-27 21:27:54 +00009558 auto TPL = getDerived().TransformTemplateParameterList(
Faisal Vali2cba1332013-10-23 06:44:28 +00009559 E->getTemplateParameterList());
9560
Richard Smith01014ce2014-11-20 23:53:14 +00009561 // Transform the type of the original lambda's call operator.
9562 // The transformation MUST be done in the CurrentInstantiationScope since
9563 // it introduces a mapping of the original to the newly created
9564 // transformed parameters.
Craig Topperc3ec1492014-05-26 06:22:03 +00009565 TypeSourceInfo *NewCallOpTSI = nullptr;
Richard Smith01014ce2014-11-20 23:53:14 +00009566 {
9567 TypeSourceInfo *OldCallOpTSI = E->getCallOperator()->getTypeSourceInfo();
9568 FunctionProtoTypeLoc OldCallOpFPTL =
9569 OldCallOpTSI->getTypeLoc().getAs<FunctionProtoTypeLoc>();
Faisal Vali2cba1332013-10-23 06:44:28 +00009570
9571 TypeLocBuilder NewCallOpTLBuilder;
Richard Smith2e321552014-11-12 02:00:47 +00009572 SmallVector<QualType, 4> ExceptionStorage;
Richard Smith775118a2014-11-12 02:09:03 +00009573 TreeTransform *This = this; // Work around gcc.gnu.org/PR56135.
Richard Smith2e321552014-11-12 02:00:47 +00009574 QualType NewCallOpType = TransformFunctionProtoType(
9575 NewCallOpTLBuilder, OldCallOpFPTL, nullptr, 0,
Richard Smith775118a2014-11-12 02:09:03 +00009576 [&](FunctionProtoType::ExceptionSpecInfo &ESI, bool &Changed) {
9577 return This->TransformExceptionSpec(OldCallOpFPTL.getBeginLoc(), ESI,
9578 ExceptionStorage, Changed);
Richard Smith2e321552014-11-12 02:00:47 +00009579 });
Reid Kleckneraac43c62014-12-15 21:07:16 +00009580 if (NewCallOpType.isNull())
9581 return ExprError();
Faisal Vali2cba1332013-10-23 06:44:28 +00009582 NewCallOpTSI = NewCallOpTLBuilder.getTypeSourceInfo(getSema().Context,
9583 NewCallOpType);
Faisal Vali2b391ab2013-09-26 19:54:12 +00009584 }
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009585
Richard Smithc38498f2015-04-27 21:27:54 +00009586 LambdaScopeInfo *LSI = getSema().PushLambdaScope();
9587 Sema::FunctionScopeRAII FuncScopeCleanup(getSema());
9588 LSI->GLTemplateParameterList = TPL;
9589
Eli Friedmand564afb2012-09-19 01:18:11 +00009590 // Create the local class that will describe the lambda.
9591 CXXRecordDecl *Class
9592 = getSema().createLambdaClosureType(E->getIntroducerRange(),
Faisal Vali2cba1332013-10-23 06:44:28 +00009593 NewCallOpTSI,
Faisal Valic1a6dc42013-10-23 16:10:50 +00009594 /*KnownDependent=*/false,
9595 E->getCaptureDefault());
Eli Friedmand564afb2012-09-19 01:18:11 +00009596 getDerived().transformedLocalDecl(E->getLambdaClass(), Class);
9597
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009598 // Build the call operator.
Richard Smith01014ce2014-11-20 23:53:14 +00009599 CXXMethodDecl *NewCallOperator = getSema().startLambdaDefinition(
9600 Class, E->getIntroducerRange(), NewCallOpTSI,
9601 E->getCallOperator()->getLocEnd(),
9602 NewCallOpTSI->getTypeLoc().castAs<FunctionProtoTypeLoc>().getParams());
Faisal Vali2cba1332013-10-23 06:44:28 +00009603 LSI->CallOperator = NewCallOperator;
Rafael Espindola4b35f272013-10-04 14:28:51 +00009604
Faisal Vali2cba1332013-10-23 06:44:28 +00009605 getDerived().transformAttrs(E->getCallOperator(), NewCallOperator);
Richard Smithc38498f2015-04-27 21:27:54 +00009606 getDerived().transformedLocalDecl(E->getCallOperator(), NewCallOperator);
Richard Smithba71c082013-05-16 06:20:58 +00009607
Douglas Gregorb4328232012-02-14 00:00:48 +00009608 // Introduce the context of the call operator.
Richard Smithc38498f2015-04-27 21:27:54 +00009609 Sema::ContextRAII SavedContext(getSema(), NewCallOperator,
Richard Smith7ff2bcb2014-01-24 01:54:52 +00009610 /*NewThisContext*/false);
Douglas Gregorb4328232012-02-14 00:00:48 +00009611
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009612 // Enter the scope of the lambda.
Richard Smithc38498f2015-04-27 21:27:54 +00009613 getSema().buildLambdaScope(LSI, NewCallOperator,
9614 E->getIntroducerRange(),
9615 E->getCaptureDefault(),
9616 E->getCaptureDefaultLoc(),
9617 E->hasExplicitParameters(),
9618 E->hasExplicitResultType(),
9619 E->isMutable());
9620
9621 bool Invalid = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009622
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009623 // Transform captures.
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009624 bool FinishedExplicitCaptures = false;
Chad Rosier1dcde962012-08-08 18:46:20 +00009625 for (LambdaExpr::capture_iterator C = E->capture_begin(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009626 CEnd = E->capture_end();
9627 C != CEnd; ++C) {
9628 // When we hit the first implicit capture, tell Sema that we've finished
9629 // the list of explicit captures.
9630 if (!FinishedExplicitCaptures && C->isImplicit()) {
9631 getSema().finishLambdaExplicitCaptures(LSI);
9632 FinishedExplicitCaptures = true;
9633 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009634
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009635 // Capturing 'this' is trivial.
9636 if (C->capturesThis()) {
9637 getSema().CheckCXXThisCapture(C->getLocation(), C->isExplicit());
9638 continue;
9639 }
Alexey Bataev39c81e22014-08-28 04:28:19 +00009640 // Captured expression will be recaptured during captured variables
9641 // rebuilding.
9642 if (C->capturesVLAType())
9643 continue;
Chad Rosier1dcde962012-08-08 18:46:20 +00009644
Richard Smithba71c082013-05-16 06:20:58 +00009645 // Rebuild init-captures, including the implied field declaration.
James Dennettdd2ffea22015-05-07 18:48:18 +00009646 if (E->isInitCapture(C)) {
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009647 InitCaptureInfoTy InitExprTypePair =
9648 InitCaptureExprsAndTypes[C - E->capture_begin()];
9649 ExprResult Init = InitExprTypePair.first;
9650 QualType InitQualType = InitExprTypePair.second;
9651 if (Init.isInvalid() || InitQualType.isNull()) {
Richard Smithba71c082013-05-16 06:20:58 +00009652 Invalid = true;
9653 continue;
9654 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009655 VarDecl *OldVD = C->getCapturedVar();
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009656 VarDecl *NewVD = getSema().createLambdaInitCaptureVarDecl(
9657 OldVD->getLocation(), InitExprTypePair.second,
9658 OldVD->getIdentifier(), Init.get());
Richard Smithbb13c9a2013-09-28 04:02:39 +00009659 if (!NewVD)
Richard Smithba71c082013-05-16 06:20:58 +00009660 Invalid = true;
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009661 else {
Richard Smithbb13c9a2013-09-28 04:02:39 +00009662 getDerived().transformedLocalDecl(OldVD, NewVD);
Faisal Vali5fb7c3c2013-12-05 01:40:41 +00009663 }
Richard Smithbb13c9a2013-09-28 04:02:39 +00009664 getSema().buildInitCaptureField(LSI, NewVD);
Richard Smithba71c082013-05-16 06:20:58 +00009665 continue;
9666 }
9667
9668 assert(C->capturesVariable() && "unexpected kind of lambda capture");
9669
Douglas Gregor3e308b12012-02-14 19:27:52 +00009670 // Determine the capture kind for Sema.
9671 Sema::TryCaptureKind Kind
9672 = C->isImplicit()? Sema::TryCapture_Implicit
9673 : C->getCaptureKind() == LCK_ByCopy
9674 ? Sema::TryCapture_ExplicitByVal
9675 : Sema::TryCapture_ExplicitByRef;
9676 SourceLocation EllipsisLoc;
9677 if (C->isPackExpansion()) {
9678 UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
9679 bool ShouldExpand = false;
9680 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +00009681 Optional<unsigned> NumExpansions;
Chad Rosier1dcde962012-08-08 18:46:20 +00009682 if (getDerived().TryExpandParameterPacks(C->getEllipsisLoc(),
9683 C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009684 Unexpanded,
9685 ShouldExpand, RetainExpansion,
Richard Smithba71c082013-05-16 06:20:58 +00009686 NumExpansions)) {
9687 Invalid = true;
9688 continue;
9689 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009690
Douglas Gregor3e308b12012-02-14 19:27:52 +00009691 if (ShouldExpand) {
9692 // The transform has determined that we should perform an expansion;
9693 // transform and capture each of the arguments.
9694 // expansion of the pattern. Do so.
9695 VarDecl *Pack = C->getCapturedVar();
9696 for (unsigned I = 0; I != *NumExpansions; ++I) {
9697 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
9698 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009699 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor3e308b12012-02-14 19:27:52 +00009700 Pack));
9701 if (!CapturedVar) {
9702 Invalid = true;
9703 continue;
9704 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009705
Douglas Gregor3e308b12012-02-14 19:27:52 +00009706 // Capture the transformed variable.
Chad Rosier1dcde962012-08-08 18:46:20 +00009707 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind);
9708 }
Richard Smith9467be42014-06-06 17:33:35 +00009709
9710 // FIXME: Retain a pack expansion if RetainExpansion is true.
9711
Douglas Gregor3e308b12012-02-14 19:27:52 +00009712 continue;
9713 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009714
Douglas Gregor3e308b12012-02-14 19:27:52 +00009715 EllipsisLoc = C->getEllipsisLoc();
9716 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009717
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009718 // Transform the captured variable.
9719 VarDecl *CapturedVar
Chad Rosier1dcde962012-08-08 18:46:20 +00009720 = cast_or_null<VarDecl>(getDerived().TransformDecl(C->getLocation(),
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009721 C->getCapturedVar()));
Richard Trieub2926042014-09-02 19:32:44 +00009722 if (!CapturedVar || CapturedVar->isInvalidDecl()) {
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009723 Invalid = true;
9724 continue;
9725 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009726
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009727 // Capture the transformed variable.
Meador Inge4f9dee72015-06-26 00:09:55 +00009728 getSema().tryCaptureVariable(CapturedVar, C->getLocation(), Kind,
9729 EllipsisLoc);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009730 }
9731 if (!FinishedExplicitCaptures)
9732 getSema().finishLambdaExplicitCaptures(LSI);
9733
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009734 // Enter a new evaluation context to insulate the lambda from any
9735 // cleanups from the enclosing full-expression.
Chad Rosier1dcde962012-08-08 18:46:20 +00009736 getSema().PushExpressionEvaluationContext(Sema::PotentiallyEvaluated);
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009737
Douglas Gregor0c46b2b2012-02-13 22:00:16 +00009738 // Instantiate the body of the lambda expression.
Richard Smithc38498f2015-04-27 21:27:54 +00009739 StmtResult Body =
9740 Invalid ? StmtError() : getDerived().TransformStmt(E->getBody());
9741
9742 // ActOnLambda* will pop the function scope for us.
9743 FuncScopeCleanup.disable();
9744
Douglas Gregorb4328232012-02-14 00:00:48 +00009745 if (Body.isInvalid()) {
Richard Smithc38498f2015-04-27 21:27:54 +00009746 SavedContext.pop();
Craig Topperc3ec1492014-05-26 06:22:03 +00009747 getSema().ActOnLambdaError(E->getLocStart(), /*CurScope=*/nullptr,
Douglas Gregorb4328232012-02-14 00:00:48 +00009748 /*IsInstantiation=*/true);
Chad Rosier1dcde962012-08-08 18:46:20 +00009749 return ExprError();
Douglas Gregorb4328232012-02-14 00:00:48 +00009750 }
Douglas Gregor7fcbd902012-02-21 00:37:24 +00009751
Richard Smithc38498f2015-04-27 21:27:54 +00009752 // Copy the LSI before ActOnFinishFunctionBody removes it.
9753 // FIXME: This is dumb. Store the lambda information somewhere that outlives
9754 // the call operator.
9755 auto LSICopy = *LSI;
9756 getSema().ActOnFinishFunctionBody(NewCallOperator, Body.get(),
9757 /*IsInstantiation*/ true);
9758 SavedContext.pop();
9759
9760 return getSema().BuildLambdaExpr(E->getLocStart(), Body.get()->getLocEnd(),
9761 &LSICopy);
Douglas Gregore31e6062012-02-07 10:09:13 +00009762}
9763
9764template<typename Derived>
9765ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +00009766TreeTransform<Derived>::TransformCXXUnresolvedConstructExpr(
John McCall47f29ea2009-12-08 09:21:05 +00009767 CXXUnresolvedConstructExpr *E) {
Douglas Gregor2b88c112010-09-08 00:15:04 +00009768 TypeSourceInfo *T = getDerived().TransformType(E->getTypeSourceInfo());
9769 if (!T)
John McCallfaf5fb42010-08-26 23:41:50 +00009770 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009771
Douglas Gregora16548e2009-08-11 05:31:07 +00009772 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +00009773 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +00009774 Args.reserve(E->arg_size());
Chad Rosier1dcde962012-08-08 18:46:20 +00009775 if (getDerived().TransformExprs(E->arg_begin(), E->arg_size(), true, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +00009776 &ArgumentChanged))
9777 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009778
Douglas Gregora16548e2009-08-11 05:31:07 +00009779 if (!getDerived().AlwaysRebuild() &&
Douglas Gregor2b88c112010-09-08 00:15:04 +00009780 T == E->getTypeSourceInfo() &&
Douglas Gregora16548e2009-08-11 05:31:07 +00009781 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009782 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009783
Douglas Gregora16548e2009-08-11 05:31:07 +00009784 // FIXME: we're faking the locations of the commas
Douglas Gregor2b88c112010-09-08 00:15:04 +00009785 return getDerived().RebuildCXXUnresolvedConstructExpr(T,
Douglas Gregora16548e2009-08-11 05:31:07 +00009786 E->getLParenLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +00009787 Args,
Douglas Gregora16548e2009-08-11 05:31:07 +00009788 E->getRParenLoc());
9789}
Mike Stump11289f42009-09-09 15:08:12 +00009790
Douglas Gregora16548e2009-08-11 05:31:07 +00009791template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009792ExprResult
John McCall8cd78132009-11-19 22:55:06 +00009793TreeTransform<Derived>::TransformCXXDependentScopeMemberExpr(
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009794 CXXDependentScopeMemberExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +00009795 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009796 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009797 Expr *OldBase;
9798 QualType BaseType;
9799 QualType ObjectType;
9800 if (!E->isImplicitAccess()) {
9801 OldBase = E->getBase();
9802 Base = getDerived().TransformExpr(OldBase);
9803 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009804 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009805
John McCall2d74de92009-12-01 22:10:20 +00009806 // Start the member reference and compute the object's type.
John McCallba7bf592010-08-24 05:47:05 +00009807 ParsedType ObjectTy;
Douglas Gregore610ada2010-02-24 18:44:31 +00009808 bool MayBePseudoDestructor = false;
Craig Topperc3ec1492014-05-26 06:22:03 +00009809 Base = SemaRef.ActOnStartCXXMemberReference(nullptr, Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009810 E->getOperatorLoc(),
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009811 E->isArrow()? tok::arrow : tok::period,
Douglas Gregore610ada2010-02-24 18:44:31 +00009812 ObjectTy,
9813 MayBePseudoDestructor);
John McCall2d74de92009-12-01 22:10:20 +00009814 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009815 return ExprError();
John McCall2d74de92009-12-01 22:10:20 +00009816
John McCallba7bf592010-08-24 05:47:05 +00009817 ObjectType = ObjectTy.get();
John McCall2d74de92009-12-01 22:10:20 +00009818 BaseType = ((Expr*) Base.get())->getType();
9819 } else {
Craig Topperc3ec1492014-05-26 06:22:03 +00009820 OldBase = nullptr;
John McCall2d74de92009-12-01 22:10:20 +00009821 BaseType = getDerived().TransformType(E->getBaseType());
9822 ObjectType = BaseType->getAs<PointerType>()->getPointeeType();
9823 }
Mike Stump11289f42009-09-09 15:08:12 +00009824
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009825 // Transform the first part of the nested-name-specifier that qualifies
9826 // the member name.
Douglas Gregor2b6ca462009-09-03 21:38:09 +00009827 NamedDecl *FirstQualifierInScope
Douglas Gregora5cb6da2009-10-20 05:58:46 +00009828 = getDerived().TransformFirstQualifierInScope(
Douglas Gregore16af532011-02-28 18:50:33 +00009829 E->getFirstQualifierFoundInScope(),
9830 E->getQualifierLoc().getBeginLoc());
Mike Stump11289f42009-09-09 15:08:12 +00009831
Douglas Gregore16af532011-02-28 18:50:33 +00009832 NestedNameSpecifierLoc QualifierLoc;
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009833 if (E->getQualifier()) {
Douglas Gregore16af532011-02-28 18:50:33 +00009834 QualifierLoc
9835 = getDerived().TransformNestedNameSpecifierLoc(E->getQualifierLoc(),
9836 ObjectType,
9837 FirstQualifierInScope);
9838 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009839 return ExprError();
Douglas Gregorc26e0f62009-09-03 16:14:30 +00009840 }
Mike Stump11289f42009-09-09 15:08:12 +00009841
Abramo Bagnara7945c982012-01-27 09:46:47 +00009842 SourceLocation TemplateKWLoc = E->getTemplateKeywordLoc();
9843
John McCall31f82722010-11-12 08:19:04 +00009844 // TODO: If this is a conversion-function-id, verify that the
9845 // destination type name (if present) resolves the same way after
9846 // instantiation as it did in the local scope.
9847
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009848 DeclarationNameInfo NameInfo
John McCall31f82722010-11-12 08:19:04 +00009849 = getDerived().TransformDeclarationNameInfo(E->getMemberNameInfo());
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009850 if (!NameInfo.getName())
John McCallfaf5fb42010-08-26 23:41:50 +00009851 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009852
John McCall2d74de92009-12-01 22:10:20 +00009853 if (!E->hasExplicitTemplateArgs()) {
Douglas Gregor308047d2009-09-09 00:23:06 +00009854 // This is a reference to a member without an explicitly-specified
9855 // template argument list. Optimize for this common case.
9856 if (!getDerived().AlwaysRebuild() &&
John McCall2d74de92009-12-01 22:10:20 +00009857 Base.get() == OldBase &&
9858 BaseType == E->getBaseType() &&
Douglas Gregore16af532011-02-28 18:50:33 +00009859 QualifierLoc == E->getQualifierLoc() &&
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009860 NameInfo.getName() == E->getMember() &&
Douglas Gregor308047d2009-09-09 00:23:06 +00009861 FirstQualifierInScope == E->getFirstQualifierFoundInScope())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +00009862 return E;
Mike Stump11289f42009-09-09 15:08:12 +00009863
John McCallb268a282010-08-23 23:25:46 +00009864 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009865 BaseType,
Douglas Gregor308047d2009-09-09 00:23:06 +00009866 E->isArrow(),
9867 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009868 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009869 TemplateKWLoc,
John McCall10eae182009-11-30 22:42:35 +00009870 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009871 NameInfo,
Craig Topperc3ec1492014-05-26 06:22:03 +00009872 /*TemplateArgs*/nullptr);
Douglas Gregor308047d2009-09-09 00:23:06 +00009873 }
9874
John McCall6b51f282009-11-23 01:53:49 +00009875 TemplateArgumentListInfo TransArgs(E->getLAngleLoc(), E->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009876 if (getDerived().TransformTemplateArguments(E->getTemplateArgs(),
9877 E->getNumTemplateArgs(),
9878 TransArgs))
9879 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +00009880
John McCallb268a282010-08-23 23:25:46 +00009881 return getDerived().RebuildCXXDependentScopeMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009882 BaseType,
Douglas Gregora16548e2009-08-11 05:31:07 +00009883 E->isArrow(),
9884 E->getOperatorLoc(),
Douglas Gregore16af532011-02-28 18:50:33 +00009885 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009886 TemplateKWLoc,
Douglas Gregor308047d2009-09-09 00:23:06 +00009887 FirstQualifierInScope,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009888 NameInfo,
John McCall10eae182009-11-30 22:42:35 +00009889 &TransArgs);
9890}
9891
9892template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009893ExprResult
John McCall47f29ea2009-12-08 09:21:05 +00009894TreeTransform<Derived>::TransformUnresolvedMemberExpr(UnresolvedMemberExpr *Old) {
John McCall10eae182009-11-30 22:42:35 +00009895 // Transform the base of the expression.
Craig Topperc3ec1492014-05-26 06:22:03 +00009896 ExprResult Base((Expr*) nullptr);
John McCall2d74de92009-12-01 22:10:20 +00009897 QualType BaseType;
9898 if (!Old->isImplicitAccess()) {
9899 Base = getDerived().TransformExpr(Old->getBase());
9900 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +00009901 return ExprError();
Nikola Smiljanic01a75982014-05-29 10:55:11 +00009902 Base = getSema().PerformMemberExprBaseConversion(Base.get(),
Richard Smithcab9a7d2011-10-26 19:06:56 +00009903 Old->isArrow());
9904 if (Base.isInvalid())
9905 return ExprError();
9906 BaseType = Base.get()->getType();
John McCall2d74de92009-12-01 22:10:20 +00009907 } else {
9908 BaseType = getDerived().TransformType(Old->getBaseType());
9909 }
John McCall10eae182009-11-30 22:42:35 +00009910
Douglas Gregor0da1d432011-02-28 20:01:57 +00009911 NestedNameSpecifierLoc QualifierLoc;
9912 if (Old->getQualifierLoc()) {
9913 QualifierLoc
9914 = getDerived().TransformNestedNameSpecifierLoc(Old->getQualifierLoc());
9915 if (!QualifierLoc)
John McCallfaf5fb42010-08-26 23:41:50 +00009916 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009917 }
9918
Abramo Bagnara7945c982012-01-27 09:46:47 +00009919 SourceLocation TemplateKWLoc = Old->getTemplateKeywordLoc();
9920
Abramo Bagnarad6d2f182010-08-11 22:01:17 +00009921 LookupResult R(SemaRef, Old->getMemberNameInfo(),
John McCall10eae182009-11-30 22:42:35 +00009922 Sema::LookupOrdinaryName);
9923
9924 // Transform all the decls.
9925 for (UnresolvedMemberExpr::decls_iterator I = Old->decls_begin(),
9926 E = Old->decls_end(); I != E; ++I) {
Douglas Gregora04f2ca2010-03-01 15:56:25 +00009927 NamedDecl *InstD = static_cast<NamedDecl*>(
9928 getDerived().TransformDecl(Old->getMemberLoc(),
9929 *I));
John McCall84d87672009-12-10 09:41:52 +00009930 if (!InstD) {
9931 // Silently ignore these if a UsingShadowDecl instantiated to nothing.
9932 // This can happen because of dependent hiding.
9933 if (isa<UsingShadowDecl>(*I))
9934 continue;
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009935 else {
9936 R.clear();
John McCallfaf5fb42010-08-26 23:41:50 +00009937 return ExprError();
Argyrios Kyrtzidis98feafe2011-04-22 01:18:40 +00009938 }
John McCall84d87672009-12-10 09:41:52 +00009939 }
John McCall10eae182009-11-30 22:42:35 +00009940
9941 // Expand using declarations.
9942 if (isa<UsingDecl>(InstD)) {
9943 UsingDecl *UD = cast<UsingDecl>(InstD);
Aaron Ballman91cdc282014-03-13 18:07:29 +00009944 for (auto *I : UD->shadows())
9945 R.addDecl(I);
John McCall10eae182009-11-30 22:42:35 +00009946 continue;
9947 }
9948
9949 R.addDecl(InstD);
9950 }
9951
9952 R.resolveKind();
9953
Douglas Gregor9262f472010-04-27 18:19:34 +00009954 // Determine the naming class.
Chandler Carrutheba788e2010-05-19 01:37:01 +00009955 if (Old->getNamingClass()) {
Chad Rosier1dcde962012-08-08 18:46:20 +00009956 CXXRecordDecl *NamingClass
Douglas Gregor9262f472010-04-27 18:19:34 +00009957 = cast_or_null<CXXRecordDecl>(getDerived().TransformDecl(
Douglas Gregorda7be082010-04-27 16:10:10 +00009958 Old->getMemberLoc(),
9959 Old->getNamingClass()));
9960 if (!NamingClass)
John McCallfaf5fb42010-08-26 23:41:50 +00009961 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +00009962
Douglas Gregorda7be082010-04-27 16:10:10 +00009963 R.setNamingClass(NamingClass);
Douglas Gregor9262f472010-04-27 18:19:34 +00009964 }
Chad Rosier1dcde962012-08-08 18:46:20 +00009965
John McCall10eae182009-11-30 22:42:35 +00009966 TemplateArgumentListInfo TransArgs;
9967 if (Old->hasExplicitTemplateArgs()) {
9968 TransArgs.setLAngleLoc(Old->getLAngleLoc());
9969 TransArgs.setRAngleLoc(Old->getRAngleLoc());
Douglas Gregor62e06f22010-12-20 17:31:10 +00009970 if (getDerived().TransformTemplateArguments(Old->getTemplateArgs(),
9971 Old->getNumTemplateArgs(),
9972 TransArgs))
9973 return ExprError();
John McCall10eae182009-11-30 22:42:35 +00009974 }
John McCall38836f02010-01-15 08:34:02 +00009975
9976 // FIXME: to do this check properly, we will need to preserve the
9977 // first-qualifier-in-scope here, just in case we had a dependent
9978 // base (and therefore couldn't do the check) and a
9979 // nested-name-qualifier (and therefore could do the lookup).
Craig Topperc3ec1492014-05-26 06:22:03 +00009980 NamedDecl *FirstQualifierInScope = nullptr;
Chad Rosier1dcde962012-08-08 18:46:20 +00009981
John McCallb268a282010-08-23 23:25:46 +00009982 return getDerived().RebuildUnresolvedMemberExpr(Base.get(),
John McCall2d74de92009-12-01 22:10:20 +00009983 BaseType,
John McCall10eae182009-11-30 22:42:35 +00009984 Old->getOperatorLoc(),
9985 Old->isArrow(),
Douglas Gregor0da1d432011-02-28 20:01:57 +00009986 QualifierLoc,
Abramo Bagnara7945c982012-01-27 09:46:47 +00009987 TemplateKWLoc,
John McCall38836f02010-01-15 08:34:02 +00009988 FirstQualifierInScope,
John McCall10eae182009-11-30 22:42:35 +00009989 R,
9990 (Old->hasExplicitTemplateArgs()
Craig Topperc3ec1492014-05-26 06:22:03 +00009991 ? &TransArgs : nullptr));
Douglas Gregora16548e2009-08-11 05:31:07 +00009992}
9993
9994template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +00009995ExprResult
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009996TreeTransform<Derived>::TransformCXXNoexceptExpr(CXXNoexceptExpr *E) {
Alexis Hunt414e3e32011-05-31 19:54:49 +00009997 EnterExpressionEvaluationContext Unevaluated(SemaRef, Sema::Unevaluated);
Sebastian Redl4202c0f2010-09-10 20:55:43 +00009998 ExprResult SubExpr = getDerived().TransformExpr(E->getOperand());
9999 if (SubExpr.isInvalid())
10000 return ExprError();
10001
10002 if (!getDerived().AlwaysRebuild() && SubExpr.get() == E->getOperand())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010003 return E;
Sebastian Redl4202c0f2010-09-10 20:55:43 +000010004
10005 return getDerived().RebuildCXXNoexceptExpr(E->getSourceRange(),SubExpr.get());
10006}
10007
10008template<typename Derived>
10009ExprResult
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010010TreeTransform<Derived>::TransformPackExpansionExpr(PackExpansionExpr *E) {
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010011 ExprResult Pattern = getDerived().TransformExpr(E->getPattern());
10012 if (Pattern.isInvalid())
10013 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010014
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010015 if (!getDerived().AlwaysRebuild() && Pattern.get() == E->getPattern())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010016 return E;
Douglas Gregor0f836ea2011-01-13 00:19:55 +000010017
Douglas Gregorb8840002011-01-14 21:20:45 +000010018 return getDerived().RebuildPackExpansion(Pattern.get(), E->getEllipsisLoc(),
10019 E->getNumExpansions());
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010020}
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010021
10022template<typename Derived>
10023ExprResult
10024TreeTransform<Derived>::TransformSizeOfPackExpr(SizeOfPackExpr *E) {
10025 // If E is not value-dependent, then nothing will change when we transform it.
10026 // Note: This is an instantiation-centric view.
10027 if (!E->isValueDependent())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010028 return E;
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010029
Richard Smithd784e682015-09-23 21:41:42 +000010030 EnterExpressionEvaluationContext Unevaluated(getSema(), Sema::Unevaluated);
Chad Rosier1dcde962012-08-08 18:46:20 +000010031
Richard Smithd784e682015-09-23 21:41:42 +000010032 ArrayRef<TemplateArgument> PackArgs;
10033 TemplateArgument ArgStorage;
Chad Rosier1dcde962012-08-08 18:46:20 +000010034
Richard Smithd784e682015-09-23 21:41:42 +000010035 // Find the argument list to transform.
10036 if (E->isPartiallySubstituted()) {
10037 PackArgs = E->getPartialArguments();
10038 } else if (E->isValueDependent()) {
10039 UnexpandedParameterPack Unexpanded(E->getPack(), E->getPackLoc());
10040 bool ShouldExpand = false;
10041 bool RetainExpansion = false;
10042 Optional<unsigned> NumExpansions;
10043 if (getDerived().TryExpandParameterPacks(E->getOperatorLoc(), E->getPackLoc(),
10044 Unexpanded,
10045 ShouldExpand, RetainExpansion,
10046 NumExpansions))
10047 return ExprError();
10048
10049 // If we need to expand the pack, build a template argument from it and
10050 // expand that.
10051 if (ShouldExpand) {
10052 auto *Pack = E->getPack();
10053 if (auto *TTPD = dyn_cast<TemplateTypeParmDecl>(Pack)) {
10054 ArgStorage = getSema().Context.getPackExpansionType(
10055 getSema().Context.getTypeDeclType(TTPD), None);
10056 } else if (auto *TTPD = dyn_cast<TemplateTemplateParmDecl>(Pack)) {
10057 ArgStorage = TemplateArgument(TemplateName(TTPD), None);
10058 } else {
10059 auto *VD = cast<ValueDecl>(Pack);
10060 ExprResult DRE = getSema().BuildDeclRefExpr(VD, VD->getType(),
10061 VK_RValue, E->getPackLoc());
10062 if (DRE.isInvalid())
10063 return ExprError();
10064 ArgStorage = new (getSema().Context) PackExpansionExpr(
10065 getSema().Context.DependentTy, DRE.get(), E->getPackLoc(), None);
10066 }
10067 PackArgs = ArgStorage;
10068 }
10069 }
10070
10071 // If we're not expanding the pack, just transform the decl.
10072 if (!PackArgs.size()) {
10073 auto *Pack = cast_or_null<NamedDecl>(
10074 getDerived().TransformDecl(E->getPackLoc(), E->getPack()));
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010075 if (!Pack)
10076 return ExprError();
Richard Smithd784e682015-09-23 21:41:42 +000010077 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), Pack,
10078 E->getPackLoc(),
10079 E->getRParenLoc(), None, None);
10080 }
10081
10082 TemplateArgumentListInfo TransformedPackArgs(E->getPackLoc(),
10083 E->getPackLoc());
10084 {
10085 TemporaryBase Rebase(*this, E->getPackLoc(), getBaseEntity());
10086 typedef TemplateArgumentLocInventIterator<
10087 Derived, const TemplateArgument*> PackLocIterator;
10088 if (TransformTemplateArguments(PackLocIterator(*this, PackArgs.begin()),
10089 PackLocIterator(*this, PackArgs.end()),
10090 TransformedPackArgs, /*Uneval*/true))
10091 return ExprError();
Douglas Gregorab96bcf2011-10-10 18:59:29 +000010092 }
10093
Richard Smithd784e682015-09-23 21:41:42 +000010094 SmallVector<TemplateArgument, 8> Args;
10095 bool PartialSubstitution = false;
10096 for (auto &Loc : TransformedPackArgs.arguments()) {
10097 Args.push_back(Loc.getArgument());
10098 if (Loc.getArgument().isPackExpansion())
10099 PartialSubstitution = true;
10100 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010101
Richard Smithd784e682015-09-23 21:41:42 +000010102 if (PartialSubstitution)
10103 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
10104 E->getPackLoc(),
10105 E->getRParenLoc(), None, Args);
10106
10107 return getDerived().RebuildSizeOfPackExpr(E->getOperatorLoc(), E->getPack(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010108 E->getPackLoc(), E->getRParenLoc(),
Richard Smithd784e682015-09-23 21:41:42 +000010109 Args.size(), None);
Douglas Gregor820ba7b2011-01-04 17:33:58 +000010110}
10111
Douglas Gregore8e9dd62011-01-03 17:17:50 +000010112template<typename Derived>
10113ExprResult
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010114TreeTransform<Derived>::TransformSubstNonTypeTemplateParmPackExpr(
10115 SubstNonTypeTemplateParmPackExpr *E) {
10116 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010117 return E;
Douglas Gregorcdbc5392011-01-15 01:15:58 +000010118}
10119
10120template<typename Derived>
10121ExprResult
John McCall7c454bb2011-07-15 05:09:51 +000010122TreeTransform<Derived>::TransformSubstNonTypeTemplateParmExpr(
10123 SubstNonTypeTemplateParmExpr *E) {
10124 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010125 return E;
John McCall7c454bb2011-07-15 05:09:51 +000010126}
10127
10128template<typename Derived>
10129ExprResult
Richard Smithb15fe3a2012-09-12 00:56:43 +000010130TreeTransform<Derived>::TransformFunctionParmPackExpr(FunctionParmPackExpr *E) {
10131 // Default behavior is to do nothing with this transformation.
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010132 return E;
Richard Smithb15fe3a2012-09-12 00:56:43 +000010133}
10134
10135template<typename Derived>
10136ExprResult
Douglas Gregorfe314812011-06-21 17:03:29 +000010137TreeTransform<Derived>::TransformMaterializeTemporaryExpr(
10138 MaterializeTemporaryExpr *E) {
10139 return getDerived().TransformExpr(E->GetTemporaryExpr());
10140}
Chad Rosier1dcde962012-08-08 18:46:20 +000010141
Douglas Gregorfe314812011-06-21 17:03:29 +000010142template<typename Derived>
10143ExprResult
Richard Smith0f0af192014-11-08 05:07:16 +000010144TreeTransform<Derived>::TransformCXXFoldExpr(CXXFoldExpr *E) {
10145 Expr *Pattern = E->getPattern();
10146
10147 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10148 getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
10149 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10150
10151 // Determine whether the set of unexpanded parameter packs can and should
10152 // be expanded.
10153 bool Expand = true;
10154 bool RetainExpansion = false;
10155 Optional<unsigned> NumExpansions;
10156 if (getDerived().TryExpandParameterPacks(E->getEllipsisLoc(),
10157 Pattern->getSourceRange(),
10158 Unexpanded,
10159 Expand, RetainExpansion,
10160 NumExpansions))
10161 return true;
10162
10163 if (!Expand) {
10164 // Do not expand any packs here, just transform and rebuild a fold
10165 // expression.
10166 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10167
10168 ExprResult LHS =
10169 E->getLHS() ? getDerived().TransformExpr(E->getLHS()) : ExprResult();
10170 if (LHS.isInvalid())
10171 return true;
10172
10173 ExprResult RHS =
10174 E->getRHS() ? getDerived().TransformExpr(E->getRHS()) : ExprResult();
10175 if (RHS.isInvalid())
10176 return true;
10177
10178 if (!getDerived().AlwaysRebuild() &&
10179 LHS.get() == E->getLHS() && RHS.get() == E->getRHS())
10180 return E;
10181
10182 return getDerived().RebuildCXXFoldExpr(
10183 E->getLocStart(), LHS.get(), E->getOperator(), E->getEllipsisLoc(),
10184 RHS.get(), E->getLocEnd());
10185 }
10186
10187 // The transform has determined that we should perform an elementwise
10188 // expansion of the pattern. Do so.
10189 ExprResult Result = getDerived().TransformExpr(E->getInit());
10190 if (Result.isInvalid())
10191 return true;
10192 bool LeftFold = E->isLeftFold();
10193
10194 // If we're retaining an expansion for a right fold, it is the innermost
10195 // component and takes the init (if any).
10196 if (!LeftFold && RetainExpansion) {
10197 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10198
10199 ExprResult Out = getDerived().TransformExpr(Pattern);
10200 if (Out.isInvalid())
10201 return true;
10202
10203 Result = getDerived().RebuildCXXFoldExpr(
10204 E->getLocStart(), Out.get(), E->getOperator(), E->getEllipsisLoc(),
10205 Result.get(), E->getLocEnd());
10206 if (Result.isInvalid())
10207 return true;
10208 }
10209
10210 for (unsigned I = 0; I != *NumExpansions; ++I) {
10211 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(
10212 getSema(), LeftFold ? I : *NumExpansions - I - 1);
10213 ExprResult Out = getDerived().TransformExpr(Pattern);
10214 if (Out.isInvalid())
10215 return true;
10216
10217 if (Out.get()->containsUnexpandedParameterPack()) {
10218 // We still have a pack; retain a pack expansion for this slice.
10219 Result = getDerived().RebuildCXXFoldExpr(
10220 E->getLocStart(),
10221 LeftFold ? Result.get() : Out.get(),
10222 E->getOperator(), E->getEllipsisLoc(),
10223 LeftFold ? Out.get() : Result.get(),
10224 E->getLocEnd());
10225 } else if (Result.isUsable()) {
10226 // We've got down to a single element; build a binary operator.
10227 Result = getDerived().RebuildBinaryOperator(
10228 E->getEllipsisLoc(), E->getOperator(),
10229 LeftFold ? Result.get() : Out.get(),
10230 LeftFold ? Out.get() : Result.get());
10231 } else
10232 Result = Out;
10233
10234 if (Result.isInvalid())
10235 return true;
10236 }
10237
10238 // If we're retaining an expansion for a left fold, it is the outermost
10239 // component and takes the complete expansion so far as its init (if any).
10240 if (LeftFold && RetainExpansion) {
10241 ForgetPartiallySubstitutedPackRAII Forget(getDerived());
10242
10243 ExprResult Out = getDerived().TransformExpr(Pattern);
10244 if (Out.isInvalid())
10245 return true;
10246
10247 Result = getDerived().RebuildCXXFoldExpr(
10248 E->getLocStart(), Result.get(),
10249 E->getOperator(), E->getEllipsisLoc(),
10250 Out.get(), E->getLocEnd());
10251 if (Result.isInvalid())
10252 return true;
10253 }
10254
10255 // If we had no init and an empty pack, and we're not retaining an expansion,
10256 // then produce a fallback value or error.
10257 if (Result.isUnset())
10258 return getDerived().RebuildEmptyCXXFoldExpr(E->getEllipsisLoc(),
10259 E->getOperator());
10260
10261 return Result;
10262}
10263
10264template<typename Derived>
10265ExprResult
Richard Smithcc1b96d2013-06-12 22:31:48 +000010266TreeTransform<Derived>::TransformCXXStdInitializerListExpr(
10267 CXXStdInitializerListExpr *E) {
10268 return getDerived().TransformExpr(E->getSubExpr());
10269}
10270
10271template<typename Derived>
10272ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010273TreeTransform<Derived>::TransformObjCStringLiteral(ObjCStringLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010274 return SemaRef.MaybeBindToTemporary(E);
10275}
10276
10277template<typename Derived>
10278ExprResult
10279TreeTransform<Derived>::TransformObjCBoolLiteralExpr(ObjCBoolLiteralExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010280 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010281}
10282
10283template<typename Derived>
10284ExprResult
Patrick Beard0caa3942012-04-19 00:25:12 +000010285TreeTransform<Derived>::TransformObjCBoxedExpr(ObjCBoxedExpr *E) {
10286 ExprResult SubExpr = getDerived().TransformExpr(E->getSubExpr());
10287 if (SubExpr.isInvalid())
10288 return ExprError();
10289
10290 if (!getDerived().AlwaysRebuild() &&
10291 SubExpr.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010292 return E;
Patrick Beard0caa3942012-04-19 00:25:12 +000010293
10294 return getDerived().RebuildObjCBoxedExpr(E->getSourceRange(), SubExpr.get());
Ted Kremeneke65b0862012-03-06 20:05:56 +000010295}
10296
10297template<typename Derived>
10298ExprResult
10299TreeTransform<Derived>::TransformObjCArrayLiteral(ObjCArrayLiteral *E) {
10300 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010301 SmallVector<Expr *, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010302 bool ArgChanged = false;
Chad Rosier1dcde962012-08-08 18:46:20 +000010303 if (getDerived().TransformExprs(E->getElements(), E->getNumElements(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010304 /*IsCall=*/false, Elements, &ArgChanged))
10305 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010306
Ted Kremeneke65b0862012-03-06 20:05:56 +000010307 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10308 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010309
Ted Kremeneke65b0862012-03-06 20:05:56 +000010310 return getDerived().RebuildObjCArrayLiteral(E->getSourceRange(),
10311 Elements.data(),
10312 Elements.size());
10313}
10314
10315template<typename Derived>
10316ExprResult
10317TreeTransform<Derived>::TransformObjCDictionaryLiteral(
Chad Rosier1dcde962012-08-08 18:46:20 +000010318 ObjCDictionaryLiteral *E) {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010319 // Transform each of the elements.
Dmitri Gribenkof8579502013-01-12 19:30:44 +000010320 SmallVector<ObjCDictionaryElement, 8> Elements;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010321 bool ArgChanged = false;
10322 for (unsigned I = 0, N = E->getNumElements(); I != N; ++I) {
10323 ObjCDictionaryElement OrigElement = E->getKeyValueElement(I);
Chad Rosier1dcde962012-08-08 18:46:20 +000010324
Ted Kremeneke65b0862012-03-06 20:05:56 +000010325 if (OrigElement.isPackExpansion()) {
10326 // This key/value element is a pack expansion.
10327 SmallVector<UnexpandedParameterPack, 2> Unexpanded;
10328 getSema().collectUnexpandedParameterPacks(OrigElement.Key, Unexpanded);
10329 getSema().collectUnexpandedParameterPacks(OrigElement.Value, Unexpanded);
10330 assert(!Unexpanded.empty() && "Pack expansion without parameter packs?");
10331
10332 // Determine whether the set of unexpanded parameter packs can
10333 // and should be expanded.
10334 bool Expand = true;
10335 bool RetainExpansion = false;
David Blaikie05785d12013-02-20 22:23:23 +000010336 Optional<unsigned> OrigNumExpansions = OrigElement.NumExpansions;
10337 Optional<unsigned> NumExpansions = OrigNumExpansions;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010338 SourceRange PatternRange(OrigElement.Key->getLocStart(),
10339 OrigElement.Value->getLocEnd());
10340 if (getDerived().TryExpandParameterPacks(OrigElement.EllipsisLoc,
10341 PatternRange,
10342 Unexpanded,
10343 Expand, RetainExpansion,
10344 NumExpansions))
10345 return ExprError();
10346
10347 if (!Expand) {
10348 // The transform has determined that we should perform a simple
Chad Rosier1dcde962012-08-08 18:46:20 +000010349 // transformation on the pack expansion, producing another pack
Ted Kremeneke65b0862012-03-06 20:05:56 +000010350 // expansion.
10351 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), -1);
10352 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10353 if (Key.isInvalid())
10354 return ExprError();
10355
10356 if (Key.get() != OrigElement.Key)
10357 ArgChanged = true;
10358
10359 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10360 if (Value.isInvalid())
10361 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010362
Ted Kremeneke65b0862012-03-06 20:05:56 +000010363 if (Value.get() != OrigElement.Value)
10364 ArgChanged = true;
10365
Chad Rosier1dcde962012-08-08 18:46:20 +000010366 ObjCDictionaryElement Expansion = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010367 Key.get(), Value.get(), OrigElement.EllipsisLoc, NumExpansions
10368 };
10369 Elements.push_back(Expansion);
10370 continue;
10371 }
10372
10373 // Record right away that the argument was changed. This needs
10374 // to happen even if the array expands to nothing.
10375 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010376
Ted Kremeneke65b0862012-03-06 20:05:56 +000010377 // The transform has determined that we should perform an elementwise
10378 // expansion of the pattern. Do so.
10379 for (unsigned I = 0; I != *NumExpansions; ++I) {
10380 Sema::ArgumentPackSubstitutionIndexRAII SubstIndex(getSema(), I);
10381 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10382 if (Key.isInvalid())
10383 return ExprError();
10384
10385 ExprResult Value = getDerived().TransformExpr(OrigElement.Value);
10386 if (Value.isInvalid())
10387 return ExprError();
10388
Chad Rosier1dcde962012-08-08 18:46:20 +000010389 ObjCDictionaryElement Element = {
Ted Kremeneke65b0862012-03-06 20:05:56 +000010390 Key.get(), Value.get(), SourceLocation(), NumExpansions
10391 };
10392
10393 // If any unexpanded parameter packs remain, we still have a
10394 // pack expansion.
Richard Smith9467be42014-06-06 17:33:35 +000010395 // FIXME: Can this really happen?
Ted Kremeneke65b0862012-03-06 20:05:56 +000010396 if (Key.get()->containsUnexpandedParameterPack() ||
10397 Value.get()->containsUnexpandedParameterPack())
10398 Element.EllipsisLoc = OrigElement.EllipsisLoc;
Chad Rosier1dcde962012-08-08 18:46:20 +000010399
Ted Kremeneke65b0862012-03-06 20:05:56 +000010400 Elements.push_back(Element);
10401 }
10402
Richard Smith9467be42014-06-06 17:33:35 +000010403 // FIXME: Retain a pack expansion if RetainExpansion is true.
10404
Ted Kremeneke65b0862012-03-06 20:05:56 +000010405 // We've finished with this pack expansion.
10406 continue;
10407 }
10408
10409 // Transform and check key.
10410 ExprResult Key = getDerived().TransformExpr(OrigElement.Key);
10411 if (Key.isInvalid())
10412 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010413
Ted Kremeneke65b0862012-03-06 20:05:56 +000010414 if (Key.get() != OrigElement.Key)
10415 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010416
Ted Kremeneke65b0862012-03-06 20:05:56 +000010417 // Transform and check value.
10418 ExprResult Value
10419 = getDerived().TransformExpr(OrigElement.Value);
10420 if (Value.isInvalid())
10421 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010422
Ted Kremeneke65b0862012-03-06 20:05:56 +000010423 if (Value.get() != OrigElement.Value)
10424 ArgChanged = true;
Chad Rosier1dcde962012-08-08 18:46:20 +000010425
10426 ObjCDictionaryElement Element = {
David Blaikie7a30dc52013-02-21 01:47:18 +000010427 Key.get(), Value.get(), SourceLocation(), None
Ted Kremeneke65b0862012-03-06 20:05:56 +000010428 };
10429 Elements.push_back(Element);
10430 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010431
Ted Kremeneke65b0862012-03-06 20:05:56 +000010432 if (!getDerived().AlwaysRebuild() && !ArgChanged)
10433 return SemaRef.MaybeBindToTemporary(E);
10434
10435 return getDerived().RebuildObjCDictionaryLiteral(E->getSourceRange(),
10436 Elements.data(),
10437 Elements.size());
Douglas Gregora16548e2009-08-11 05:31:07 +000010438}
10439
Mike Stump11289f42009-09-09 15:08:12 +000010440template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010441ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010442TreeTransform<Derived>::TransformObjCEncodeExpr(ObjCEncodeExpr *E) {
Douglas Gregorabd9e962010-04-20 15:39:42 +000010443 TypeSourceInfo *EncodedTypeInfo
10444 = getDerived().TransformType(E->getEncodedTypeSourceInfo());
10445 if (!EncodedTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010446 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010447
Douglas Gregora16548e2009-08-11 05:31:07 +000010448 if (!getDerived().AlwaysRebuild() &&
Douglas Gregorabd9e962010-04-20 15:39:42 +000010449 EncodedTypeInfo == E->getEncodedTypeSourceInfo())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010450 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010451
10452 return getDerived().RebuildObjCEncodeExpr(E->getAtLoc(),
Douglas Gregorabd9e962010-04-20 15:39:42 +000010453 EncodedTypeInfo,
Douglas Gregora16548e2009-08-11 05:31:07 +000010454 E->getRParenLoc());
10455}
Mike Stump11289f42009-09-09 15:08:12 +000010456
Douglas Gregora16548e2009-08-11 05:31:07 +000010457template<typename Derived>
John McCall31168b02011-06-15 23:02:42 +000010458ExprResult TreeTransform<Derived>::
10459TransformObjCIndirectCopyRestoreExpr(ObjCIndirectCopyRestoreExpr *E) {
John McCallbc489892013-04-11 02:14:26 +000010460 // This is a kind of implicit conversion, and it needs to get dropped
10461 // and recomputed for the same general reasons that ImplicitCastExprs
10462 // do, as well a more specific one: this expression is only valid when
10463 // it appears *immediately* as an argument expression.
10464 return getDerived().TransformExpr(E->getSubExpr());
John McCall31168b02011-06-15 23:02:42 +000010465}
10466
10467template<typename Derived>
10468ExprResult TreeTransform<Derived>::
10469TransformObjCBridgedCastExpr(ObjCBridgedCastExpr *E) {
Chad Rosier1dcde962012-08-08 18:46:20 +000010470 TypeSourceInfo *TSInfo
John McCall31168b02011-06-15 23:02:42 +000010471 = getDerived().TransformType(E->getTypeInfoAsWritten());
10472 if (!TSInfo)
10473 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010474
John McCall31168b02011-06-15 23:02:42 +000010475 ExprResult Result = getDerived().TransformExpr(E->getSubExpr());
Chad Rosier1dcde962012-08-08 18:46:20 +000010476 if (Result.isInvalid())
John McCall31168b02011-06-15 23:02:42 +000010477 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010478
John McCall31168b02011-06-15 23:02:42 +000010479 if (!getDerived().AlwaysRebuild() &&
10480 TSInfo == E->getTypeInfoAsWritten() &&
10481 Result.get() == E->getSubExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010482 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010483
John McCall31168b02011-06-15 23:02:42 +000010484 return SemaRef.BuildObjCBridgedCast(E->getLParenLoc(), E->getBridgeKind(),
Chad Rosier1dcde962012-08-08 18:46:20 +000010485 E->getBridgeKeywordLoc(), TSInfo,
John McCall31168b02011-06-15 23:02:42 +000010486 Result.get());
10487}
10488
10489template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010490ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010491TreeTransform<Derived>::TransformObjCMessageExpr(ObjCMessageExpr *E) {
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010492 // Transform arguments.
10493 bool ArgChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010494 SmallVector<Expr*, 8> Args;
Douglas Gregora3efea12011-01-03 19:04:46 +000010495 Args.reserve(E->getNumArgs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010496 if (getDerived().TransformExprs(E->getArgs(), E->getNumArgs(), false, Args,
Douglas Gregora3efea12011-01-03 19:04:46 +000010497 &ArgChanged))
10498 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010499
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010500 if (E->getReceiverKind() == ObjCMessageExpr::Class) {
10501 // Class message: transform the receiver type.
10502 TypeSourceInfo *ReceiverTypeInfo
10503 = getDerived().TransformType(E->getClassReceiverTypeInfo());
10504 if (!ReceiverTypeInfo)
John McCallfaf5fb42010-08-26 23:41:50 +000010505 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010506
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010507 // If nothing changed, just retain the existing message send.
10508 if (!getDerived().AlwaysRebuild() &&
10509 ReceiverTypeInfo == E->getClassReceiverTypeInfo() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010510 return SemaRef.MaybeBindToTemporary(E);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010511
10512 // Build a new class message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010513 SmallVector<SourceLocation, 16> SelLocs;
10514 E->getSelectorLocs(SelLocs);
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010515 return getDerived().RebuildObjCMessageExpr(ReceiverTypeInfo,
10516 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010517 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010518 E->getMethodDecl(),
10519 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010520 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010521 E->getRightLoc());
10522 }
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010523 else if (E->getReceiverKind() == ObjCMessageExpr::SuperClass ||
10524 E->getReceiverKind() == ObjCMessageExpr::SuperInstance) {
10525 // Build a new class message send to 'super'.
10526 SmallVector<SourceLocation, 16> SelLocs;
10527 E->getSelectorLocs(SelLocs);
10528 return getDerived().RebuildObjCMessageExpr(E->getSuperLoc(),
10529 E->getSelector(),
10530 SelLocs,
Argyrios Kyrtzidisc2a58912015-07-28 06:12:24 +000010531 E->getReceiverType(),
Fariborz Jahaniana8c2a0b02015-03-30 23:30:24 +000010532 E->getMethodDecl(),
10533 E->getLeftLoc(),
10534 Args,
10535 E->getRightLoc());
10536 }
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010537
10538 // Instance message: transform the receiver
10539 assert(E->getReceiverKind() == ObjCMessageExpr::Instance &&
10540 "Only class and instance messages may be instantiated");
John McCalldadc5752010-08-24 06:29:42 +000010541 ExprResult Receiver
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010542 = getDerived().TransformExpr(E->getInstanceReceiver());
10543 if (Receiver.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010544 return ExprError();
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010545
10546 // If nothing changed, just retain the existing message send.
10547 if (!getDerived().AlwaysRebuild() &&
10548 Receiver.get() == E->getInstanceReceiver() && !ArgChanged)
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010549 return SemaRef.MaybeBindToTemporary(E);
Chad Rosier1dcde962012-08-08 18:46:20 +000010550
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010551 // Build a new instance message send.
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010552 SmallVector<SourceLocation, 16> SelLocs;
10553 E->getSelectorLocs(SelLocs);
John McCallb268a282010-08-23 23:25:46 +000010554 return getDerived().RebuildObjCMessageExpr(Receiver.get(),
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010555 E->getSelector(),
Argyrios Kyrtzidisa6011e22011-10-03 06:36:51 +000010556 SelLocs,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010557 E->getMethodDecl(),
10558 E->getLeftLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010559 Args,
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010560 E->getRightLoc());
Douglas Gregora16548e2009-08-11 05:31:07 +000010561}
10562
Mike Stump11289f42009-09-09 15:08:12 +000010563template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010564ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010565TreeTransform<Derived>::TransformObjCSelectorExpr(ObjCSelectorExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010566 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010567}
10568
Mike Stump11289f42009-09-09 15:08:12 +000010569template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010570ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010571TreeTransform<Derived>::TransformObjCProtocolExpr(ObjCProtocolExpr *E) {
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010572 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010573}
10574
Mike Stump11289f42009-09-09 15:08:12 +000010575template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010576ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010577TreeTransform<Derived>::TransformObjCIvarRefExpr(ObjCIvarRefExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010578 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010579 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010580 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010581 return ExprError();
Douglas Gregord51d90d2010-04-26 20:11:03 +000010582
10583 // We don't need to transform the ivar; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010584
Douglas Gregord51d90d2010-04-26 20:11:03 +000010585 // If nothing changed, just retain the existing expression.
10586 if (!getDerived().AlwaysRebuild() &&
10587 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010588 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010589
John McCallb268a282010-08-23 23:25:46 +000010590 return getDerived().RebuildObjCIvarRefExpr(Base.get(), E->getDecl(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010591 E->getLocation(),
10592 E->isArrow(), E->isFreeIvar());
Douglas Gregora16548e2009-08-11 05:31:07 +000010593}
10594
Mike Stump11289f42009-09-09 15:08:12 +000010595template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010596ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010597TreeTransform<Derived>::TransformObjCPropertyRefExpr(ObjCPropertyRefExpr *E) {
John McCallb7bd14f2010-12-02 01:19:52 +000010598 // 'super' and types never change. Property never changes. Just
10599 // retain the existing expression.
10600 if (!E->isObjectReceiver())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010601 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010602
Douglas Gregor9faee212010-04-26 20:47:02 +000010603 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010604 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregor9faee212010-04-26 20:47:02 +000010605 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010606 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010607
Douglas Gregor9faee212010-04-26 20:47:02 +000010608 // We don't need to transform the property; it will never change.
Chad Rosier1dcde962012-08-08 18:46:20 +000010609
Douglas Gregor9faee212010-04-26 20:47:02 +000010610 // If nothing changed, just retain the existing expression.
10611 if (!getDerived().AlwaysRebuild() &&
10612 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010613 return E;
Douglas Gregora16548e2009-08-11 05:31:07 +000010614
John McCallb7bd14f2010-12-02 01:19:52 +000010615 if (E->isExplicitProperty())
10616 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
10617 E->getExplicitProperty(),
10618 E->getLocation());
10619
10620 return getDerived().RebuildObjCPropertyRefExpr(Base.get(),
John McCall526ab472011-10-25 17:37:35 +000010621 SemaRef.Context.PseudoObjectTy,
John McCallb7bd14f2010-12-02 01:19:52 +000010622 E->getImplicitPropertyGetter(),
10623 E->getImplicitPropertySetter(),
10624 E->getLocation());
Douglas Gregora16548e2009-08-11 05:31:07 +000010625}
10626
Mike Stump11289f42009-09-09 15:08:12 +000010627template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010628ExprResult
Ted Kremeneke65b0862012-03-06 20:05:56 +000010629TreeTransform<Derived>::TransformObjCSubscriptRefExpr(ObjCSubscriptRefExpr *E) {
10630 // Transform the base expression.
10631 ExprResult Base = getDerived().TransformExpr(E->getBaseExpr());
10632 if (Base.isInvalid())
10633 return ExprError();
10634
10635 // Transform the key expression.
10636 ExprResult Key = getDerived().TransformExpr(E->getKeyExpr());
10637 if (Key.isInvalid())
10638 return ExprError();
10639
10640 // If nothing changed, just retain the existing expression.
10641 if (!getDerived().AlwaysRebuild() &&
10642 Key.get() == E->getKeyExpr() && Base.get() == E->getBaseExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010643 return E;
Ted Kremeneke65b0862012-03-06 20:05:56 +000010644
Chad Rosier1dcde962012-08-08 18:46:20 +000010645 return getDerived().RebuildObjCSubscriptRefExpr(E->getRBracket(),
Ted Kremeneke65b0862012-03-06 20:05:56 +000010646 Base.get(), Key.get(),
10647 E->getAtIndexMethodDecl(),
10648 E->setAtIndexMethodDecl());
10649}
10650
10651template<typename Derived>
10652ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010653TreeTransform<Derived>::TransformObjCIsaExpr(ObjCIsaExpr *E) {
Douglas Gregord51d90d2010-04-26 20:11:03 +000010654 // Transform the base expression.
John McCalldadc5752010-08-24 06:29:42 +000010655 ExprResult Base = getDerived().TransformExpr(E->getBase());
Douglas Gregord51d90d2010-04-26 20:11:03 +000010656 if (Base.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000010657 return ExprError();
Chad Rosier1dcde962012-08-08 18:46:20 +000010658
Douglas Gregord51d90d2010-04-26 20:11:03 +000010659 // If nothing changed, just retain the existing expression.
10660 if (!getDerived().AlwaysRebuild() &&
10661 Base.get() == E->getBase())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010662 return E;
Chad Rosier1dcde962012-08-08 18:46:20 +000010663
John McCallb268a282010-08-23 23:25:46 +000010664 return getDerived().RebuildObjCIsaExpr(Base.get(), E->getIsaMemberLoc(),
Fariborz Jahanian06bb7f72013-03-28 19:50:55 +000010665 E->getOpLoc(),
Douglas Gregord51d90d2010-04-26 20:11:03 +000010666 E->isArrow());
Douglas Gregora16548e2009-08-11 05:31:07 +000010667}
10668
Mike Stump11289f42009-09-09 15:08:12 +000010669template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010670ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010671TreeTransform<Derived>::TransformShuffleVectorExpr(ShuffleVectorExpr *E) {
Douglas Gregora16548e2009-08-11 05:31:07 +000010672 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010673 SmallVector<Expr*, 8> SubExprs;
Douglas Gregora3efea12011-01-03 19:04:46 +000010674 SubExprs.reserve(E->getNumSubExprs());
Chad Rosier1dcde962012-08-08 18:46:20 +000010675 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
Douglas Gregora3efea12011-01-03 19:04:46 +000010676 SubExprs, &ArgumentChanged))
10677 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000010678
Douglas Gregora16548e2009-08-11 05:31:07 +000010679 if (!getDerived().AlwaysRebuild() &&
10680 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010681 return E;
Mike Stump11289f42009-09-09 15:08:12 +000010682
Douglas Gregora16548e2009-08-11 05:31:07 +000010683 return getDerived().RebuildShuffleVectorExpr(E->getBuiltinLoc(),
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010684 SubExprs,
Douglas Gregora16548e2009-08-11 05:31:07 +000010685 E->getRParenLoc());
10686}
10687
Mike Stump11289f42009-09-09 15:08:12 +000010688template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010689ExprResult
Hal Finkelc4d7c822013-09-18 03:29:45 +000010690TreeTransform<Derived>::TransformConvertVectorExpr(ConvertVectorExpr *E) {
10691 ExprResult SrcExpr = getDerived().TransformExpr(E->getSrcExpr());
10692 if (SrcExpr.isInvalid())
10693 return ExprError();
10694
10695 TypeSourceInfo *Type = getDerived().TransformType(E->getTypeSourceInfo());
10696 if (!Type)
10697 return ExprError();
10698
10699 if (!getDerived().AlwaysRebuild() &&
10700 Type == E->getTypeSourceInfo() &&
10701 SrcExpr.get() == E->getSrcExpr())
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010702 return E;
Hal Finkelc4d7c822013-09-18 03:29:45 +000010703
10704 return getDerived().RebuildConvertVectorExpr(E->getBuiltinLoc(),
10705 SrcExpr.get(), Type,
10706 E->getRParenLoc());
10707}
10708
10709template<typename Derived>
10710ExprResult
John McCall47f29ea2009-12-08 09:21:05 +000010711TreeTransform<Derived>::TransformBlockExpr(BlockExpr *E) {
John McCall490112f2011-02-04 18:33:18 +000010712 BlockDecl *oldBlock = E->getBlockDecl();
Chad Rosier1dcde962012-08-08 18:46:20 +000010713
Craig Topperc3ec1492014-05-26 06:22:03 +000010714 SemaRef.ActOnBlockStart(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall490112f2011-02-04 18:33:18 +000010715 BlockScopeInfo *blockScope = SemaRef.getCurBlock();
10716
10717 blockScope->TheDecl->setIsVariadic(oldBlock->isVariadic());
Fariborz Jahaniandd5eb9d2011-12-03 17:47:53 +000010718 blockScope->TheDecl->setBlockMissingReturnType(
10719 oldBlock->blockMissingReturnType());
Chad Rosier1dcde962012-08-08 18:46:20 +000010720
Chris Lattner01cf8db2011-07-20 06:58:45 +000010721 SmallVector<ParmVarDecl*, 4> params;
10722 SmallVector<QualType, 4> paramTypes;
Chad Rosier1dcde962012-08-08 18:46:20 +000010723
Fariborz Jahanian1babe772010-07-09 18:44:02 +000010724 // Parameter substitution.
John McCall490112f2011-02-04 18:33:18 +000010725 if (getDerived().TransformFunctionTypeParams(E->getCaretLocation(),
10726 oldBlock->param_begin(),
10727 oldBlock->param_size(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010728 nullptr, paramTypes, &params)) {
10729 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
Douglas Gregorc7f46f22011-12-10 00:23:21 +000010730 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010731 }
John McCall490112f2011-02-04 18:33:18 +000010732
Jordan Rosea0a86be2013-03-08 22:25:36 +000010733 const FunctionProtoType *exprFunctionType = E->getFunctionType();
Eli Friedman34b49062012-01-26 03:00:14 +000010734 QualType exprResultType =
Alp Toker314cc812014-01-25 16:55:45 +000010735 getDerived().TransformType(exprFunctionType->getReturnType());
Douglas Gregor476e3022011-01-19 21:32:01 +000010736
Jordan Rose5c382722013-03-08 21:51:21 +000010737 QualType functionType =
10738 getDerived().RebuildFunctionProtoType(exprResultType, paramTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010739 exprFunctionType->getExtProtoInfo());
John McCall490112f2011-02-04 18:33:18 +000010740 blockScope->FunctionType = functionType;
John McCall3882ace2011-01-05 12:14:39 +000010741
10742 // Set the parameters on the block decl.
John McCall490112f2011-02-04 18:33:18 +000010743 if (!params.empty())
David Blaikie9c70e042011-09-21 18:16:56 +000010744 blockScope->TheDecl->setParams(params);
Eli Friedman34b49062012-01-26 03:00:14 +000010745
10746 if (!oldBlock->blockMissingReturnType()) {
10747 blockScope->HasImplicitReturnType = false;
10748 blockScope->ReturnType = exprResultType;
10749 }
Chad Rosier1dcde962012-08-08 18:46:20 +000010750
John McCall3882ace2011-01-05 12:14:39 +000010751 // Transform the body
John McCall490112f2011-02-04 18:33:18 +000010752 StmtResult body = getDerived().TransformStmt(E->getBody());
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010753 if (body.isInvalid()) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010754 getSema().ActOnBlockError(E->getCaretLocation(), /*Scope=*/nullptr);
John McCall3882ace2011-01-05 12:14:39 +000010755 return ExprError();
Argyrios Kyrtzidis34172b82012-01-25 03:53:04 +000010756 }
John McCall3882ace2011-01-05 12:14:39 +000010757
John McCall490112f2011-02-04 18:33:18 +000010758#ifndef NDEBUG
10759 // In builds with assertions, make sure that we captured everything we
10760 // captured before.
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010761 if (!SemaRef.getDiagnostics().hasErrorOccurred()) {
Aaron Ballman9371dd22014-03-14 18:34:04 +000010762 for (const auto &I : oldBlock->captures()) {
10763 VarDecl *oldCapture = I.getVariable();
John McCall490112f2011-02-04 18:33:18 +000010764
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010765 // Ignore parameter packs.
10766 if (isa<ParmVarDecl>(oldCapture) &&
10767 cast<ParmVarDecl>(oldCapture)->isParameterPack())
10768 continue;
John McCall490112f2011-02-04 18:33:18 +000010769
Douglas Gregor4385d8b2011-05-20 15:32:55 +000010770 VarDecl *newCapture =
10771 cast<VarDecl>(getDerived().TransformDecl(E->getCaretLocation(),
10772 oldCapture));
10773 assert(blockScope->CaptureMap.count(newCapture));
10774 }
Douglas Gregor3a08c1c2012-02-24 17:41:38 +000010775 assert(oldBlock->capturesCXXThis() == blockScope->isCXXThisCaptured());
John McCall490112f2011-02-04 18:33:18 +000010776 }
10777#endif
10778
10779 return SemaRef.ActOnBlockStmtExpr(E->getCaretLocation(), body.get(),
Craig Topperc3ec1492014-05-26 06:22:03 +000010780 /*Scope=*/nullptr);
Douglas Gregora16548e2009-08-11 05:31:07 +000010781}
10782
Mike Stump11289f42009-09-09 15:08:12 +000010783template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000010784ExprResult
Tanya Lattner55808c12011-06-04 00:47:47 +000010785TreeTransform<Derived>::TransformAsTypeExpr(AsTypeExpr *E) {
David Blaikie83d382b2011-09-23 05:06:16 +000010786 llvm_unreachable("Cannot transform asType expressions yet");
Tanya Lattner55808c12011-06-04 00:47:47 +000010787}
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010788
10789template<typename Derived>
10790ExprResult
10791TreeTransform<Derived>::TransformAtomicExpr(AtomicExpr *E) {
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010792 QualType RetTy = getDerived().TransformType(E->getType());
10793 bool ArgumentChanged = false;
Benjamin Kramerf0623432012-08-23 22:51:59 +000010794 SmallVector<Expr*, 8> SubExprs;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010795 SubExprs.reserve(E->getNumSubExprs());
10796 if (getDerived().TransformExprs(E->getSubExprs(), E->getNumSubExprs(), false,
10797 SubExprs, &ArgumentChanged))
10798 return ExprError();
10799
10800 if (!getDerived().AlwaysRebuild() &&
10801 !ArgumentChanged)
Nikola Smiljanic03ff2592014-05-29 14:05:12 +000010802 return E;
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010803
Benjamin Kramer62b95d82012-08-23 21:35:17 +000010804 return getDerived().RebuildAtomicExpr(E->getBuiltinLoc(), SubExprs,
Eli Friedman8d3e43f2011-10-14 22:48:56 +000010805 RetTy, E->getOp(), E->getRParenLoc());
Eli Friedmandf14b3a2011-10-11 02:20:01 +000010806}
Chad Rosier1dcde962012-08-08 18:46:20 +000010807
Douglas Gregora16548e2009-08-11 05:31:07 +000010808//===----------------------------------------------------------------------===//
Douglas Gregord6ff3322009-08-04 16:50:30 +000010809// Type reconstruction
10810//===----------------------------------------------------------------------===//
10811
Mike Stump11289f42009-09-09 15:08:12 +000010812template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010813QualType TreeTransform<Derived>::RebuildPointerType(QualType PointeeType,
10814 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010815 return SemaRef.BuildPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010816 getDerived().getBaseEntity());
10817}
10818
Mike Stump11289f42009-09-09 15:08:12 +000010819template<typename Derived>
John McCall70dd5f62009-10-30 00:06:24 +000010820QualType TreeTransform<Derived>::RebuildBlockPointerType(QualType PointeeType,
10821 SourceLocation Star) {
John McCallcb0f89a2010-06-05 06:41:15 +000010822 return SemaRef.BuildBlockPointerType(PointeeType, Star,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010823 getDerived().getBaseEntity());
10824}
10825
Mike Stump11289f42009-09-09 15:08:12 +000010826template<typename Derived>
10827QualType
John McCall70dd5f62009-10-30 00:06:24 +000010828TreeTransform<Derived>::RebuildReferenceType(QualType ReferentType,
10829 bool WrittenAsLValue,
10830 SourceLocation Sigil) {
John McCallcb0f89a2010-06-05 06:41:15 +000010831 return SemaRef.BuildReferenceType(ReferentType, WrittenAsLValue,
John McCall70dd5f62009-10-30 00:06:24 +000010832 Sigil, getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010833}
10834
10835template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010836QualType
John McCall70dd5f62009-10-30 00:06:24 +000010837TreeTransform<Derived>::RebuildMemberPointerType(QualType PointeeType,
10838 QualType ClassType,
10839 SourceLocation Sigil) {
Reid Kleckner0503a872013-12-05 01:23:43 +000010840 return SemaRef.BuildMemberPointerType(PointeeType, ClassType, Sigil,
10841 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010842}
10843
10844template<typename Derived>
Douglas Gregor9bda6cf2015-07-07 03:58:14 +000010845QualType TreeTransform<Derived>::RebuildObjCObjectType(
10846 QualType BaseType,
10847 SourceLocation Loc,
10848 SourceLocation TypeArgsLAngleLoc,
10849 ArrayRef<TypeSourceInfo *> TypeArgs,
10850 SourceLocation TypeArgsRAngleLoc,
10851 SourceLocation ProtocolLAngleLoc,
10852 ArrayRef<ObjCProtocolDecl *> Protocols,
10853 ArrayRef<SourceLocation> ProtocolLocs,
10854 SourceLocation ProtocolRAngleLoc) {
10855 return SemaRef.BuildObjCObjectType(BaseType, Loc, TypeArgsLAngleLoc,
10856 TypeArgs, TypeArgsRAngleLoc,
10857 ProtocolLAngleLoc, Protocols, ProtocolLocs,
10858 ProtocolRAngleLoc,
10859 /*FailOnError=*/true);
10860}
10861
10862template<typename Derived>
10863QualType TreeTransform<Derived>::RebuildObjCObjectPointerType(
10864 QualType PointeeType,
10865 SourceLocation Star) {
10866 return SemaRef.Context.getObjCObjectPointerType(PointeeType);
10867}
10868
10869template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010870QualType
Douglas Gregord6ff3322009-08-04 16:50:30 +000010871TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
10872 ArrayType::ArraySizeModifier SizeMod,
10873 const llvm::APInt *Size,
10874 Expr *SizeExpr,
10875 unsigned IndexTypeQuals,
10876 SourceRange BracketsRange) {
10877 if (SizeExpr || !Size)
10878 return SemaRef.BuildArrayType(ElementType, SizeMod, SizeExpr,
10879 IndexTypeQuals, BracketsRange,
10880 getDerived().getBaseEntity());
Mike Stump11289f42009-09-09 15:08:12 +000010881
10882 QualType Types[] = {
10883 SemaRef.Context.UnsignedCharTy, SemaRef.Context.UnsignedShortTy,
10884 SemaRef.Context.UnsignedIntTy, SemaRef.Context.UnsignedLongTy,
10885 SemaRef.Context.UnsignedLongLongTy, SemaRef.Context.UnsignedInt128Ty
Douglas Gregord6ff3322009-08-04 16:50:30 +000010886 };
Craig Toppere5ce8312013-07-15 03:38:40 +000010887 const unsigned NumTypes = llvm::array_lengthof(Types);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010888 QualType SizeType;
10889 for (unsigned I = 0; I != NumTypes; ++I)
10890 if (Size->getBitWidth() == SemaRef.Context.getIntWidth(Types[I])) {
10891 SizeType = Types[I];
10892 break;
10893 }
Mike Stump11289f42009-09-09 15:08:12 +000010894
Eli Friedman9562f392012-01-25 23:20:27 +000010895 // Note that we can return a VariableArrayType here in the case where
10896 // the element type was a dependent VariableArrayType.
10897 IntegerLiteral *ArraySize
10898 = IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
10899 /*FIXME*/BracketsRange.getBegin());
10900 return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010901 IndexTypeQuals, BracketsRange,
Mike Stump11289f42009-09-09 15:08:12 +000010902 getDerived().getBaseEntity());
Douglas Gregord6ff3322009-08-04 16:50:30 +000010903}
Mike Stump11289f42009-09-09 15:08:12 +000010904
Douglas Gregord6ff3322009-08-04 16:50:30 +000010905template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010906QualType
10907TreeTransform<Derived>::RebuildConstantArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010908 ArrayType::ArraySizeModifier SizeMod,
10909 const llvm::APInt &Size,
John McCall70dd5f62009-10-30 00:06:24 +000010910 unsigned IndexTypeQuals,
10911 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010912 return getDerived().RebuildArrayType(ElementType, SizeMod, &Size, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010913 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010914}
10915
10916template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010917QualType
Mike Stump11289f42009-09-09 15:08:12 +000010918TreeTransform<Derived>::RebuildIncompleteArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010919 ArrayType::ArraySizeModifier SizeMod,
John McCall70dd5f62009-10-30 00:06:24 +000010920 unsigned IndexTypeQuals,
10921 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010922 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr, nullptr,
John McCall70dd5f62009-10-30 00:06:24 +000010923 IndexTypeQuals, BracketsRange);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010924}
Mike Stump11289f42009-09-09 15:08:12 +000010925
Douglas Gregord6ff3322009-08-04 16:50:30 +000010926template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010927QualType
10928TreeTransform<Derived>::RebuildVariableArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010929 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010930 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010931 unsigned IndexTypeQuals,
10932 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010933 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010934 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010935 IndexTypeQuals, BracketsRange);
10936}
10937
10938template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010939QualType
10940TreeTransform<Derived>::RebuildDependentSizedArrayType(QualType ElementType,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010941 ArrayType::ArraySizeModifier SizeMod,
John McCallb268a282010-08-23 23:25:46 +000010942 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010943 unsigned IndexTypeQuals,
10944 SourceRange BracketsRange) {
Craig Topperc3ec1492014-05-26 06:22:03 +000010945 return getDerived().RebuildArrayType(ElementType, SizeMod, nullptr,
John McCallb268a282010-08-23 23:25:46 +000010946 SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010947 IndexTypeQuals, BracketsRange);
10948}
10949
10950template<typename Derived>
10951QualType TreeTransform<Derived>::RebuildVectorType(QualType ElementType,
Bob Wilsonaeb56442010-11-10 21:56:12 +000010952 unsigned NumElements,
10953 VectorType::VectorKind VecKind) {
Douglas Gregord6ff3322009-08-04 16:50:30 +000010954 // FIXME: semantic checking!
Bob Wilsonaeb56442010-11-10 21:56:12 +000010955 return SemaRef.Context.getVectorType(ElementType, NumElements, VecKind);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010956}
Mike Stump11289f42009-09-09 15:08:12 +000010957
Douglas Gregord6ff3322009-08-04 16:50:30 +000010958template<typename Derived>
10959QualType TreeTransform<Derived>::RebuildExtVectorType(QualType ElementType,
10960 unsigned NumElements,
10961 SourceLocation AttributeLoc) {
10962 llvm::APInt numElements(SemaRef.Context.getIntWidth(SemaRef.Context.IntTy),
10963 NumElements, true);
10964 IntegerLiteral *VectorSize
Argyrios Kyrtzidis43b20572010-08-28 09:06:06 +000010965 = IntegerLiteral::Create(SemaRef.Context, numElements, SemaRef.Context.IntTy,
10966 AttributeLoc);
John McCallb268a282010-08-23 23:25:46 +000010967 return SemaRef.BuildExtVectorType(ElementType, VectorSize, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010968}
Mike Stump11289f42009-09-09 15:08:12 +000010969
Douglas Gregord6ff3322009-08-04 16:50:30 +000010970template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000010971QualType
10972TreeTransform<Derived>::RebuildDependentSizedExtVectorType(QualType ElementType,
John McCallb268a282010-08-23 23:25:46 +000010973 Expr *SizeExpr,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010974 SourceLocation AttributeLoc) {
John McCallb268a282010-08-23 23:25:46 +000010975 return SemaRef.BuildExtVectorType(ElementType, SizeExpr, AttributeLoc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010976}
Mike Stump11289f42009-09-09 15:08:12 +000010977
Douglas Gregord6ff3322009-08-04 16:50:30 +000010978template<typename Derived>
Jordan Rose5c382722013-03-08 21:51:21 +000010979QualType TreeTransform<Derived>::RebuildFunctionProtoType(
10980 QualType T,
Craig Toppere3d2ecbe2014-06-28 23:22:33 +000010981 MutableArrayRef<QualType> ParamTypes,
Jordan Rosea0a86be2013-03-08 22:25:36 +000010982 const FunctionProtoType::ExtProtoInfo &EPI) {
10983 return SemaRef.BuildFunctionType(T, ParamTypes,
Douglas Gregord6ff3322009-08-04 16:50:30 +000010984 getDerived().getBaseLocation(),
Eli Friedmand8725a92010-08-05 02:54:05 +000010985 getDerived().getBaseEntity(),
Jordan Rosea0a86be2013-03-08 22:25:36 +000010986 EPI);
Douglas Gregord6ff3322009-08-04 16:50:30 +000010987}
Mike Stump11289f42009-09-09 15:08:12 +000010988
Douglas Gregord6ff3322009-08-04 16:50:30 +000010989template<typename Derived>
John McCall550e0c22009-10-21 00:40:46 +000010990QualType TreeTransform<Derived>::RebuildFunctionNoProtoType(QualType T) {
10991 return SemaRef.Context.getFunctionNoProtoType(T);
10992}
10993
10994template<typename Derived>
John McCallb96ec562009-12-04 22:46:56 +000010995QualType TreeTransform<Derived>::RebuildUnresolvedUsingType(Decl *D) {
10996 assert(D && "no decl found");
10997 if (D->isInvalidDecl()) return QualType();
10998
Douglas Gregorc298ffc2010-04-22 16:44:27 +000010999 // FIXME: Doesn't account for ObjCInterfaceDecl!
John McCallb96ec562009-12-04 22:46:56 +000011000 TypeDecl *Ty;
11001 if (isa<UsingDecl>(D)) {
11002 UsingDecl *Using = cast<UsingDecl>(D);
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +000011003 assert(Using->hasTypename() &&
John McCallb96ec562009-12-04 22:46:56 +000011004 "UnresolvedUsingTypenameDecl transformed to non-typename using");
11005
11006 // A valid resolved using typename decl points to exactly one type decl.
11007 assert(++Using->shadow_begin() == Using->shadow_end());
11008 Ty = cast<TypeDecl>((*Using->shadow_begin())->getTargetDecl());
Chad Rosier1dcde962012-08-08 18:46:20 +000011009
John McCallb96ec562009-12-04 22:46:56 +000011010 } else {
11011 assert(isa<UnresolvedUsingTypenameDecl>(D) &&
11012 "UnresolvedUsingTypenameDecl transformed to non-using decl");
11013 Ty = cast<UnresolvedUsingTypenameDecl>(D);
11014 }
11015
11016 return SemaRef.Context.getTypeDeclType(Ty);
11017}
11018
11019template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011020QualType TreeTransform<Derived>::RebuildTypeOfExprType(Expr *E,
11021 SourceLocation Loc) {
11022 return SemaRef.BuildTypeofExprType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011023}
11024
11025template<typename Derived>
11026QualType TreeTransform<Derived>::RebuildTypeOfType(QualType Underlying) {
11027 return SemaRef.Context.getTypeOfType(Underlying);
11028}
11029
11030template<typename Derived>
John McCall36e7fe32010-10-12 00:20:44 +000011031QualType TreeTransform<Derived>::RebuildDecltypeType(Expr *E,
11032 SourceLocation Loc) {
11033 return SemaRef.BuildDecltypeType(E, Loc);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011034}
11035
11036template<typename Derived>
Alexis Hunte852b102011-05-24 22:41:36 +000011037QualType TreeTransform<Derived>::RebuildUnaryTransformType(QualType BaseType,
11038 UnaryTransformType::UTTKind UKind,
11039 SourceLocation Loc) {
11040 return SemaRef.BuildUnaryTransformType(BaseType, UKind, Loc);
11041}
11042
11043template<typename Derived>
Douglas Gregord6ff3322009-08-04 16:50:30 +000011044QualType TreeTransform<Derived>::RebuildTemplateSpecializationType(
John McCall0ad16662009-10-29 08:12:44 +000011045 TemplateName Template,
11046 SourceLocation TemplateNameLoc,
Douglas Gregor739b107a2011-03-03 02:41:12 +000011047 TemplateArgumentListInfo &TemplateArgs) {
John McCall6b51f282009-11-23 01:53:49 +000011048 return SemaRef.CheckTemplateIdType(Template, TemplateNameLoc, TemplateArgs);
Douglas Gregord6ff3322009-08-04 16:50:30 +000011049}
Mike Stump11289f42009-09-09 15:08:12 +000011050
Douglas Gregor1135c352009-08-06 05:28:30 +000011051template<typename Derived>
Eli Friedman0dfb8892011-10-06 23:00:33 +000011052QualType TreeTransform<Derived>::RebuildAtomicType(QualType ValueType,
11053 SourceLocation KWLoc) {
11054 return SemaRef.BuildAtomicType(ValueType, KWLoc);
11055}
11056
11057template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011058TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011059TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011060 bool TemplateKW,
11061 TemplateDecl *Template) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011062 return SemaRef.Context.getQualifiedTemplateName(SS.getScopeRep(), TemplateKW,
Douglas Gregor71dc5092009-08-06 06:41:21 +000011063 Template);
11064}
11065
11066template<typename Derived>
Mike Stump11289f42009-09-09 15:08:12 +000011067TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011068TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
11069 const IdentifierInfo &Name,
11070 SourceLocation NameLoc,
John McCall31f82722010-11-12 08:19:04 +000011071 QualType ObjectType,
11072 NamedDecl *FirstQualifierInScope) {
Douglas Gregor9db53502011-03-02 18:07:45 +000011073 UnqualifiedId TemplateName;
11074 TemplateName.setIdentifier(&Name, NameLoc);
Douglas Gregorbb119652010-06-16 23:00:59 +000011075 Sema::TemplateTy Template;
Abramo Bagnara7945c982012-01-27 09:46:47 +000011076 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Craig Topperc3ec1492014-05-26 06:22:03 +000011077 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011078 SS, TemplateKWLoc, TemplateName,
John McCallba7bf592010-08-24 05:47:05 +000011079 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011080 /*EnteringContext=*/false,
11081 Template);
John McCall31f82722010-11-12 08:19:04 +000011082 return Template.get();
Douglas Gregor71dc5092009-08-06 06:41:21 +000011083}
Mike Stump11289f42009-09-09 15:08:12 +000011084
Douglas Gregora16548e2009-08-11 05:31:07 +000011085template<typename Derived>
Douglas Gregor71395fa2009-11-04 00:56:37 +000011086TemplateName
Douglas Gregor9db53502011-03-02 18:07:45 +000011087TreeTransform<Derived>::RebuildTemplateName(CXXScopeSpec &SS,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011088 OverloadedOperatorKind Operator,
Douglas Gregor9db53502011-03-02 18:07:45 +000011089 SourceLocation NameLoc,
Douglas Gregor71395fa2009-11-04 00:56:37 +000011090 QualType ObjectType) {
Douglas Gregor71395fa2009-11-04 00:56:37 +000011091 UnqualifiedId Name;
Douglas Gregor9db53502011-03-02 18:07:45 +000011092 // FIXME: Bogus location information.
Abramo Bagnara7945c982012-01-27 09:46:47 +000011093 SourceLocation SymbolLocations[3] = { NameLoc, NameLoc, NameLoc };
Douglas Gregor9db53502011-03-02 18:07:45 +000011094 Name.setOperatorFunctionId(NameLoc, Operator, SymbolLocations);
Abramo Bagnara7945c982012-01-27 09:46:47 +000011095 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
Douglas Gregorbb119652010-06-16 23:00:59 +000011096 Sema::TemplateTy Template;
Craig Topperc3ec1492014-05-26 06:22:03 +000011097 getSema().ActOnDependentTemplateName(/*Scope=*/nullptr,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011098 SS, TemplateKWLoc, Name,
John McCallba7bf592010-08-24 05:47:05 +000011099 ParsedType::make(ObjectType),
Douglas Gregorbb119652010-06-16 23:00:59 +000011100 /*EnteringContext=*/false,
11101 Template);
Serge Pavlov9ddb76e2013-08-27 13:15:56 +000011102 return Template.get();
Douglas Gregor71395fa2009-11-04 00:56:37 +000011103}
Chad Rosier1dcde962012-08-08 18:46:20 +000011104
Douglas Gregor71395fa2009-11-04 00:56:37 +000011105template<typename Derived>
John McCalldadc5752010-08-24 06:29:42 +000011106ExprResult
Douglas Gregora16548e2009-08-11 05:31:07 +000011107TreeTransform<Derived>::RebuildCXXOperatorCallExpr(OverloadedOperatorKind Op,
11108 SourceLocation OpLoc,
John McCallb268a282010-08-23 23:25:46 +000011109 Expr *OrigCallee,
11110 Expr *First,
11111 Expr *Second) {
11112 Expr *Callee = OrigCallee->IgnoreParenCasts();
11113 bool isPostIncDec = Second && (Op == OO_PlusPlus || Op == OO_MinusMinus);
Mike Stump11289f42009-09-09 15:08:12 +000011114
Argyrios Kyrtzidis0f995372014-06-19 14:45:16 +000011115 if (First->getObjectKind() == OK_ObjCProperty) {
11116 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
11117 if (BinaryOperator::isAssignmentOp(Opc))
11118 return SemaRef.checkPseudoObjectAssignment(/*Scope=*/nullptr, OpLoc, Opc,
11119 First, Second);
11120 ExprResult Result = SemaRef.CheckPlaceholderExpr(First);
11121 if (Result.isInvalid())
11122 return ExprError();
11123 First = Result.get();
11124 }
11125
11126 if (Second && Second->getObjectKind() == OK_ObjCProperty) {
11127 ExprResult Result = SemaRef.CheckPlaceholderExpr(Second);
11128 if (Result.isInvalid())
11129 return ExprError();
11130 Second = Result.get();
11131 }
11132
Douglas Gregora16548e2009-08-11 05:31:07 +000011133 // Determine whether this should be a builtin operation.
Sebastian Redladba46e2009-10-29 20:17:01 +000011134 if (Op == OO_Subscript) {
John McCallb268a282010-08-23 23:25:46 +000011135 if (!First->getType()->isOverloadableType() &&
11136 !Second->getType()->isOverloadableType())
11137 return getSema().CreateBuiltinArraySubscriptExpr(First,
11138 Callee->getLocStart(),
11139 Second, OpLoc);
Eli Friedmanf2f534d2009-11-16 19:13:03 +000011140 } else if (Op == OO_Arrow) {
11141 // -> is never a builtin operation.
Craig Topperc3ec1492014-05-26 06:22:03 +000011142 return SemaRef.BuildOverloadedArrowExpr(nullptr, First, OpLoc);
11143 } else if (Second == nullptr || isPostIncDec) {
John McCallb268a282010-08-23 23:25:46 +000011144 if (!First->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011145 // The argument is not of overloadable type, so try to create a
11146 // built-in unary operation.
John McCalle3027922010-08-25 11:45:40 +000011147 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011148 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
Mike Stump11289f42009-09-09 15:08:12 +000011149
John McCallb268a282010-08-23 23:25:46 +000011150 return getSema().CreateBuiltinUnaryOp(OpLoc, Opc, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011151 }
11152 } else {
John McCallb268a282010-08-23 23:25:46 +000011153 if (!First->getType()->isOverloadableType() &&
11154 !Second->getType()->isOverloadableType()) {
Douglas Gregora16548e2009-08-11 05:31:07 +000011155 // Neither of the arguments is an overloadable type, so try to
11156 // create a built-in binary operation.
John McCalle3027922010-08-25 11:45:40 +000011157 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011158 ExprResult Result
John McCallb268a282010-08-23 23:25:46 +000011159 = SemaRef.CreateBuiltinBinOp(OpLoc, Opc, First, Second);
Douglas Gregora16548e2009-08-11 05:31:07 +000011160 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011161 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011162
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011163 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011164 }
11165 }
Mike Stump11289f42009-09-09 15:08:12 +000011166
11167 // Compute the transformed set of functions (and function templates) to be
Douglas Gregora16548e2009-08-11 05:31:07 +000011168 // used during overload resolution.
John McCall4c4c1df2010-01-26 03:27:55 +000011169 UnresolvedSet<16> Functions;
Mike Stump11289f42009-09-09 15:08:12 +000011170
John McCallb268a282010-08-23 23:25:46 +000011171 if (UnresolvedLookupExpr *ULE = dyn_cast<UnresolvedLookupExpr>(Callee)) {
John McCalld14a8642009-11-21 08:51:07 +000011172 assert(ULE->requiresADL());
Richard Smith100b24a2014-04-17 01:52:14 +000011173 Functions.append(ULE->decls_begin(), ULE->decls_end());
John McCalld14a8642009-11-21 08:51:07 +000011174 } else {
Richard Smith58db83d2012-11-28 21:47:39 +000011175 // If we've resolved this to a particular non-member function, just call
11176 // that function. If we resolved it to a member function,
11177 // CreateOverloaded* will find that function for us.
11178 NamedDecl *ND = cast<DeclRefExpr>(Callee)->getDecl();
11179 if (!isa<CXXMethodDecl>(ND))
11180 Functions.addDecl(ND);
John McCalld14a8642009-11-21 08:51:07 +000011181 }
Mike Stump11289f42009-09-09 15:08:12 +000011182
Douglas Gregora16548e2009-08-11 05:31:07 +000011183 // Add any functions found via argument-dependent lookup.
John McCallb268a282010-08-23 23:25:46 +000011184 Expr *Args[2] = { First, Second };
Craig Topperc3ec1492014-05-26 06:22:03 +000011185 unsigned NumArgs = 1 + (Second != nullptr);
Mike Stump11289f42009-09-09 15:08:12 +000011186
Douglas Gregora16548e2009-08-11 05:31:07 +000011187 // Create the overloaded operator invocation for unary operators.
11188 if (NumArgs == 1 || isPostIncDec) {
John McCalle3027922010-08-25 11:45:40 +000011189 UnaryOperatorKind Opc
Douglas Gregora16548e2009-08-11 05:31:07 +000011190 = UnaryOperator::getOverloadedOpcode(Op, isPostIncDec);
John McCallb268a282010-08-23 23:25:46 +000011191 return SemaRef.CreateOverloadedUnaryOp(OpLoc, Opc, Functions, First);
Douglas Gregora16548e2009-08-11 05:31:07 +000011192 }
Mike Stump11289f42009-09-09 15:08:12 +000011193
Douglas Gregore9d62932011-07-15 16:25:15 +000011194 if (Op == OO_Subscript) {
11195 SourceLocation LBrace;
11196 SourceLocation RBrace;
11197
11198 if (DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(Callee)) {
NAKAMURA Takumi44d4d9a2014-10-29 08:11:47 +000011199 DeclarationNameLoc NameLoc = DRE->getNameInfo().getInfo();
Douglas Gregore9d62932011-07-15 16:25:15 +000011200 LBrace = SourceLocation::getFromRawEncoding(
11201 NameLoc.CXXOperatorName.BeginOpNameLoc);
11202 RBrace = SourceLocation::getFromRawEncoding(
11203 NameLoc.CXXOperatorName.EndOpNameLoc);
11204 } else {
11205 LBrace = Callee->getLocStart();
11206 RBrace = OpLoc;
11207 }
11208
11209 return SemaRef.CreateOverloadedArraySubscriptExpr(LBrace, RBrace,
11210 First, Second);
11211 }
Sebastian Redladba46e2009-10-29 20:17:01 +000011212
Douglas Gregora16548e2009-08-11 05:31:07 +000011213 // Create the overloaded operator invocation for binary operators.
John McCalle3027922010-08-25 11:45:40 +000011214 BinaryOperatorKind Opc = BinaryOperator::getOverloadedOpcode(Op);
John McCalldadc5752010-08-24 06:29:42 +000011215 ExprResult Result
Douglas Gregora16548e2009-08-11 05:31:07 +000011216 = SemaRef.CreateOverloadedBinOp(OpLoc, Opc, Functions, Args[0], Args[1]);
11217 if (Result.isInvalid())
John McCallfaf5fb42010-08-26 23:41:50 +000011218 return ExprError();
Mike Stump11289f42009-09-09 15:08:12 +000011219
Benjamin Kramer62b95d82012-08-23 21:35:17 +000011220 return Result;
Douglas Gregora16548e2009-08-11 05:31:07 +000011221}
Mike Stump11289f42009-09-09 15:08:12 +000011222
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011223template<typename Derived>
Chad Rosier1dcde962012-08-08 18:46:20 +000011224ExprResult
John McCallb268a282010-08-23 23:25:46 +000011225TreeTransform<Derived>::RebuildCXXPseudoDestructorExpr(Expr *Base,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011226 SourceLocation OperatorLoc,
11227 bool isArrow,
Douglas Gregora6ce6082011-02-25 18:19:59 +000011228 CXXScopeSpec &SS,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011229 TypeSourceInfo *ScopeType,
11230 SourceLocation CCLoc,
Douglas Gregorcdbd5152010-02-24 23:50:37 +000011231 SourceLocation TildeLoc,
Douglas Gregor678f90d2010-02-25 01:56:36 +000011232 PseudoDestructorTypeStorage Destroyed) {
John McCallb268a282010-08-23 23:25:46 +000011233 QualType BaseType = Base->getType();
11234 if (Base->isTypeDependent() || Destroyed.getIdentifier() ||
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011235 (!isArrow && !BaseType->getAs<RecordType>()) ||
Chad Rosier1dcde962012-08-08 18:46:20 +000011236 (isArrow && BaseType->getAs<PointerType>() &&
Gabor Greif5c079262010-02-25 13:04:33 +000011237 !BaseType->getAs<PointerType>()->getPointeeType()
11238 ->template getAs<RecordType>())){
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011239 // This pseudo-destructor expression is still a pseudo-destructor.
David Majnemerced8bdf2015-02-25 17:36:15 +000011240 return SemaRef.BuildPseudoDestructorExpr(
11241 Base, OperatorLoc, isArrow ? tok::arrow : tok::period, SS, ScopeType,
11242 CCLoc, TildeLoc, Destroyed);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011243 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011244
Douglas Gregor678f90d2010-02-25 01:56:36 +000011245 TypeSourceInfo *DestroyedType = Destroyed.getTypeSourceInfo();
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011246 DeclarationName Name(SemaRef.Context.DeclarationNames.getCXXDestructorName(
11247 SemaRef.Context.getCanonicalType(DestroyedType->getType())));
11248 DeclarationNameInfo NameInfo(Name, Destroyed.getLocation());
11249 NameInfo.setNamedTypeInfo(DestroyedType);
11250
Richard Smith8e4a3862012-05-15 06:15:11 +000011251 // The scope type is now known to be a valid nested name specifier
11252 // component. Tack it on to the end of the nested name specifier.
Alexey Bataev2a066812014-10-16 03:04:35 +000011253 if (ScopeType) {
11254 if (!ScopeType->getType()->getAs<TagType>()) {
11255 getSema().Diag(ScopeType->getTypeLoc().getBeginLoc(),
11256 diag::err_expected_class_or_namespace)
11257 << ScopeType->getType() << getSema().getLangOpts().CPlusPlus;
11258 return ExprError();
11259 }
11260 SS.Extend(SemaRef.Context, SourceLocation(), ScopeType->getTypeLoc(),
11261 CCLoc);
11262 }
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011263
Abramo Bagnara7945c982012-01-27 09:46:47 +000011264 SourceLocation TemplateKWLoc; // FIXME: retrieve it from caller.
John McCallb268a282010-08-23 23:25:46 +000011265 return getSema().BuildMemberReferenceExpr(Base, BaseType,
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011266 OperatorLoc, isArrow,
Abramo Bagnara7945c982012-01-27 09:46:47 +000011267 SS, TemplateKWLoc,
Craig Topperc3ec1492014-05-26 06:22:03 +000011268 /*FIXME: FirstQualifier*/ nullptr,
Abramo Bagnarad6d2f182010-08-11 22:01:17 +000011269 NameInfo,
Aaron Ballman6924dcd2015-09-01 14:49:24 +000011270 /*TemplateArgs*/ nullptr,
11271 /*S*/nullptr);
Douglas Gregor651fe5e2010-02-24 23:40:28 +000011272}
11273
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011274template<typename Derived>
11275StmtResult
11276TreeTransform<Derived>::TransformCapturedStmt(CapturedStmt *S) {
Wei Pan17fbf6e2013-05-04 03:59:06 +000011277 SourceLocation Loc = S->getLocStart();
Alexey Bataev9959db52014-05-06 10:08:46 +000011278 CapturedDecl *CD = S->getCapturedDecl();
11279 unsigned NumParams = CD->getNumParams();
11280 unsigned ContextParamPos = CD->getContextParamPosition();
11281 SmallVector<Sema::CapturedParamNameType, 4> Params;
11282 for (unsigned I = 0; I < NumParams; ++I) {
11283 if (I != ContextParamPos) {
11284 Params.push_back(
11285 std::make_pair(
11286 CD->getParam(I)->getName(),
11287 getDerived().TransformType(CD->getParam(I)->getType())));
11288 } else {
11289 Params.push_back(std::make_pair(StringRef(), QualType()));
11290 }
11291 }
Craig Topperc3ec1492014-05-26 06:22:03 +000011292 getSema().ActOnCapturedRegionStart(Loc, /*CurScope*/nullptr,
Alexey Bataev9959db52014-05-06 10:08:46 +000011293 S->getCapturedRegionKind(), Params);
Alexey Bataevc5e02582014-06-16 07:08:35 +000011294 StmtResult Body;
11295 {
11296 Sema::CompoundScopeRAII CompoundScope(getSema());
11297 Body = getDerived().TransformStmt(S->getCapturedStmt());
11298 }
Wei Pan17fbf6e2013-05-04 03:59:06 +000011299
11300 if (Body.isInvalid()) {
11301 getSema().ActOnCapturedRegionError();
11302 return StmtError();
11303 }
11304
Nikola Smiljanic01a75982014-05-29 10:55:11 +000011305 return getSema().ActOnCapturedRegionEnd(Body.get());
Tareq A. Siraj24110cc2013-04-16 18:53:08 +000011306}
11307
Douglas Gregord6ff3322009-08-04 16:50:30 +000011308} // end namespace clang
11309
Hans Wennborg59dbe862015-09-29 20:56:43 +000011310#endif // LLVM_CLANG_LIB_SEMA_TREETRANSFORM_H